General Actions:
Log-in
Wiki:
L3D's Wiki
▼
:
Document Index
»
Space:
Main
▼
:
Document Index
»
Page:
LuceneSearch
Search
Page Actions:
Export
▼
:
Export as PDF
Export as RTF
Export as HTML
More actions
▼
:
Print preview
View Source
Welcome to your wiki
»
Search
»
Search
Wiki source code of
Search
Last modified by
Administrator
on 2009/01/30 06:31
Content
·
Comments
(0)
·
Attachments
(0)
·
History
·
Information
Show line numbers
## =================== ## Lucene search ## =================== ## Inputs : $request.text ## Outputs : $list, $isScored ## =================== ## Uncomment this line to overload the maximum list of wiki where to search (also the one listed in the wikis combobox) ## #set($allwikinamelist = ["xwiki", "wiki1", "wiki2"]) ## ## Uncomment this line to overload the wikis where to search ## #set($wikinames = "xwiki,wiki,wiki") ## {pre} #set ($displayUI = true) #if ($request.xpage && $request.xpage == "rdf") #set ($displayUI = false) #end ## --------------- ## Title ## --------------- #if ($displayUI) {/pre} 1 $msg.get("search") {pre} #end ## --------------- ## Space filtering ## --------------- #if($request.space && $request.space != "") #set($space = $request.space) #set($reqspace = " AND web:${space}") #else #set($space = "") #end #set($spacesText = {}) #set($spaces = $xwiki.spaces) #set($ok = $spacesText.put("All","")) #foreach($space in $spaces) #set($ok = $spacesText.put($space,$space)) #end ## --------------- ## Space macros ## --------------- #macro(spaceoption $space $selectspace $spacesText) <option value="$spacesText.get($space)" #if($selectspace == $spacesText.get($space))selected="selected"#end>$space</option> #end #macro(spaceselect $selectspace $spaces $spacesText) <select name="space"> #spaceoption("All" $selectspace $spacesText) #foreach($space in $spaces) #spaceoption($space $selectspace $spacesText) #end </select> #end ## --------------- ## Wikis filtering ## --------------- #set($wikinamelist = []) #if(!$wikinames) #set($wikinametable = $request.getParameterValues("wikinames")) #if(!$wikinametable || $request.wikinames == "") #set($wikinametable = $allwikinamelist) #end #set($wikinames = "") #foreach($wikiname in $wikinametable) #set($ok = $wikinamelist.add($wikiname)) #if($wikinames != "") #set($wikinames = $wikinames + ",") #end #set($wikinames = $wikinames + $wikiname) #end #else #set($wikinametable = $wikinames.split(", ")) #foreach($wikiname in $wikinametable) #set($ok = $wikinamelist.add($wikiname)) #end #end ## #if($xwiki.isVirtualMode()) #if(!$allwikinamelist) #set($currentwikiname = $context.database) #set($ok = $context.setDatabase($context.mainWikiName)) #set($allwikilist = $xwiki.searchDocuments(", BaseObject as obj, StringProperty as prop where doc.fullName=obj.name and obj.className='XWiki.XWikiServerClass' and prop.id.id=obj.id and prop.id.name='server'")) #set($ok = $context.setDatabase($currentwikiname)) ## #set($allwikinamelist = []) #foreach($wiki in $allwikilist) #set($ok = $allwikinamelist.add($wiki.substring(17).toLowerCase())) #end #if(!$allwikinamelist.contains($context.mainWikiName)) #set($ok = $allwikinamelist.add($context.mainWikiName)) #end #end ## --------------- ## Wikis macros ## --------------- #macro(wikinamesoption $wikiname $wikinamelist) <option value="$wikiname" #if($wikinamelist.contains($wikiname))selected="selected"#end>$wikiname</option> #end #macro(wikinamesselect $allwikinamelist $wikinamelist) <select name="wikinames"> <option value="" selected="selected">All</option> #foreach($wikiname in $allwikinamelist) #wikinamesoption($wikiname $wikinamelist) #end </select> #end #else #if($wikinames == "") #set($wikinames = $context.mainWikiName) #end #end ## --------------- ## Query preparation ## --------------- #set($text = "$!request.getParameter('text')") #set($query = $text) #set($utext = $util.encodeURI($query)) #set($itemsPerPage = "30") ## --------------- ## RSS link ## --------------- #if($space == "") #set($url = $xwiki.getURL($doc.fullName, "view", "xpage=rdf&text=${utext}" )) #else #set($url = $xwiki.getURL($doc.fullName, "view", "xpage=rdf&space=$space&text=${utext}")) #end #if ($displayUI) <div style="float: right;"> <a href="$url"><img src="$xwiki.getSkinFile("icons/black-rss.png")" style="border:0px" alt="rss icon" /></a> </div> ## --------------- ## Query form ## --------------- <form action="$doc.name" method="get"> <div class="centered"> $msg.get("xe.search.query") <input type="text" name="text" value="$xwiki.getFormEncoded($query)" /> $msg.get("xe.search.in.space") #spaceselect($space $spaces $spacesText)#if($xwiki.isVirtualMode()) $msg.get("xe.search.in.wikis") #wikinamesselect($util.sort($allwikinamelist) $wikinamelist)#end <input type="submit" value="$msg.get("xe.search.go")"/> </div> </form> #end {/pre} ## --------------- ## Results processing ## --------------- #if($query != "") #set($lucene = $xwiki.getPlugin("lucene")) #if($lucene) ## --------------- ## Lucene search ## --------------- #set($languages = "default,en,de") #set($firstIndex = $request.getParameter("firstIndex")) #if(!$firstIndex) #set($firstIndex = "1") #end #set($searchresults = $lucene.getSearchResults("${query}$!{reqspace}", $wikinames, $languages, $xwiki)) #set($results = $searchresults.getResults($firstIndex,$itemsPerPage)) #if($searchresults.getHitcount()>0) ## ----------------- ## Results numbers ## ----------------- #set($lastIndex=$searchresults.getEndIndex($firstIndex, $itemsPerPage)) #if ($displayUI) #if($searchresults.getHitcount()==1) $msg.get("xe.search.results.one") #else $msg.get("xe.search.results") $firstIndex - $lastIndex $msg.get("xe.search.of") ${searchresults.getHitcount()}: #end #end ## --------------- ## Previous page ## --------------- #if($searchresults.hasPrevious($firstIndex) && $displayUI) #set($linkfirstIndex = $searchresults.getPreviousIndex($firstIndex,$itemsPerPage)) #set($link = "${doc.name}?text=${query}&firstIndex=${linkfirstIndex}") {pre} <a href="$link"><img src="${xwiki.getSkinFile("icons/silk/resultset_previous.gif")}" alt="$msg.get('xe.search.page.previous')" />$msg.get("xe.search.page.previous")</a> {/pre} #end ## ------------- ## Next page ## ------------- #if($searchresults.hasNext($firstIndex,$itemsPerPage) && $displayUI) #set($linkfirstIndex = $searchresults.getNextIndex($firstIndex,$itemsPerPage)) #set($link = "${doc.name}?text=${query}&firstIndex=${linkfirstIndex}") {pre} <a href="$link"><img src="${xwiki.getSkinFile("icons/silk/resultset_next.gif")}" alt="$msg.get('xe.search.page.next')" />$msg.get("xe.search.page.next")</a> {/pre} #end ## ----------------- ## Display results ## ----------------- #if ($request.xpage && $request.xpage == "rdf") #set ($baseurl = "http://${request.serverName}") #set ($descText = $msg.get("xe.search.rss.feedfor")) #set ($description = "$descText '$text'") #set ($list = $util.arrayList) #foreach ($item in $results) #if ($item.type != "attachment") #set ($ok = $list.add(0, "${item.web}.${item.name}")) #end #end #set ($ok = $response.setContentType("text/xml")) #includeInContext("XWiki.WebRssCode") #else #set ($list = $results) #set ($isScored = true) #includeInContext("XWiki.Results") #end #end #else #error($msg.get("xe.search.plugin.notfound")) #end #end #if ($displayUI) {pre} ## --------------- ## Rebuild processing ## --------------- #set($lucene = $xwiki.getPlugin("lucene")) #if($lucene) #set($doRebuild = "$!{request.getParameter('rebuild')}") #if($doRebuild == "yes") #set($documentCount = $lucene.rebuildIndex()) #if(${documentCount} >= 0) {/pre}#info($msg.get("xe.search.rebuild.started")){pre} #elseif(${documentCount} == -1) #error($msg.get("xe.search.rebuild.rights")) #elseif(${documentCount} == -2) #error($msg.get("xe.search.rebuild.inprogress")) #else #error($msg.get("xe.search.rebuild.failed")) #end #else ## !doRebuild ## --------------- ## Queue & rebuild option ## --------------- #set ($queuesize = $xwiki.lucene.getQueueSize()) #if ($queuesize > 2) #set($info1 = $msg.get('xe.search.rebuild.currently', [${queuesize}])) #else #set($info1 = $msg.get('xe.search.index.uptodate')) #end #if($hasAdmin) #set($info2 = " [$msg.get('xe.search.index.rebuild')>${doc.space}.${doc.name}?rebuild=yes].") #else #set($info2 = "") #end {/pre}#info("${info1}${info2}"){pre} #end ## doRebuild ## --------------- ## Comment ## --------------- {/pre} #set($defaultSearch = "[$msg.get('xe.search.default.engine')>WebSearch?text=$utext]") #warning($msg.get("xe.search.lucene.experimental", [$defaultSearch])) #else ## !lucene exists #set($defaultSearch = "[$msg.get('xe.search.default.engine')>WebSearch?text=$utext]") #warning($msg.get("xe.search.plugin.notenabled", [$defaultSearch])) #end ## lucene exists #end ## displayUI
Search
Quick Links
L3D Calendar
Wiki Dashboard
Document Index
Blog
Sandbox
Recently Modified
XWiki Scheduler Job Class
|
XWiki Preferences
|
XWikiAllGroup