[xwiki-dev] Costumized Lucene Search Page

jeremi joslin jeremi at xwiki.com
Thu Apr 19 09:47:19 CEST 2007


Hi,
Thanks.

Here is another sample of the Lucene plugin (but specific to Curriki).
That can help you to understand what you can do with it :
http://www.curriki.org/xwiki/bin/view/Main/BrowseSearch?brsqry=mit
and here is the code :
http://www.curriki.org/xwiki/bin/view/Main/BrowseSearch?xpage=code


jeremi

On 4/19/07, Michael Guntli <michael.guntli at leica-geosystems.com> 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
> --
> View this message in context: http://www.nabble.com/Costumized-Lucene-Search-Page-tf3605463.html#a10073014
> Sent from the XWiki- Dev mailing list archive at Nabble.com.
>
>
>
>
> --
> You receive this message as a subscriber of the xwiki-dev at objectweb.org mailing list.
> To unsubscribe: mailto:xwiki-dev-unsubscribe at objectweb.org
> For general help: mailto:sympa at objectweb.org?subject=help
> ObjectWeb mailing lists service home page: http://www.objectweb.org/wws
>
>


-- 
Jeremi Joslin (http://www.jeremi.info)
skype: jeremi23 - jabber: jeremi23 at gmail.com
http://www.xwiki.com - http://www.pengyou-project.info




More information about the devs mailing list