Class LuceneSearchProvider

All Implemented Interfaces:
WikiProvider, SearchProvider
Direct Known Subclasses:

public class LuceneSearchProvider
extends java.lang.Object
implements SearchProvider
Interface for the search providers that handle searching the Wiki
  • Field Summary

    Modifier and Type Field Description
    static int FLAG_CONTEXTS
    Create contexts also.
    protected static org.apache.log4j.Logger log  
    protected static java.lang.String LUCENE_ATTACHMENTS  
    protected static java.lang.String LUCENE_AUTHOR  
    protected static java.lang.String LUCENE_ID  
    protected static java.lang.String LUCENE_PAGE_CONTENTS  
    protected static java.lang.String LUCENE_PAGE_KEYWORDS  
    protected static java.lang.String LUCENE_PAGE_NAME  
    protected java.util.List<java.lang.Object[]> m_updates  
    static int MAX_SEARCH_HITS
    The maximum number of hits to return from searches.
    static java.lang.String PROP_LUCENE_ANALYZER
    Which analyzer to use.
    static java.lang.String[] SEARCHABLE_FILE_SUFFIXES
    These attachment file suffixes will be indexed.

    Fields inherited from interface

  • Constructor Summary

    Constructor Description
  • Method Summary

    Modifier and Type Method Description
    protected void doFullLuceneReindex()
    Performs a full Lucene reindex, if necessary.
    java.util.Collection<SearchResult> findPages​(java.lang.String query, int flags, Context wikiContext)
    Searches pages using a particular combination of flags.
    java.util.Collection<SearchResult> findPages​(java.lang.String query, Context wikiContext)
    Search for pages matching a search query.
    protected java.lang.String getAttachmentContent​(java.lang.String attachmentName, int version)
    Fetches the attachment content from the repository.
    protected java.lang.String getAttachmentContent​(Attachment att)  
    protected Engine getEngine()
    Returns the handling engine.
    java.lang.String getProviderInfo()
    Return a valid HTML string for information.
    void initialize​(Engine engine, java.util.Properties props)
    Initializes the page provider.
    protected org.apache.lucene.document.Document luceneIndexPage​(Page page, java.lang.String text, org.apache.lucene.index.IndexWriter writer)
    Indexes page using the given IndexWriter.
    void pageRemoved​(Page page)
    Delete a page from the search index.
    void reindexPage​(Page page)
    Adds a page-text pair to the lucene update queue.
    protected void updateLuceneIndex​(Page page, java.lang.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 Details

  • Constructor Details

  • Method Details

    • initialize

      public void initialize​(Engine engine, java.util.Properties props) throws NoRequiredPropertyException,
      Initializes the page provider.
      Specified by:
      initialize in interface WikiProvider
      engine - Engine to own this provider
      props - A set of properties used to initialize this provider
      NoRequiredPropertyException - If the provider needs a property which is not found in the property set - If there is an IO problem
    • getEngine

      protected Engine getEngine()
      Returns the handling engine.
      Current Engine
    • doFullLuceneReindex

      protected void doFullLuceneReindex() throws
      Performs a full Lucene reindex, if necessary.
      Throws: - If there's a problem during indexing
    • getAttachmentContent

      protected java.lang.String getAttachmentContent​(java.lang.String attachmentName, int version)
      Fetches the attachment content from the repository. Content is flat text that can be used for indexing/searching or display
      attachmentName - Name of the attachment.
      version - The version of the attachment.
      the content of the Attachment as a String.
    • getAttachmentContent

      protected java.lang.String getAttachmentContent​(Attachment att)
      att - Attachment to get content for. Filename extension is used to determine the type of the attachment.
      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' way to search attachments
    • updateLuceneIndex

      protected void updateLuceneIndex​(Page page, java.lang.String text)
      Updates the lucene index for a single page.
      page - The WikiPage to check
      text - The page text to index.
    • luceneIndexPage

      protected org.apache.lucene.document.Document luceneIndexPage​(Page page, java.lang.String text, org.apache.lucene.index.IndexWriter writer) throws
      Indexes page using the given IndexWriter.
      page - WikiPage
      text - Page text to index
      writer - The Lucene IndexWriter to use for indexing
      the created index Document
      Throws: - If there's an indexing problem
    • pageRemoved

      public void pageRemoved​(Page page)
      Delete a page from the search index.
      Specified by:
      pageRemoved in interface SearchProvider
      page - Page to remove from search index.
    • reindexPage

      public void reindexPage​(Page page)
      Adds a page-text pair to the lucene update queue. Safe to call always
      Specified by:
      reindexPage in interface SearchProvider
      page - WikiPage to add to the update queue.
    • findPages

      public java.util.Collection<SearchResult> findPages​(java.lang.String query, Context wikiContext) throws ProviderException
      Search for pages matching a search query.
      Specified by:
      findPages in interface SearchProvider
      query - query to search for
      wikiContext - the context within which to run the search
      collection of pages that match query
      ProviderException - if the search provider failed.
    • findPages

      public java.util.Collection<SearchResult> findPages​(java.lang.String query, int flags, Context wikiContext) throws ProviderException
      Searches pages using a particular combination of flags.
      query - The query to perform in Lucene query language
      flags - A set of flags
      A Collection of SearchResult instances
      ProviderException - if there is a problem with the backend
    • getProviderInfo

      public java.lang.String getProviderInfo()
      Return a valid HTML string for information. May be anything.
      Specified by:
      getProviderInfo in interface WikiProvider
      A string describing the provider.