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 class
Builder Class for Search Helper. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final String
Default query parse error message prefix.static final String
protected org.apache.lucene.search.Sort
the Lucene sort instruction based onorder
created viaprepareExec(SortedSet)
.static final int
Max number of words to suggest for spellcheck. -
Method Summary
Modifier and TypeMethodDescriptionvoid
destroy()
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()
int
getOrder()
getPrimeRelativePath
(String project, String relativePath) Determines if there is a prime equivalent torelativePath
according to indexed symlinks and translate (or not) accordingly.org.apache.lucene.search.Query
getQuery()
org.apache.lucene.search.IndexSearcher
int
getStart()
If a search did not return a hit, one may use this method to obtain suggestions for a new search.int
getTabSize
(Project proj) Gets the persisted tabSize viaSettingsHelper
for the active reader.long
prepareExec
(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.int
searchSingle
(File file) Searches for a document for a single file from the index.void
setErrorMsg
(String errorMsg) void
setRedirect
(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 onorder
created 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 anyredirect
link. It also does nothing ifredirect
orerrorMsg
have a none-null
value.Parameters which should be populated/set at this time:
builder
dataRoot
order
(falls back to relevance if unset)
query
searcher
sort
projects
errorMsg
if 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 ifredirect
orerrorMsg
have a none-null
value.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
)contextPath
errorMsg
if an error occursredirect
if 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:
projects
dataRoot
builder
- Returns:
- a possible empty list of suggestions.
-
prepareSummary
Prepare the fields to support printing a full blown summary. Does nothing ifredirect
orerrorMsg
have a none-null
value.Parameters which should be populated/set at this time:
query
builder
null
):sourceContext
summarizer
historyContext
- 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.doc
or -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 viaSettingsHelper
for the active reader.- Parameters:
proj
- a defined instance ornull
if 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 torelativePath
according 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
relativePath
if no prime is matched - Throws:
IOException
ForbiddenSymlinkException
-