Package org.opengrok.indexer.web
Class SearchHelper
java.lang.Object
org.opengrok.indexer.web.SearchHelper
Working set for a search basically to factor out/separate search related
complexity from UI design.
- Author:
- Jens Elkner
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classBuilder Class for Search Helper. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringDefault query parse error message prefix.static final Stringprotected org.apache.lucene.search.Sortthe Lucene sort instruction based onordercreated viaprepareExec(SortedSet).static final intMax number of words to suggest for spellcheck. -
Method Summary
Modifier and TypeMethodDescriptionvoiddestroy()Free any resources associated with this helper.Start the search prepared byprepareExec(SortedSet).getDesc()User readable description for file types.org.apache.lucene.search.ScoreDoc[]getHits()intgetOrder()getPrimeRelativePath(String project, String relativePath) Determines if there is a prime equivalent torelativePathaccording to indexed symlinks and translate (or not) accordingly.org.apache.lucene.search.QuerygetQuery()org.apache.lucene.search.IndexSearcherintgetStart()If a search did not return a hit, one may use this method to obtain suggestions for a new search.intgetTabSize(Project proj) Gets the persisted tabSize viaSettingsHelperfor the active reader.longprepareExec(SortedSet<String> projects) Create the searcher to use w.r.t.prepareExec(Project project) CallsprepareExec(java.util.SortedSet)with a single-element set forproject.Prepare the fields to support printing a full blown summary.intsearchSingle(File file) Searches for a document for a single file from the index.voidsetErrorMsg(String errorMsg) voidsetRedirect(String redirect)
-
Field Details
-
REQUEST_ATTR
- See Also:
-
PARSE_ERROR_MSG
Default query parse error message prefix.- See Also:
-
SPELLCHECK_SUGGEST_WORD_COUNT
public static final int SPELLCHECK_SUGGEST_WORD_COUNTMax number of words to suggest for spellcheck.- See Also:
-
sort
protected org.apache.lucene.search.Sort sortthe Lucene sort instruction based onordercreated viaprepareExec(SortedSet).
-
-
Method Details
-
getDataRoot
-
getSourceRoot
-
getDesc
-
getBuilder
-
getContextPath
-
setRedirect
-
getRedirect
-
getErrorMsg
-
setErrorMsg
-
getSearcher
public org.apache.lucene.search.IndexSearcher getSearcher() -
getHits
public org.apache.lucene.search.ScoreDoc[] getHits() -
getQuery
public org.apache.lucene.search.Query getQuery() -
getTotalHits
public long getTotalHits() -
getProjects
-
getSourceContext
-
getMaxItems
public int getMaxItems() -
getOrder
-
getStart
public int getStart() -
getSummarizer
-
getHistoryContext
-
getFileTypeDescriptions
User readable description for file types. Only those listed in fileTypeDescription will be shown to the user. Returns a set of file type descriptions to be used for a search form.- Returns:
- Set of tuples with file type and description.
-
prepareExec
Create the searcher to use w.r.t. currently set parameters and the given projects. Does not produce anyredirectlink. It also does nothing ifredirectorerrorMsghave a none-nullvalue.Parameters which should be populated/set at this time:
builderdataRootorder(falls back to relevance if unset)
querysearchersortprojectserrorMsgif an error occurs
- Parameters:
projects- project names. If empty, a no-project setup is assumed (i.e. DATA_ROOT/index will be used instead of possible multiple DATA_ROOT/$project/index). If the set contains projects not known in the configuration or projects not yet indexed an error will be returned inerrorMsg.- Returns:
- this instance
-
prepareExec
CallsprepareExec(java.util.SortedSet)with a single-element set forproject.- Parameters:
project- a defined instance- Returns:
- this instance
-
executeQuery
Start the search prepared byprepareExec(SortedSet). It does nothing ifredirectorerrorMsghave a none-nullvalue.Parameters which should be populated/set at this time:
- all
fields required for and populated by
prepareExec(SortedSet)) start(default: 0)maxItems(default: 0)crossRefSearch(default: false)
hits(seeTopDocs.scoreDocs)totalHits(seeTopDocs.totalHits)contextPatherrorMsgif an error occursredirectif certain conditions are met
- Returns:
- this instance
- all
fields required for and populated by
-
getSuggestions
If a search did not return a hit, one may use this method to obtain suggestions for a new search.Parameters which should be populated/set at this time:
projectsdataRootbuilder
- Returns:
- a possible empty list of suggestions.
-
prepareSummary
Prepare the fields to support printing a full blown summary. Does nothing ifredirectorerrorMsghave a none-nullvalue.Parameters which should be populated/set at this time:
querybuilder
null):sourceContextsummarizerhistoryContext
- Returns:
- this instance.
-
destroy
public void destroy()Free any resources associated with this helper. -
searchSingle
public int searchSingle(File file) throws IOException, org.apache.lucene.queryparser.classic.ParseException Searches for a document for a single file from the index.- Parameters:
file- the file whose definitions to find- Returns:
ScoreDoc.docor -1 if it could not be found- Throws:
IOException- if an error happens when accessing the indexorg.apache.lucene.queryparser.classic.ParseException- if an error happens when building the Lucene query
-
getTabSize
Gets the persisted tabSize viaSettingsHelperfor the active reader.- Parameters:
proj- a defined instance ornullif no project is active- Returns:
- tabSize
- Throws:
IOException- if an I/O error occurs querying the active reader
-
getPrimeRelativePath
public String getPrimeRelativePath(String project, String relativePath) throws IOException, ForbiddenSymlinkException Determines if there is a prime equivalent torelativePathaccording to indexed symlinks and translate (or not) accordingly.- Parameters:
project- the project name or empty string if projects are not usedrelativePath- an OpenGrok-style (i.e. starting with a file separator) relative path- Returns:
- a prime relative path or just
relativePathif no prime is matched - Throws:
IOExceptionForbiddenSymlinkException
-