Package org.opengrok.indexer.search
Class SearchEngine
java.lang.Object
org.opengrok.indexer.search.SearchEngine
This is an encapsulation of the details on how to search in the index database.
This is used for searching via the REST API.
- Author:
- Trond Norbye 2005, Lubos Kosco - upgrade to lucene 3.x, 4.x, 5.x
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final org.apache.lucene.util.VersionVersion of Lucene index common for the whole application.static final String -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoiddestroy()Free resources associated with this instance.org.apache.lucene.document.Documentdoc(int docId) Gets the document of the specifieddocIdfromsearch(...)if it was called.Getter for property definition.getFile()Getter for property file.Getter for property freetext.Getter for property history.intGetter for property maxHitsPerFile.getQuery()Gets the instance fromsearch(...)if it was called.Gets the builder fromsearch(...)if it was called.org.apache.lucene.search.QueryGets the instance fromsearch(...)if it was called.org.apache.lucene.search.IndexSearcherGets the searcher fromsearch(...)if it was called.Getter for property sort.Getter for property symbol.getType()Getter for property type.booleanvoidGet results , if no search was started before, no results are returned.org.apache.lucene.search.ScoreDoc[]Gets the queried score docs fromsearch(...)if it was called.intsearch()Execute a search without authorization.intExecute a search aware of current request, limited to specific project names.voidsetDefinition(String definition) Setter for property definition.voidSetter for property file.voidsetFreetext(String freetext) Setter for property freetext.voidsetHistory(String history) Setter for property history.voidsetMaxHitsPerFile(int maxHitsPerFile) Sets the maximum number of matching lines returned per file inresults(int, int, java.util.List<org.opengrok.indexer.search.Hit>).voidsetSortOrder(SortOrder sortOrder) Setter for property sort.voidSetter for property symbol.voidSetter for property type.
-
Field Details
-
LUCENE_VERSION
public static final org.apache.lucene.util.Version LUCENE_VERSIONVersion of Lucene index common for the whole application. -
LUCENE_VERSION_HELP
-
-
Constructor Details
-
SearchEngine
public SearchEngine()Creates a new instance of SearchEngine.
-
-
Method Details
-
isValidQuery
public boolean isValidQuery() -
getQuery
Gets the instance fromsearch(...)if it was called.- Returns:
- defined instance or
null
-
getQueryObject
public org.apache.lucene.search.Query getQueryObject()Gets the instance fromsearch(...)if it was called.- Returns:
- defined instance or
null
-
getQueryBuilder
Gets the builder fromsearch(...)if it was called.(Modifying the builder will have no effect on this
SearchEngine.)- Returns:
- defined instance or
null
-
getSearcher
public org.apache.lucene.search.IndexSearcher getSearcher()Gets the searcher fromsearch(...)if it was called.- Returns:
- defined instance or
null
-
search
Execute a search aware of current request, limited to specific project names. This filters out all projects which are not allowed for the current request. Before calling this function, you must set the appropriate search criteria with the set-functions. Note that this search will return the first cachePages of hitsPerPage, for more you need to call more. Call to search() must be eventually followed by call to destroy() so that IndexSearcher objects are properly freed.- Parameters:
projects- projects to search- Returns:
- The number of hits
-
search
public int search()Execute a search without authorization. Before calling this function, you must set the appropriate search criteria with the set-functions. Note that this search will return the first cachePages of hitsPerPage, for more you need to call more. Call to search() must be eventually followed by call to destroy() so that IndexSearcher objects are properly freed.- Returns:
- The number of hits
-
scoreDocs
public org.apache.lucene.search.ScoreDoc[] scoreDocs()Gets the queried score docs fromsearch(...)if it was called.- Returns:
- a defined instance if a query succeeded, or
null
-
doc
Gets the document of the specifieddocIdfromsearch(...)if it was called.- Parameters:
docId- document ID- Returns:
- a defined instance if a query succeeded
- Throws:
IOException- if an error occurs obtaining the Lucene document by ID
-
results
Get results , if no search was started before, no results are returned. This method will requery ifendis more than first query from search, hence performance hit applies, if you want results in later pages than number of cachePages.endhas to be bigger thanstart!- Parameters:
start- start of the hit listend- end of the hit listret- list of results from start to end or null/empty if no search was started
-
destroy
public void destroy()Free resources associated with this instance. -
getDefinition
Getter for property definition.- Returns:
- Value of property definition.
-
setDefinition
Setter for property definition.- Parameters:
definition- New value of property definition.
-
getFile
Getter for property file.- Returns:
- Value of property file.
-
setFile
Setter for property file.- Parameters:
file- New value of property file.
-
getFreetext
Getter for property freetext.- Returns:
- Value of property freetext.
-
setFreetext
Setter for property freetext.- Parameters:
freetext- New value of property freetext.
-
getMaxHitsPerFile
public int getMaxHitsPerFile()Getter for property maxHitsPerFile.- Returns:
- Value of property maxHitsPerFile. 0 means unlimited.
-
setMaxHitsPerFile
public void setMaxHitsPerFile(int maxHitsPerFile) Sets the maximum number of matching lines returned per file inresults(int, int, java.util.List<org.opengrok.indexer.search.Hit>). 0 (the default) returns all matching lines, consistent with the HTML search page. Callers that need to bound response size can pass a positive value to cap per-file hits.- Parameters:
maxHitsPerFile- maximum hits per file, or 0 for unlimited.
-
getHistory
Getter for property history.- Returns:
- Value of property history.
-
setHistory
Setter for property history.- Parameters:
history- New value of property history.
-
getSymbol
Getter for property symbol.- Returns:
- Value of property symbol.
-
setSymbol
Setter for property symbol.- Parameters:
symbol- New value of property symbol.
-
getType
Getter for property type.- Returns:
- Value of property type.
-
setType
Setter for property type.- Parameters:
fileType- New value of property type.
-
getSortOrder
Getter for property sort.- Returns:
- Value of property sortOrder.
-
setSortOrder
Setter for property sort.- Parameters:
sortOrder- New value of property sortOrder.
-