org.apache.wiki.search
Class LuceneSearchProvider

java.lang.Object
  extended by org.apache.wiki.search.LuceneSearchProvider
All Implemented Interfaces:
SearchProvider, WikiProvider

public class LuceneSearchProvider
extends Object
implements SearchProvider

Interface for the search providers that handle searching the Wiki

Since:
2.2.21.

Field Summary
static int FLAG_CONTEXTS
          Create contexts also.
protected static org.apache.log4j.Logger log
           
protected static String LUCENE_ATTACHMENTS
           
protected static String LUCENE_AUTHOR
           
protected static String LUCENE_ID
           
protected static String LUCENE_PAGE_CONTENTS
           
protected static String LUCENE_PAGE_NAME
           
protected  Vector<Object[]> m_updates
           
static int MAX_SEARCH_HITS
          The maximum number of hits to return from searches.
static String PROP_LUCENE_ANALYZER
          Which analyzer to use.
static String[] SEARCHABLE_FILE_SUFFIXES
          These attachment file suffixes will be indexed.
 
Fields inherited from interface org.apache.wiki.WikiProvider
LATEST_VERSION
 
Constructor Summary
LuceneSearchProvider()
           
 
Method Summary
protected  void doFullLuceneReindex()
          Performs a full Lucene reindex, if necessary.
 Collection findPages(String query)
          Search for pages matching a search query
 Collection findPages(String query, int flags)
          Searches pages using a particular combination of flags.
protected  String getAttachmentContent(Attachment att)
           
protected  String getAttachmentContent(String attachmentName, int version)
          Fetches the attachment content from the repository.
protected  WikiEngine getEngine()
          Returns the handling engine.
 String getProviderInfo()
          Return a valid HTML string for information.
 void initialize(WikiEngine engine, Properties props)
          Initializes the page provider.
protected  org.apache.lucene.document.Document luceneIndexPage(WikiPage page, String text, org.apache.lucene.index.IndexWriter writer)
          Indexes page using the given IndexWriter.
 void pageRemoved(WikiPage page)
          Delete a page from the search index
 void reindexPage(WikiPage page)
          Adds a page-text pair to the lucene update queue.
protected  void updateLuceneIndex(WikiPage page, String text)
          Updates the lucene index for a single page.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

protected static final org.apache.log4j.Logger log

PROP_LUCENE_ANALYZER

public static final String PROP_LUCENE_ANALYZER
Which analyzer to use. Default is StandardAnalyzer.

See Also:
Constant Field Values

SEARCHABLE_FILE_SUFFIXES

public static final String[] SEARCHABLE_FILE_SUFFIXES
These attachment file suffixes will be indexed.


LUCENE_ID

protected static final String LUCENE_ID
See Also:
Constant Field Values

LUCENE_PAGE_CONTENTS

protected static final String LUCENE_PAGE_CONTENTS
See Also:
Constant Field Values

LUCENE_AUTHOR

protected static final String LUCENE_AUTHOR
See Also:
Constant Field Values

LUCENE_ATTACHMENTS

protected static final String LUCENE_ATTACHMENTS
See Also:
Constant Field Values

LUCENE_PAGE_NAME

protected static final String LUCENE_PAGE_NAME
See Also:
Constant Field Values

m_updates

protected Vector<Object[]> m_updates

MAX_SEARCH_HITS

public static final int MAX_SEARCH_HITS
The maximum number of hits to return from searches.

See Also:
Constant Field Values

FLAG_CONTEXTS

public static final int FLAG_CONTEXTS
Create contexts also. Generating contexts can be expensive, so they're not on by default.

See Also:
Constant Field Values
Constructor Detail

LuceneSearchProvider

public LuceneSearchProvider()
Method Detail

initialize

public void initialize(WikiEngine engine,
                       Properties props)
                throws NoRequiredPropertyException,
                       IOException
Initializes the page provider.

Specified by:
initialize in interface WikiProvider
Parameters:
engine - WikiEngine to own this provider
props - A set of properties used to initialize this provider
Throws:
NoRequiredPropertyException - If the provider needs a property which is not found in the property set
IOException - If there is an IO problem

getEngine

protected WikiEngine getEngine()
Returns the handling engine.

Returns:
Current WikiEngine

doFullLuceneReindex

protected void doFullLuceneReindex()
                            throws IOException
Performs a full Lucene reindex, if necessary.

Throws:
IOException - If there's a problem during indexing

getAttachmentContent

protected String getAttachmentContent(String attachmentName,
                                      int version)
Fetches the attachment content from the repository. Content is flat text that can be used for indexing/searching or display

Parameters:
attachmentName - Name of the attachment.
version - The version of the attachment.
Returns:
the content of the Attachment as a String.

getAttachmentContent

protected String getAttachmentContent(Attachment att)
Parameters:
att - Attachment to get content for. Filename extension is used to determine the type of the attachment.
Returns:
String representing the content of the file. FIXME This is a very simple implementation of some text-based attachment, mainly used for testing. This should be replaced /moved to Attachment search providers or some other 'pluggable' wat to search attachments

updateLuceneIndex

protected void updateLuceneIndex(WikiPage page,
                                 String text)
Updates the lucene index for a single page.

Parameters:
page - The WikiPage to check
text - The page text to index.

luceneIndexPage

protected org.apache.lucene.document.Document luceneIndexPage(WikiPage page,
                                                              String text,
                                                              org.apache.lucene.index.IndexWriter writer)
                                                       throws IOException
Indexes page using the given IndexWriter.

Parameters:
page - WikiPage
text - Page text to index
writer - The Lucene IndexWriter to use for indexing
Returns:
the created index Document
Throws:
IOException - If there's an indexing problem

pageRemoved

public void pageRemoved(WikiPage page)
Delete a page from the search index

Specified by:
pageRemoved in interface SearchProvider
Parameters:
page - Page to remove from search index

reindexPage

public void reindexPage(WikiPage page)
Adds a page-text pair to the lucene update queue. Safe to call always

Specified by:
reindexPage in interface SearchProvider
Parameters:
page - WikiPage to add to the update queue.

findPages

public Collection findPages(String query)
                     throws ProviderException
Search for pages matching a search query

Specified by:
findPages in interface SearchProvider
Parameters:
query - query to search for
Returns:
collection of pages that match query
Throws:
ProviderException - if the search provider failed.

findPages

public Collection findPages(String query,
                            int flags)
                     throws ProviderException
Searches pages using a particular combination of flags.

Parameters:
query - The query to perform in Lucene query language
flags - A set of flags
Returns:
A Collection of SearchResult instances
Throws:
ProviderException - if there is a problem with the backend

getProviderInfo

public String getProviderInfo()
Return a valid HTML string for information. May be anything.

Specified by:
getProviderInfo in interface WikiProvider
Returns:
A string describing the provider.


Copyright © {inceptionYear}-2014 The Apache Software Foundation. All rights reserved.