LuceneSearch
Log-in
|
Main
:
Welcome to your wiki
>
WebSearch
>
LuceneSearch
Top Menu
Show
:
Comments
Attachments
History
Information
Stampa
:
Stampa
Anteprima di stampa
Esporta come PDF
Esporta in formato RTF
Esporta come HTML
Esporta in formato XAR
Wiki source code of
LuceneSearch
Show line numbers
$xwiki.jsfx.use("uicomponents/search/search.js", true)## $xwiki.ssfx.use("uicomponents/search/search.css", true)## ## Disable the document extra data: comments, attachments, history... #set($docextras = []) ## =================== ## 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") ## ## Uncomment this line to overload the languages to search ## #set($languages = "default,en,de") {pre} #set ($displayUI = true) #if ("$!request.xpage" == ’rdf’) #set ($displayUI = false) #end ## --------------- ## Space filtering ## --------------- #set($extraClause = ’’) #set($selectedSpace = "$!request.space") #if($selectedSpace != ’’ && !$blacklistedSpaces.contains($selectedSpace)) #set($extraClause = " AND web:${selectedSpace}") #end ## ---------------------------------------------------------------------- ## Exclude Blacklisted spaces ($blacklistedSpaces is set in xwikivars.vm) ## Also exclude WebPreferences. ## ---------------------------------------------------------------------- #foreach ($blacklistedSpace in $blacklistedSpaces) #set ($extraClause = " AND NOT web:${blacklistedSpace}${extraClause}") #end #if(!$hasAdmin && !$isAdvancedUser) #set ($extraClause = " AND NOT name:WebPreferences${extraClause}") #end ## --------------- ## Space macros ## --------------- #macro(spaceoption $space $selectedSpace) <option value="${space}" #if($selectedSpace == $space)selected="selected"#end>$space</option> #end #macro(spaceselect $selectedSpace $spaces) <select name="space" title="$msg.get(’xe.search.bar.spaces.title’)"> <option value="" #if($selectedSpace == ’’)selected="selected"#end>$msg.get(’xe.search.bar.spaces.all’)</option> #foreach($space in $xwiki.spaces) #if (!$blacklistedSpaces.contains($space)) #spaceoption($space $selectedSpace) #end #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($defaultItemsPerPage = 30) #set($itemsPerPage = $util.parseInt("$!{request.perPage}")) #if($itemsPerPage <= 0) #set($itemsPerPage = $defaultItemsPerPage) #end ## --------------- ## RSS link ## --------------- #if($selectedSpace == ’’) #set($url = $xwiki.getURL($doc.fullName, ’view’, "xpage=rdf&text=${utext}" )) #else #set($url = $xwiki.getURL($doc.fullName, ’view’, "xpage=rdf&space=${selectedSpace}&text=${utext}")) #end ## --------------- ## Title ## --------------- #if ($displayUI) <h1><span> <a style="float: right;" href="$url"><img src="$xwiki.getSkinFile(’icons/silk/feed.gif’)" alt="$msg.get(’xe.rss.icon’)" /></a> $msg.get(’xe.search.title’)</span> </h1> ## --------------- ## Query form ## --------------- <form action="" method="get" id="searchBar"> <div class="centered"> <input type="text" name="text" class="searchQuery #if($text == ’’) defaultText#end" #if($text == ’’) value="$msg.get(’xe.search.bar.query.tip’)" #else value="$xwiki.getXMLEncoded(${text})" #end title="$msg.get(’xe.search.bar.query.title’)"/> #spaceselect($selectedSpace $spaces) <input type="submit" class="searchButton" value="$msg.get(’xe.search.bar.submit’)" title="$msg.get(’xe.search.bar.submit.title’)"/> <div class="searchHelp">$msg.get(’xe.search.bar.queryTip’)</div> </div> </form> #end {/pre} ## --------------- ## Results processing ## --------------- #if($query != ’’) #set($lucene = $xwiki.getPlugin("lucene")) #if($lucene) ## --------------- ## Lucene search ## --------------- #set($searchresults = $lucene.getSearchResults("${query}${extraClause}", $wikinames, $!languages, $xwiki)) #if($searchresults.getHitcount() > 0) ## ----------------- ## Pagination (top) ## ----------------- #if($displayUI) #set($paginationParameters = {’url’ : $doc.getURL(’view’, "text=${query}&space=${selectedSpace}"), ’totalItems’ : $searchresults.getHitcount(), ’defaultItemsPerPage’ : $defaultItemsPerPage, ’position’: ’top’}) #pagination($paginationParameters) #end ## ----------------- ## Display results ## ----------------- #set($firstIndex = "$!{paginationParameters.firstItem}") #if($firstIndex == ’’) #set($firstIndex = "$!request.getParameter(’firstIndex’)") #if($firstIndex == ’’) #set($firstIndex = ’0’) #end #end #set($firstIndex = $util.parseInt($firstIndex)) #set($firstIndex = $firstIndex + 1) #set($results = $searchresults.getResults("$firstIndex", "$itemsPerPage")) #if ("$!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 ## ----------------- ## Pagination (bottom) ## ----------------- #if($displayUI) #set($paginationParameters.position = ’bottom’) #pagination($paginationParameters) #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 {/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
Wiki Dashboard
Document Index
Blog
Sandbox
My Recent Modifications
dany
|
marco