Package org.apache.wiki.search
Class LuceneSearchProvider
java.lang.Object
org.apache.wiki.search.LuceneSearchProvider
- All Implemented Interfaces:
WikiProvider,SearchProvider
- Direct Known Subclasses:
TikaSearchProvider
public class LuceneSearchProvider extends Object implements SearchProvider
Interface for the search providers that handle searching the Wiki
- Since:
- 2.2.21.
-
Field Summary
Fields Modifier and Type Field Description static intFLAG_CONTEXTSCreate contexts also.protected static org.apache.log4j.Loggerlogprotected static StringLUCENE_ATTACHMENTSprotected static StringLUCENE_AUTHORprotected static StringLUCENE_IDprotected static StringLUCENE_PAGE_CONTENTSprotected static StringLUCENE_PAGE_KEYWORDSprotected static StringLUCENE_PAGE_NAMEprotected List<Object[]>m_updatesstatic intMAX_SEARCH_HITSThe maximum number of hits to return from searches.static StringPROP_LUCENE_ANALYZERWhich analyzer to use.static String[]SEARCHABLE_FILE_SUFFIXESThese attachment file suffixes will be indexed.Fields inherited from interface org.apache.wiki.api.providers.WikiProvider
LATEST_VERSION -
Constructor Summary
Constructors Constructor Description LuceneSearchProvider() -
Method Summary
Modifier and Type Method Description protected voiddoFullLuceneReindex()Performs a full Lucene reindex, if necessary.Collection<SearchResult>findPages(String query, int flags, Context wikiContext)Searches pages using a particular combination of flags.Collection<SearchResult>findPages(String query, Context wikiContext)Search for pages matching a search query.protected StringgetAttachmentContent(String attachmentName, int version)Fetches the attachment content from the repository.protected StringgetAttachmentContent(Attachment att)protected EnginegetEngine()Returns the handling engine.StringgetProviderInfo()Return a valid HTML string for information.voidinitialize(Engine engine, Properties props)Initializes the page provider.protected org.apache.lucene.document.DocumentluceneIndexPage(Page page, String text, org.apache.lucene.index.IndexWriter writer)Indexes page using the given IndexWriter.voidpageRemoved(Page page)Delete a page from the search index.voidreindexPage(Page page)Adds a page-text pair to the lucene update queue.protected voidupdateLuceneIndex(Page page, String text)Updates the lucene index for a single page.
-
Field Details
-
log
-
PROP_LUCENE_ANALYZER
Which analyzer to use. Default is StandardAnalyzer.- See Also:
- Constant Field Values
-
SEARCHABLE_FILE_SUFFIXES
These attachment file suffixes will be indexed. -
LUCENE_ID
- See Also:
- Constant Field Values
-
LUCENE_PAGE_CONTENTS
- See Also:
- Constant Field Values
-
LUCENE_AUTHOR
- See Also:
- Constant Field Values
-
LUCENE_ATTACHMENTS
- See Also:
- Constant Field Values
-
LUCENE_PAGE_NAME
- See Also:
- Constant Field Values
-
LUCENE_PAGE_KEYWORDS
- See Also:
- Constant Field Values
-
m_updates
-
MAX_SEARCH_HITS
The maximum number of hits to return from searches.- See Also:
- Constant Field Values
-
FLAG_CONTEXTS
Create contexts also. Generating contexts can be expensive, so they're not on by default.- See Also:
- Constant Field Values
-
-
Constructor Details
-
LuceneSearchProvider
public LuceneSearchProvider()
-
-
Method Details
-
initialize
public void initialize(Engine engine, Properties props) throws NoRequiredPropertyException, IOExceptionInitializes the page provider.- Specified by:
initializein interfaceWikiProvider- Parameters:
engine- Engine to own this providerprops- A set of properties used to initialize this provider- Throws:
NoRequiredPropertyException- If the provider needs a property which is not found in the property setIOException- If there is an IO problem
-
getEngine
Returns the handling engine.- Returns:
- Current Engine
-
doFullLuceneReindex
Performs a full Lucene reindex, if necessary.- Throws:
IOException- If there's a problem during indexing
-
getAttachmentContent
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
- 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' way to search attachments
-
updateLuceneIndex
Updates the lucene index for a single page.- Parameters:
page- The WikiPage to checktext- The page text to index.
-
luceneIndexPage
protected org.apache.lucene.document.Document luceneIndexPage(Page page, String text, org.apache.lucene.index.IndexWriter writer) throws IOExceptionIndexes page using the given IndexWriter.- Parameters:
page- WikiPagetext- Page text to indexwriter- The Lucene IndexWriter to use for indexing- Returns:
- the created index Document
- Throws:
IOException- If there's an indexing problem
-
pageRemoved
Delete a page from the search index.- Specified by:
pageRemovedin interfaceSearchProvider- Parameters:
page- Page to remove from search index.
-
reindexPage
Adds a page-text pair to the lucene update queue. Safe to call always- Specified by:
reindexPagein interfaceSearchProvider- Parameters:
page- WikiPage to add to the update queue.
-
findPages
public Collection<SearchResult> findPages(String query, Context wikiContext) throws ProviderExceptionSearch for pages matching a search query.- Specified by:
findPagesin interfaceSearchProvider- Parameters:
query- query to search forwikiContext- the context within which to run the search- Returns:
- collection of pages that match query
- Throws:
ProviderException- if the search provider failed.
-
findPages
public Collection<SearchResult> findPages(String query, int flags, Context wikiContext) throws ProviderExceptionSearches pages using a particular combination of flags.- Parameters:
query- The query to perform in Lucene query languageflags- A set of flags- Returns:
- A Collection of SearchResult instances
- Throws:
ProviderException- if there is a problem with the backend
-
getProviderInfo
Return a valid HTML string for information. May be anything.- Specified by:
getProviderInfoin interfaceWikiProvider- Returns:
- A string describing the provider.
-