[xwiki-dev] Costumized Lucene Search Page

Vincent Massol vincent at massol.net
Thu Apr 19 09:36:05 CEST 2007


Hi Michael/Jens,

Thanks for your contribution Michael.

1) I didn't know Jens had a page documenting the Lucene plugin. The  
page is quite nice and much better than ours at http://www.xwiki.org/ 
xwiki/bin/view/Code/LucenePlugin.

Jens, would you mind if we merge the content of your page in the one  
at xwiki.org? Also, my understanding is that you donated the Lucene  
plugin to the XWiki project some time back. Is that correct? If so  
maybe we could deprecate your lucene doc page (once and if you agree  
to merge the content with the one on xwiki.org). WDYT?

2) Michael, In Velocity, looping is done with foreach. That's the  
only loop there is I think.

3) Michael, what would be nice would be if you could add your code as  
a Code Snippet on xwiki.org: http://www.xwiki.org/xwiki/bin/view/Code/ 
Snippets (there's a "Add snippet" on the right). In that manner we'll  
be able to add a link to it from the Lucene plugin. It would be nice  
if you could put a screenshot of the result on the Code Snippet page  
so that users can see how it looks and decide if they want to use  
your snippet. WDYT?

Thanks a lot
-Vincent

On Apr 19, 2007, at 9:12 AM, Michael Guntli wrote:

>
> With RC1 lucene seems to work again, so i have costumized the  
> existing search
> form from jkraemer
> (http://www.jkraemer.net/static/maven/xwiki/plugins/lucene-plugin/ 
> install.html)
>
> But keep attention: it's just a quick&dirty example to display the  
> results
> in a table ;-)
> As im not very familiar with velocity, the code is quite ugly! (for  
> example
> i didn't find a while loop to output the number of stars for score- 
> quality,
> so i did it with if, if, if..)
>
> it still has some bugs:
> * if you search for a regular expression (e.g. win*), then the  
> query for the
> next page will be win</strong>
> * non wiki-documents and non-attachments will be hidden from the  
> results, so
> it could happen that you see an empty page with a link to the next  
> results
> (that's because searchresults.hitcount returns all results, also  
> the hidden
> ones..)
> * many more..
> * icons are hard-coded.. (/skins/lgs/*.png)
>
> You can get the icons for free from famfamfam:
> http://www.famfamfam.com/lab/icons/silk/
>
> ---------------------------
> Searchform.vm:
> 1 Search
> #set($query = $request.getParameter("text"))
> #if(!$query)
> 	#set($query = "")
> #end
> #warning("This is the new lucene search engine.\\
> If you experience any problems, try to use the default xwiki
> [Search>WebSearch?text=$query]..")
> #set($itemsPerPage = "30")
> #set($doRebuild = $request.getParameter("rebuild"))
> #if($doRebuild=="yes")
> 	#set($lucene = $xwiki.getPlugin("lucene"))
> 	#if($lucene)
> 		#set($documentCount = $lucene.rebuildIndex($xwiki,$context))
> 		#if(${documentCount}>=0)
> 			Started index rebuild with $documentCount documents. Will take  
> some time
> depending on the number of pages/attachments.
> 		#else
> 			Index rebuild failed.
> 		#end
> 	#end
> #else
> 	#if($xwiki.hasAdminRights())
> 		[rebuild Index>${doc.web}.${doc.name}?rebuild=yes]
> 	#end
> #end
>
> {pre}
> <form action="$doc.name" method="post">
> <input type="text" name="text" value="$query" />
> <input type="submit" value="Search"/>
> </form>
> {/pre}
>
> #if($query != "")
> 	#set($lucene = $xwiki.getPlugin("lucene"))
> 	#if($lucene)
> 		#set($wikinames = "xwiki")
> 		#set($languages = "default,en,de")
> 		#set($firstIndex = $request.getParameter("firstIndex"))
> 		#if(!$firstIndex)
> 			#set($firstIndex = "1")
> 		#end
> 		#set($searchresults = $lucene.getSearchResults($query, $wikinames,
> $languages, $xwiki))
> 		#set($results = $searchresults.getResults($firstIndex, 
> $itemsPerPage))
> 		#if($results.size()>0)
> 			#set($lastIndex=$searchresults.getEndIndex($firstIndex,  
> $itemsPerPage))
> 			#if($searchresults.hitcount==1)
> 				##{pre} $msg.get("oneresult"):{/pre}
> 			#else
> 				##{pre}$msg.get("results") $firstIndex - $lastIndex $msg.get("of")
> ${searchresults.hitcount}:{/pre}
>
> 			#if($searchresults.hasPrevious($firstIndex))
> 				[previous
> page>${doc.web}.${doc.name}?text=$query&firstIndex= 
> $searchresults.getPreviousIndex($firstIndex,$itemsPerPage)]
> 			#end
> 			#if($searchresults.hasNext($firstIndex,$itemsPerPage))
> 				[next
> page>${doc.web}.${doc.name}?text=$query&firstIndex= 
> $searchresults.getNextIndex($firstIndex,$itemsPerPage)]
> 			#end
> 		#end
> 		
> 		<table width="100%" class="grid" cellSpacing=0 cellpadding="5"  
> border="1">
> 		<tr>
> 		<th>Result</th>
> 		<th width="100">Date</th>
> 		<th width="150">Last Author</th>
> 		<th width="100">Score</th>
> 		</tr>
> 		#foreach($result in $results)
> 			#if($result.type=='wikipage')
> 				<tr>
> 				#if($xwiki.isVirtual())
> 					<td align=left>[${result.wiki}:${result.web}.${result.name}]</td>
> 				#else
> 					<td align=left>[${result.web}.${result.name}]</td>
> 				#end
> 				<td>$xwiki.formatDate($result.date, "d. MMM yyyy")</td>
> 				<td>$xwiki.getUserName($result.author)</td>
> 				<td>
> 				#set($resval=$result.score*100)
> 				#if($resval>10)
> 					 /xwiki/skins/lgs/16-star-hot.png
> 				#end
> 				#if($resval>25)
> 					 /xwiki/skins/lgs/16-star-hot.png
> 				#end
> 				#if($resval>50)
> 					 /xwiki/skins/lgs/16-star-hot.png
> 				#end
> 				#if($resval>70)
> 					 /xwiki/skins/lgs/16-star-hot.png
> 				#end
> 				#if($resval>90)
> 					 /xwiki/skins/lgs/16-star-hot.png
> 				#end
> 				${resval}%
> 				</td>
> 				</tr>
> 			#elseif($result.type=='attachment')
> 				<tr>
> 				<td align=left> ${result.url}  /xwiki/skins/lgs/disk.png
> ${result.filename} \\
> 				Attachment of [${result.web}.${result.name}]</td>
> 				<td>$xwiki.formatDate($result.date, "d. MMM yyyy")</td>
> 				<td>$xwiki.getUserName($result.author)</td>
> 				<td>
> 				#set($resval=$result.score*100)
> 				#if($resval>10)
> 					 /xwiki/skins/lgs/16-star-hot.png
> 				#end
> 				#if($resval>25)
> 					 /xwiki/skins/lgs/16-star-hot.png
> 				#end
> 				#if($resval>50)
> 					 /xwiki/skins/lgs/16-star-hot.png
> 				#end
> 				#if($resval>70)
> 					 /xwiki/skins/lgs/16-star-hot.png
> 				#end
> 				#if($resval>90)
> 					 /xwiki/skins/lgs/16-star-hot.png
> 				#end
> 				${resval}%
> 				</td>
> 				</tr>
> 			#end
> 			</tr>
> 		#end
> 		#else
> 			$msg.get("noresults")
> 		#end
> 		</table>
> 		\\
> 	#else
> 		lucene plugin not found
> 	#end
> #end





More information about the devs mailing list