General Actions:
Log-in
Wiki:
CreativeIT
▼
:
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 the CreativeIT Wiki!
»
Search
»
Search
Wiki source code of
Search
Last modified by
Administrator
on 2008/06/25 08:43
Content
·
Comments
(0)
·
Attachments
(2)
·
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 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"> Query <input type="text" name="text" value="$xwiki.getFormEncoded($query)" /> in space #spaceselect($space $spaces $spacesText)#if($xwiki.isVirtualMode()) in wikis #wikinamesselect($util.sort($allwikinamelist) $wikinamelist)#end <input type="submit" value="Search"/> </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) One result: #else Results $firstIndex - $lastIndex 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="${doc.getAttachmentURL("previous.png")}" alt="previous" />previous page</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="${doc.getAttachmentURL("next.png")}" alt="next" />next page</a> {/pre} #end ## ----------------- ## Display results ## ----------------- #if ($request.xpage && $request.xpage == "rdf") #set ($baseurl = "http://${request.serverName}") #set ($description = "RSS feed for search on '$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("Lucene plugin not found. Make sure it's defined in your xwiki.cfg file.") #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("Started index rebuild.\\ Will take some time depending on the number of pages/attachments."){pre} #elseif(${documentCount} == -1) #error("You must have administrator rights to rebuild the index.") #elseif(${documentCount} == -2) #error("Another rebuild is in progress.") #else #error("Index rebuild failed.") #end #else ## !doRebuild ## --------------- ## Queue & rebuild option ## --------------- #set ($queuesize = $xwiki.lucene.getQueueSize()) #if ($queuesize > 2) #set($info1 = "Lucene is currently building its index, ${queuesize} documents in queue.") #else #set($info1 = "Lucene index is up to date.") #end #if($hasAdmin) #set($info2 = " [Rebuild the Lucene index>${doc.space}.${doc.name}?rebuild=yes].") #else #set($info2 = "") #end {/pre}#info("${info1}${info2}"){pre} #end ## doRebuild ## --------------- ## Comment ## --------------- {/pre} #warning("This is the new experimental Lucene search engine. \\ You can still use the XWiki [default search engine>WebSearch?text=$utext].") #else ## !lucene exists #warning("The Lucene plugin is not enabled. You can use the XWiki [default search engine>WebSearch?text=$utext].") #end ## lucene exists #end ## displayUI
Quick Links
Home
Index
What's New
Blog
Calendar
Photo Albums
Sandbox
Tags
Bulletin Board
My Recent Modifications
PamelaJennings
|
rwakkary
|
HaledenSands
|
ByronLahey