Log-in
en
General Actions:
Wiki
▼
:
Document Index
Space:
Main
▼
:
Document Index
Page:
LuceneSearch
Page Actions:
Export
▼
:
Export as PDF
Export as RTF
Export as HTML
More actions
▼
:
Print preview
View Source
Telema Wiki
»
Search
»
Lucene Search
Wiki source code of
Lucene Search
Last modified by Admin on 2010/06/21 17:29
Content
·
Comments
(0)
·
Attachments
(0)
·
History
·
Information
Show line numbers
{{velocity}} $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") #set ($rssmode = ("$!request.xpage" == 'plain')) ## --------------- ## Space filtering ## --------------- #set($extraClause = '') #set($spaces = $xwiki.spaces) #set($selectedSpace = "$!request.space") #if($selectedSpace != '' && !$blacklistedSpaces.contains($selectedSpace)) #set($extraClause = " AND space:${selectedSpace}") #end ## ---------------------------------------------------------------------- ## Exclude Blacklisted spaces ($blacklistedSpaces is set in xwikivars.vm) ## Also exclude WebPreferences. ## ---------------------------------------------------------------------- #foreach ($blacklistedSpace in $blacklistedSpaces) #set ($extraClause = " AND NOT space:${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('search.page.bar.spaces.title')"> <option value="" #if($selectedSpace == '')selected="selected"#end>$msg.get('search.page.bar.spaces.all')</option> #foreach($space in $spaces) #if (!$blacklistedSpaces.contains($space)) #spaceoption($space $selectedSpace) #end #end </select> #end ## --------------- ## Wikis filtering ## --------------- ## Parse provided wikis #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 #if (!$xcontext.isMainWiki() && $wikinames == '') #set($wikinames = $xcontext.database) #end #else #set($wikinametable = $wikinames.split(", ")) #foreach($wikiname in $wikinametable) #set($ok = $wikinamelist.add($wikiname)) #end #end ## #if($xwiki.isVirtualMode() && $xcontext.isMainWiki()) #if(!$allwikinamelist) #set($currentwikiname = $xcontext.database) ## TODO: add and use a public API method to get the list of wikis instead of doing it "by hand" #set($allwikilist = $xwiki.searchDocuments(", BaseObject as obj, StringProperty as prop where doc.fullName=obj.name and doc.fullName<>'XWiki.XWikiServerClassTemplate' and obj.className='XWiki.XWikiServerClass' and prop.id.id=obj.id and prop.id.name='server'")) ## #set($allwikinamelist = []) #foreach($wiki in $allwikilist) #set($ok = $allwikinamelist.add($wiki.substring(17).toLowerCase())) #end ## Make sure the main wiki is part of the list #if(!$allwikinamelist.contains($xcontext.mainWikiName)) #set($ok = $allwikinamelist.add($xcontext.mainWikiName)) #end #end ## --------------- ## Wikis macros ## --------------- #macro(wikioption $wikiname $wikinamelist) <option value="$wikiname" #if($wikinamelist.contains($wikiname))selected="selected"#end>$wikiname</option> #end #macro(wikisselect $wikinamelist $allwikinamelist) ## TODO: find a scaling way to handle wikis multiselect, does not use multiple="multiple" for now because it does not looks nice <select name="wikinames"> <option value="" selected="selected">$msg.get('search.page.bar.wikis.all')</option> #foreach($wikiname in $allwikinamelist) #wikioption($wikiname $wikinamelist) #end </select> #end #else #if($wikinames == '') #set($wikinames = $xcontext.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 ## --------------- ## Query form ## --------------- #if(!$rssmode) {{html}} <form action="" id="searchBar"> <div class="centered"> <label for="text" class="hidden">$msg.get('search.page.query.label')</label> <input type="text" id="text" name="text" class="searchQuery #if($text == '') defaultText#end" #if($text == '') value="$msg.get('search.page.bar.query.tip')" #else value="${escapetool.xml($text)}" #end title="$msg.get('search.page.bar.query.title')"/> #if ($xwiki.isVirtualMode() && $xcontext.isMainWiki()) #wikisselect($request.wikinames $allwikinamelist) #end #spaceselect($selectedSpace $spaces) <input type="submit" class="searchButton" value="$msg.get('search.page.bar.submit')" title="$msg.get('search.page.bar.submit.title')"/> <div class="searchHelp">$msg.get('search.page.bar.querytip')</div> </div> </form> {{/html}} #end ## --------------- ## Results processing ## --------------- #if($query != '') #set($lucene = $xwiki.getPlugin("lucene")) #if($lucene) ## --------------- ## Lucene search ## --------------- #set($searchresults = $lucene.getSearchResults("${query}${extraClause}", '', $wikinames, $!languages)) #if($searchresults.getHitcount() > 0) ## ----------------- ## Pagination (top) ## ----------------- #if(!$rssmode) #set($paginationParameters = {'url' : $doc.getURL('view', "text=${escapetool.url($query)}&space=${escapetool.url($selectedSpace)}"), 'totalItems' : $searchresults.getHitcount(), 'defaultItemsPerPage' : $defaultItemsPerPage, 'position': 'top'}) {{html}} #pagination($paginationParameters) {{/html}} #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 ($rssmode) #set ($list = $util.arrayList) #foreach ($item in $results) #if ($item.type != "attachment") #set ($ok = $list.add(0, "${item.space}.${item.name}")) #end #end #set ($feed = $xwiki.feed.getDocumentFeed($list, $util.getHashMap())) #set ($feedURI = $doc.getExternalURL("view")) #set ($discard = $feed.setLink($feedURI)) #set ($discard = $feed.setUri($feedURI)) #set ($discard = $feed.setAuthor('XWiki')) #set ($discard = $feed.setTitle($msg.get('search.rss', [$text]))) #set ($discard = $feed.setDescription($msg.get('search.rss', [$text]))) #set ($discard = $feed.setLanguage($xcontext.language)) #set ($discard = $feed.setCopyright($xwiki.getXWikiPreference('copyright'))) {{{$xwiki.feed.getFeedOutput($feed, 'rss_2.0')}}} #else #set ($list = $results) #set ($isScored = true) {{include document="XWiki.Results"/}} #end ## ----------------- ## Pagination (bottom) ## ----------------- #if(!$rssmode) #set($paginationParameters.position = 'bottom') {{html}} #pagination($paginationParameters) {{/html}} ## --------------- ## RSS link ## --------------- #if($selectedSpace == '') #set($rssURL = $xwiki.getURL($doc.fullName, 'view', "xpage=plain&text=${utext}" )) #else #set($rssURL = $xwiki.getURL($doc.fullName, 'view', "xpage=plain&space=${selectedSpace}&text=${utext}")) #end {{html}} <a href="${rssURL}"><img src="$xwiki.getSkinFile("icons/silk/feed.gif")" alt="RSS icon"/>$msg.get("search.rss", ["[$escapetool.xml($query)]"])</a> {{/html}} #end #end #else {{error}}$msg.get('search.lucene.plugin.notfound')){{/error}} #end #end #if (!$rssmode) ## --------------- ## Rebuild processing ## --------------- #set($lucene = $xwiki.getPlugin("lucene")) #if($lucene) ## --------------- ## Queue ## --------------- #set ($queuesize = $xwiki.lucene.getQueueSize()) #if ($queuesize > 0) {{info}}$msg.get('search.page.lucene.rebuilding', [${queuesize}]){{/info}} #end #end## lucene exists #end## !$rssmode {{/velocity}}