com.xpn.xwiki.plugin.lucene
Class LucenePlugin

java.lang.Object
  extended by com.xpn.xwiki.plugin.XWikiDefaultPlugin
      extended by com.xpn.xwiki.plugin.lucene.LucenePlugin
All Implemented Interfaces:
com.xpn.xwiki.plugin.XWikiPluginInterface

public class LucenePlugin
extends com.xpn.xwiki.plugin.XWikiDefaultPlugin
implements com.xpn.xwiki.plugin.XWikiPluginInterface

A plugin offering support for advanced searches using Lucene, a high performance, open source search engine. It uses an IndexUpdater to monitor and submit wiki pages for indexing to the Lucene engine, and offers simple methods for searching documents, with the possiblity to sort by one or several document fields (besides the default sort by relevance), filter by one or several languages, and search in one, several or all virtual wikis.

Version:
$Id: $

Field Summary
protected  java.util.Properties config
           
static java.lang.String DOCTYPE_ATTACHMENT
           
static java.lang.String DOCTYPE_OBJECTS
           
static java.lang.String DOCTYPE_WIKIPAGE
           
static java.lang.String PROP_ANALYZER
           
static java.lang.String PROP_INDEX_DIR
           
static java.lang.String PROP_INDEXING_INTERVAL
           
static java.lang.String PROP_MAX_QUEUE_SIZE
           
 
Constructor Summary
LucenePlugin(java.lang.String name, java.lang.String className, com.xpn.xwiki.XWikiContext context)
           
 
Method Summary
protected static void closeSearchers(org.apache.lucene.search.Searcher[] searchers)
           
 org.apache.lucene.search.Searcher[] createSearchers(java.lang.String indexDirs)
          Creates an array of Searchers for a number of lucene indexes.
protected  void finalize()
          
 void flushCache(com.xpn.xwiki.XWikiContext context)
           
 long getActiveQueueSize()
           
 java.lang.String getIndexDirs()
           
 long getLuceneDocCount()
           
 java.lang.String getName()
           
 com.xpn.xwiki.api.Api getPluginApi(com.xpn.xwiki.plugin.XWikiPluginInterface plugin, com.xpn.xwiki.XWikiContext context)
           
 long getQueueSize()
           
 SearchResults getSearchResults(java.lang.String query, java.lang.String[] sortField, java.lang.String virtualWikiNames, java.lang.String languages, com.xpn.xwiki.XWikiContext context)
          Searches all Indexes configured in xwiki.cfg (property xwiki.plugins.lucene.indexdir).
 SearchResults getSearchResults(java.lang.String query, java.lang.String sortField, java.lang.String virtualWikiNames, java.lang.String languages, com.xpn.xwiki.XWikiContext context)
          Searches all Indexes configured in xwiki.cfg (property xwiki.plugins.lucene.indexdir).
 SearchResults getSearchResultsFromIndexes(java.lang.String query, java.lang.String[] sortFields, java.lang.String myIndexDirs, java.lang.String languages, com.xpn.xwiki.XWikiContext context)
          Allows to search special named lucene indexes without having to configure them in xwiki.cfg.
 SearchResults getSearchResultsFromIndexes(java.lang.String query, java.lang.String sortField, java.lang.String myIndexDirs, java.lang.String languages, com.xpn.xwiki.XWikiContext context)
          Allows to search special named lucene indexes without having to configure them in xwiki.cfg.
 SearchResults getSearchResultsFromIndexes(java.lang.String query, java.lang.String myIndexDirs, java.lang.String languages, com.xpn.xwiki.XWikiContext context)
          Allows to search special named lucene indexes without having to configure them in xwiki.cfg.
 void init(com.xpn.xwiki.XWikiContext context)
           
protected  void openSearchers()
          Opens the searchers for the configured index Dirs after closing any already existing ones.
 void queueAttachment(com.xpn.xwiki.doc.XWikiDocument doc, com.xpn.xwiki.doc.XWikiAttachment attach, com.xpn.xwiki.XWikiContext context)
           
 void queueAttachment(com.xpn.xwiki.doc.XWikiDocument doc, com.xpn.xwiki.XWikiContext context)
           
 void queueDocument(com.xpn.xwiki.doc.XWikiDocument doc, com.xpn.xwiki.XWikiContext context)
           
 int rebuildIndex(com.xpn.xwiki.XWikiContext context)
           
 
Methods inherited from class com.xpn.xwiki.plugin.XWikiDefaultPlugin
beginParsing, beginRendering, commonTagsHandler, downloadAttachment, endParsing, endRendering, endRenderingHandler, flushCache, getClassName, insidePREHandler, outsidePREHandler, setClassName, setName, startRenderingHandler, virtualInit
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.xpn.xwiki.plugin.XWikiPluginInterface
beginParsing, beginRendering, commonTagsHandler, downloadAttachment, endParsing, endRendering, endRenderingHandler, flushCache, getClassName, insidePREHandler, outsidePREHandler, setClassName, setName, startRenderingHandler, virtualInit
 

Field Detail

DOCTYPE_WIKIPAGE

public static final java.lang.String DOCTYPE_WIKIPAGE
See Also:
Constant Field Values

DOCTYPE_OBJECTS

public static final java.lang.String DOCTYPE_OBJECTS
See Also:
Constant Field Values

DOCTYPE_ATTACHMENT

public static final java.lang.String DOCTYPE_ATTACHMENT
See Also:
Constant Field Values

PROP_INDEX_DIR

public static final java.lang.String PROP_INDEX_DIR
See Also:
Constant Field Values

PROP_ANALYZER

public static final java.lang.String PROP_ANALYZER
See Also:
Constant Field Values

PROP_INDEXING_INTERVAL

public static final java.lang.String PROP_INDEXING_INTERVAL
See Also:
Constant Field Values

PROP_MAX_QUEUE_SIZE

public static final java.lang.String PROP_MAX_QUEUE_SIZE
See Also:
Constant Field Values

config

protected java.util.Properties config
Constructor Detail

LucenePlugin

public LucenePlugin(java.lang.String name,
                    java.lang.String className,
                    com.xpn.xwiki.XWikiContext context)
Method Detail

finalize

protected void finalize()
                 throws java.lang.Throwable

Overrides:
finalize in class java.lang.Object
Throws:
java.lang.Throwable
See Also:
Object.finalize()

rebuildIndex

public int rebuildIndex(com.xpn.xwiki.XWikiContext context)

getSearchResultsFromIndexes

public SearchResults getSearchResultsFromIndexes(java.lang.String query,
                                                 java.lang.String myIndexDirs,
                                                 java.lang.String languages,
                                                 com.xpn.xwiki.XWikiContext context)
                                          throws java.lang.Exception
Allows to search special named lucene indexes without having to configure them in xwiki.cfg. Slower than getSearchResults(String, String, String, String, XWikiContext) since new index searcher instances are created for every query.

Parameters:
query - The base query, using the query engine supported by Lucene.
myIndexDirs - Comma separated list of directories containing the lucene indexes to search.
languages - Comma separated list of language codes to search in, may be null or empty to search all languages.
context - The context of the request.
Returns:
The list of search results.
Throws:
java.lang.Exception - If the index directories cannot be read, or the query is invalid.

getSearchResultsFromIndexes

public SearchResults getSearchResultsFromIndexes(java.lang.String query,
                                                 java.lang.String[] sortFields,
                                                 java.lang.String myIndexDirs,
                                                 java.lang.String languages,
                                                 com.xpn.xwiki.XWikiContext context)
                                          throws java.lang.Exception
Allows to search special named lucene indexes without having to configure them in xwiki.cfg. Slower than getSearchResults(java.lang.String, java.lang.String, java.lang.String, java.lang.String, com.xpn.xwiki.XWikiContext)since new index searcher instances are created for every query.

Parameters:
query - The base query, using the query engine supported by Lucene.
sortFields - A list of fields to sort results by. For each field, if the name starts with '-', then that field (excluding the -) is used for reverse sorting. If null or empty, sort by hit score.
myIndexDirs - Comma separated list of directories containing the lucene indexes to search.
languages - Comma separated list of language codes to search in, may be null or empty to search all languages.
context - The context of the request.
Returns:
The list of search results.
Throws:
java.lang.Exception - If the index directories cannot be read, or the query is invalid.

getSearchResultsFromIndexes

public SearchResults getSearchResultsFromIndexes(java.lang.String query,
                                                 java.lang.String sortField,
                                                 java.lang.String myIndexDirs,
                                                 java.lang.String languages,
                                                 com.xpn.xwiki.XWikiContext context)
                                          throws java.lang.Exception
Allows to search special named lucene indexes without having to configure them in xwiki.cfg. Slower than getSearchResults(String, String, String, String, XWikiContext) since new index searcher instances are created for every query.

Parameters:
query - The base query, using the query engine supported by Lucene.
sortField - The name of a field to sort results by. If the name starts with '-', then the field (excluding the -) is used for reverse sorting. If null or empty, sort by hit score.
myIndexDirs - Comma separated list of directories containing the lucene indexes to search.
languages - Comma separated list of language codes to search in, may be null or empty to search all languages.
context - The context of the request.
Returns:
The list of search results.
Throws:
java.lang.Exception - If the index directories cannot be read, or the query is invalid.

getSearchResults

public SearchResults getSearchResults(java.lang.String query,
                                      java.lang.String sortField,
                                      java.lang.String virtualWikiNames,
                                      java.lang.String languages,
                                      com.xpn.xwiki.XWikiContext context)
                               throws java.lang.Exception
Searches all Indexes configured in xwiki.cfg (property xwiki.plugins.lucene.indexdir).

Parameters:
query - The base query, using the query engine supported by Lucene.
sortField - The name of a field to sort results by. If the name starts with '-', then the field (excluding the -) is used for reverse sorting. If null or empty, sort by hit score.
virtualWikiNames - Comma separated list of virtual wiki names to search in, may be null to search all virtual wikis.
languages - Comma separated list of language codes to search in, may be null or empty to search all languages.
context - The context of the request.
Returns:
The list of search results.
Throws:
java.lang.Exception - If the index directories cannot be read, or the query is invalid.

getSearchResults

public SearchResults getSearchResults(java.lang.String query,
                                      java.lang.String[] sortField,
                                      java.lang.String virtualWikiNames,
                                      java.lang.String languages,
                                      com.xpn.xwiki.XWikiContext context)
                               throws java.lang.Exception
Searches all Indexes configured in xwiki.cfg (property xwiki.plugins.lucene.indexdir).

Parameters:
query - The base query, using the query engine supported by Lucene.
sortField - The name of a field to sort results by. If the name starts with '-', then the field (excluding the -) is used for reverse sorting. If null or empty, sort by hit score.
virtualWikiNames - Comma separated list of virtual wiki names to search in, may be null to search all virtual wikis.
languages - Comma separated list of language codes to search in, may be null or empty to search all languages.
context - The context of the request.
Returns:
The list of search results.
Throws:
java.lang.Exception - If the index directories cannot be read, or the query is invalid.

init

public void init(com.xpn.xwiki.XWikiContext context)
Specified by:
init in interface com.xpn.xwiki.plugin.XWikiPluginInterface
Overrides:
init in class com.xpn.xwiki.plugin.XWikiDefaultPlugin

flushCache

public void flushCache(com.xpn.xwiki.XWikiContext context)
Specified by:
flushCache in interface com.xpn.xwiki.plugin.XWikiPluginInterface
Overrides:
flushCache in class com.xpn.xwiki.plugin.XWikiDefaultPlugin

getName

public java.lang.String getName()
Specified by:
getName in interface com.xpn.xwiki.plugin.XWikiPluginInterface
Overrides:
getName in class com.xpn.xwiki.plugin.XWikiDefaultPlugin

getPluginApi

public com.xpn.xwiki.api.Api getPluginApi(com.xpn.xwiki.plugin.XWikiPluginInterface plugin,
                                          com.xpn.xwiki.XWikiContext context)
Specified by:
getPluginApi in interface com.xpn.xwiki.plugin.XWikiPluginInterface
Overrides:
getPluginApi in class com.xpn.xwiki.plugin.XWikiDefaultPlugin

createSearchers

public org.apache.lucene.search.Searcher[] createSearchers(java.lang.String indexDirs)
                                                    throws java.lang.Exception
Creates an array of Searchers for a number of lucene indexes.

Parameters:
indexDirs - Comma separated list of Lucene index directories to create searchers for.
Returns:
Array of searchers
Throws:
java.lang.Exception

openSearchers

protected void openSearchers()
Opens the searchers for the configured index Dirs after closing any already existing ones.


closeSearchers

protected static void closeSearchers(org.apache.lucene.search.Searcher[] searchers)
                              throws java.io.IOException
Throws:
java.io.IOException

getIndexDirs

public java.lang.String getIndexDirs()

getQueueSize

public long getQueueSize()

queueDocument

public void queueDocument(com.xpn.xwiki.doc.XWikiDocument doc,
                          com.xpn.xwiki.XWikiContext context)

queueAttachment

public void queueAttachment(com.xpn.xwiki.doc.XWikiDocument doc,
                            com.xpn.xwiki.doc.XWikiAttachment attach,
                            com.xpn.xwiki.XWikiContext context)

queueAttachment

public void queueAttachment(com.xpn.xwiki.doc.XWikiDocument doc,
                            com.xpn.xwiki.XWikiContext context)

getLuceneDocCount

public long getLuceneDocCount()
Returns:
the number of documents Lucene index writer.

getActiveQueueSize

public long getActiveQueueSize()
Returns:
the number of documents in the second queue gave to Lucene.


Copyright © 2004-2009 XWiki. All Rights Reserved.