Installation (Binary distribution)

Copy required jars

Unpack the distribution archive and copy xwiki-lucene-plugin-x.y.jar and all jars from lib/ to WEB-INF/lib inside your xwiki webapp.

XWiki configuration

Edit xwiki.cfg (located in the WEB-INF dir of your xwiki web application directory):

  • Add the full class name of the plugin to the xwiki.plugins property:
    xwiki.plugins=com.xpn.xwiki.plugin.calendar.CalendarPlugin,net.jkraemer.xwiki.plugins.lucene.LucenePlugin
  • Configure the index location. The indexdir property takes a comma-separated list of paths pointing to lucene indexes. All those indexes will be used for searching, but only the first one will be used by the plugin to index the wiki contents. Remember to create the directory and set appropriate rights (the server needs write access to this directory) before starting the server.
    xwiki.plugins.lucene.indexdir=/path/to/index/
    At the moment the plugin relies on the fact that the additional external indexes use the field names defined in LucenePlugin.java, too. This will change in the future, i.e. by presenting unknown fields and their values as a map to the searchresults page.
  • Configure the analyzer used for indexing and searching. The choice should reflect the language of the content to be indexed. See the docs at http://jakarta.apache.org/lucene for more info. For other languages than german or russian the StandardAnalyzer will do. There is no solution to reflect the multilingual support of XWiki yet.
    xwiki.plugins.lucene.analyzer=org.apache.lucene.analysis.de.GermanAnalyzer
    # xwiki.plugins.lucene.analyzer=org.apache.lucene.analysis.ru.RussianAnalyzer
    # xwiki.plugins.lucene.analyzer=org.apache.lucene.analysis.standard.StandardAnalyzer
  • If you like, set the time in seconds the indexer thread goes to sleep after all pending documents have been indexed. Default is 300 seconds. The idea here is to aggregate some changes before opening the index for writing to reduce overhead. A lower value leads to a more up-to-date index, but also to higher load.
    xwiki.plugins.lucene.indexinterval=300

Now restart the application server.

The search form

Insert the content of searchForm.vm into a wiki page of your choice. Customize it to fit your needs. The number of results to show per page is defined in the very first line where the variable itemsPerPage is defined.

If you want to build your own search form from scratch, you should have a look at the API docs of LucenePluginApi, SearchResults and SearchResult.

If you intend to keep up with the nice internationalization features of xwiki, you can add the message keys used for presenting the searchresults to the Application Resources files located in WEB-INF/classes. This is completely optional, if you only use one language you can hard wire the Strings in your Search results page as well. The message keys used are:

  • noresults=No results
  • results=Results
  • oneresult=One result
  • search=Search
  • tosearch=Search
  • next=next
  • previous=previous
  • of=of

Create an initial index

To build up the index of all existing documents in your wiki log in as a user having admin rights, and view the page you just created. There should be a link saying 'rebuild Index'. Alternatively you can simply append the url parameter rebuild=yes to the url of this page. You will need to be logged as Admin for this to be successful in any case. After a short time there should be a line telling you how many documents have been scheduled for addition to the index. Attachments and translations count as documents by themselves. Note that the index won't be built immediately, it can take up to xwiki.plugins.lucene.indexinterval (by default 300 seconds) until the thread doing the indexing work wakes up and checks its queue for documents to be indexed. The same is true for the automatic index updates due to changes you make in documents.

Try it out!

In case of any trouble set

log4j.logger.net.jkraemer.xwiki=debug
in your WEB-INF/classes/log4j.properties, restart the server and try to reproduce the problem, watching the logfile (xwiki.log) in a shell nearby.

Please contact me if you think you've found a bug, but always try to give me as much information as possible to ease tracking down the problem.

Make the search form on the right side use the Lucene plugin

This is easy. Just copy the file templates/viewtoolbar.vm to skins/yourskin/viewtoolbar.vm and change the document name in the line

#set($searchdoc = $xwiki.getDocument("Main.WebSearch"))

to the name of the document containing your Lucene based searchform.

If you don't want to do so for any reason, you can also simply change the original search page to contain the lucene search form instead of the original one.