public class LuceneSearchEngine extends AbstractSearchEngine
SearchEngine interface using lucene
as underlying search-engine.| Modifier and Type | Field and Description |
|---|---|
private org.apache.lucene.analysis.Analyzer |
analyzer
The lucene
Analyzer. |
private LuceneFieldManager |
fieldManager |
private org.apache.lucene.search.highlight.Formatter |
highlightFormatter |
private org.apache.lucene.index.IndexReader |
indexReader
The
IndexReader used for the searcher. |
private SearchQueryBuilder |
queryBuilder |
private SearchDependencies |
searchDependencies |
private org.apache.lucene.search.Searcher |
searcher
The actual lucene
Searcher. |
| Constructor and Description |
|---|
LuceneSearchEngine(org.apache.lucene.index.IndexReader indexReader,
org.apache.lucene.analysis.Analyzer analyzer,
SearchQueryBuilder queryBuilder,
org.apache.lucene.search.highlight.Formatter highlightFormatter,
LuceneFieldManager fieldManager,
SearchDependencies searchDependencies)
The constructor.
|
LuceneSearchEngine(org.apache.lucene.index.IndexReader indexReader,
org.apache.lucene.analysis.Analyzer analyzer,
SearchQueryBuilder queryBuilder,
org.apache.lucene.search.highlight.Formatter highlightFormatter,
LuceneFieldManager fieldManager,
SearchDependencies searchDependencies,
PeriodicRefresher periodicRefresher)
The constructor.
|
| Modifier and Type | Method and Description |
|---|---|
void |
close()
This method disposes the search-engine.
|
long |
count(String field,
String value)
|
protected SearchHighlighter |
createSearchHighlighter(org.apache.lucene.search.Query luceneQuery)
This method creates a new instance of the
SearchHighlighter for a SearchResultPage. |
protected SearchHit |
createSearchHit(int documentId,
double score,
SearchHighlighter searchHighlighter)
|
SearchEntry |
getEntry(int documentId) |
SearchEntry |
getEntry(String entryId)
|
protected LuceneFieldManager |
getFieldManager()
This method gets the
LuceneFieldManager. |
protected org.apache.lucene.search.highlight.Formatter |
getHighlightFormatter() |
protected org.apache.lucene.search.Query |
getLuceneQuery(SearchQuery query)
This method gets the lucene
Query for the given query. |
SearchQueryBuilder |
getQueryBuilder()
This method gets the query builder user to create and parse queries.
|
protected SearchDependencies |
getSearchDependencies()
This method gets the
SearchDependencies. |
long |
getTotalEntryCount()
This method gets the total number of
SearchEntrys in the search-index. |
boolean |
refresh()
This method tells the search-engine to refresh explicitly.
|
SearchResultPage |
search(SearchQuery query,
int hitsPerPage)
This method performs an initial search for a given
query and returns the first
SearchResultPage. |
SearchResultPage |
search(SearchQuery query,
int hitsPerPage,
int pageIndex,
int totalHitCount)
This method performs a search for a subsequent
SearchResultPage of an
initial search. |
initializegetLoggerprivate final org.apache.lucene.analysis.Analyzer analyzer
Analyzer.private final SearchQueryBuilder queryBuilder
getQueryBuilder()private final org.apache.lucene.search.highlight.Formatter highlightFormatter
getHighlightFormatter()private final LuceneFieldManager fieldManager
getFieldManager()private final SearchDependencies searchDependencies
getSearchDependencies()private org.apache.lucene.index.IndexReader indexReader
IndexReader used for the searcher.private org.apache.lucene.search.Searcher searcher
Searcher.public LuceneSearchEngine(org.apache.lucene.index.IndexReader indexReader,
org.apache.lucene.analysis.Analyzer analyzer,
SearchQueryBuilder queryBuilder,
org.apache.lucene.search.highlight.Formatter highlightFormatter,
LuceneFieldManager fieldManager,
SearchDependencies searchDependencies,
PeriodicRefresher periodicRefresher)
indexReader - is the IndexReader to access the index.analyzer - is the Analyzer to use.queryBuilder - is the SearchQueryBuilder query builder.highlightFormatter - is the Formatter for highlighting.fieldManager - is the LuceneFieldManager.searchDependencies - are the SearchDependencies.periodicRefresher - is the PeriodicRefresher.public LuceneSearchEngine(org.apache.lucene.index.IndexReader indexReader,
org.apache.lucene.analysis.Analyzer analyzer,
SearchQueryBuilder queryBuilder,
org.apache.lucene.search.highlight.Formatter highlightFormatter,
LuceneFieldManager fieldManager,
SearchDependencies searchDependencies)
indexReader - is the IndexReader.analyzer - is the Analyzer to use.queryBuilder - is the SearchQueryBuilder query builder.highlightFormatter - is the Formatter for highlighting.fieldManager - is the LuceneFieldManager.searchDependencies - are the SearchDependencies.protected SearchDependencies getSearchDependencies()
SearchDependencies.SearchDependencies.protected LuceneFieldManager getFieldManager()
LuceneFieldManager.LuceneFieldManager.public SearchQueryBuilder getQueryBuilder()
protected org.apache.lucene.search.highlight.Formatter getHighlightFormatter()
protected org.apache.lucene.search.Query getLuceneQuery(SearchQuery query)
Query for the given query.query - is the SearchQuery to "convert".Query.protected SearchHighlighter createSearchHighlighter(org.apache.lucene.search.Query luceneQuery)
SearchHighlighter for a SearchResultPage.luceneQuery - is the lucene Query used for highlighting.SearchHighlighter.protected SearchHit createSearchHit(int documentId, double score, SearchHighlighter searchHighlighter)
documentId - is the technical ID of the lucene Document representing the hit.score - is the score of the hit.searchHighlighter - is used to create the highlighted text.SearchHit.public SearchResultPage search(SearchQuery query, int hitsPerPage)
query and returns the first
SearchResultPage. The hits are in descending order of their
score so the best hit is the first
hit of the page . SearchResultPage use
SearchEngine.search(SearchQuery, int, int, int).query - is the query of the user that wants to search. Use the
query-builder to construct.hitsPerPage - is the number of hits per page. See
SearchResultPage.DEFAULT_HITS_PER_PAGE.query at the given pageIndex.SearchEngine.getQueryBuilder()public SearchResultPage search(SearchQuery query, int hitsPerPage, int pageIndex, int totalHitCount)
SearchResultPage of an
initial search. The hits are in descending order of
their score.query - is the query of the user that wants to search. Use the
query-builder to construct.hitsPerPage - is the number of hits contained in a SearchResultPage. This
should be the same value as in the initial search.pageIndex - is the page index of the requested
search result. For a new query this should initially be 0.
After a search result was retrieved by this method, further calls for the
same query can be performed with
a pageIndex greater than 0 and less than
SearchResultPage.getPageCount(). pageIndex is always valid in the sense as described
above (the search index may have been modified in the meantime). An implementation has to be able
to handle calls with a pageIndex greater or equal to
SearchResultPage.getPageCount(). The recommended strategy is to return the
last page in this case.totalHitCount - is the total hit count expected for this
query that is already known from the initial search. The
implementation has to be able to handle that the search index may have been modified in the
meantime and the value is NOT correct anymore. If the implementation can determine the correct
total hit-count without performance overhead, it may ignore this parameter.query at the given pageIndex.public long count(String field, String value)
SearchEntrys where the given field has the given
value. This can be useful for counting the SearchEntrys of a particular
source or type. You could also do a search
to figure this out but this method is supposed to be much faster.field - is the name of the field.value - is the potential value to match.SearchEntrys.public long getTotalEntryCount()
SearchEntrys in the search-index.SearchEntrys.public SearchEntry getEntry(String entryId)
entry by its technical entry-ID. hit in a new request (without
rerunning the search).entryId - is the ID of the requested entry.id or null if no such entry is available.public SearchEntry getEntry(int documentId)
documentId - is the technical ID of the lucene Document representing the hit.SearchEntry.getEntry(String)public boolean refresh()
ManagedSearchEngine.refresh(). true if something has changed, false otherwise. If the implementation can not determine the
change it should return true.public void close()
close in interface Closeableclose in interface AutoCloseableclose in interface ManagedSearchEngineclose in class AbstractSearchEngineCopyright © 2001–2016 mmm-Team. All rights reserved.