Class SearchHelper

java.lang.Object
org.opengrok.indexer.web.SearchHelper

public class SearchHelper extends Object
Working set for a search basically to factor out/separate search related complexity from UI design.
Author:
Jens Elkner
  • Field Details

    • REQUEST_ATTR

      public static final String REQUEST_ATTR
      See Also:
    • PARSE_ERROR_MSG

      public static final String PARSE_ERROR_MSG
      Default query parse error message prefix.
      See Also:
    • SPELLCHECK_SUGGEST_WORD_COUNT

      public static final int SPELLCHECK_SUGGEST_WORD_COUNT
      Max number of words to suggest for spellcheck.
      See Also:
    • sort

      protected org.apache.lucene.search.Sort sort
      the Lucene sort instruction based on order created via prepareExec(SortedSet).
  • Method Details

    • getDataRoot

      public File getDataRoot()
    • getSourceRoot

      public File getSourceRoot()
    • getDesc

      public EftarFileReader getDesc()
    • getBuilder

      public QueryBuilder getBuilder()
    • getContextPath

      public String getContextPath()
    • setRedirect

      public void setRedirect(String redirect)
    • getRedirect

      public String getRedirect()
    • getErrorMsg

      public String getErrorMsg()
    • setErrorMsg

      public void setErrorMsg(String errorMsg)
    • 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

      public SortedSet<String> getProjects()
    • getSourceContext

      public Context getSourceContext()
    • getMaxItems

      public int getMaxItems()
    • getOrder

      public SortOrder getOrder()
    • getStart

      public int getStart()
    • getSummarizer

      public Summarizer getSummarizer()
    • getHistoryContext

      public HistoryContext getHistoryContext()
    • getFileTypeDescriptions

      public static Set<Map.Entry<String,String>> 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

      public SearchHelper prepareExec(SortedSet<String> projects)
      Create the searcher to use w.r.t. currently set parameters and the given projects. Does not produce any redirect link. It also does nothing if redirect or errorMsg have a none-null value.

      Parameters which should be populated/set at this time:

      • builder
      • dataRoot
      • order (falls back to relevance if unset)
      Populates/sets:
      • 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 in errorMsg.
      Returns:
      this instance
    • prepareExec

      public SearchHelper prepareExec(Project project)
      Calls prepareExec(java.util.SortedSet) with a single-element set for project.
      Parameters:
      project - a defined instance
      Returns:
      this instance
    • executeQuery

      public SearchHelper executeQuery()
      Start the search prepared by prepareExec(SortedSet). It does nothing if redirect or errorMsg 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)
      Populates/sets:
      • hits (see TopDocs.scoreDocs)
      • totalHits (see TopDocs.totalHits)
      • contextPath
      • errorMsg if an error occurs
      • redirect if certain conditions are met
      Returns:
      this instance
    • getSuggestions

      public List<Suggestion> 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

      public SearchHelper prepareSummary()
      Prepare the fields to support printing a full blown summary. Does nothing if redirect or errorMsg have a none-null value.

      Parameters which should be populated/set at this time:

      • query
      • builder
      Populates/sets: Otherwise the following fields are set (includes 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 index
      org.apache.lucene.queryparser.classic.ParseException - if an error happens when building the Lucene query
    • getTabSize

      public int getTabSize(Project proj) throws IOException
      Gets the persisted tabSize via SettingsHelper for the active reader.
      Parameters:
      proj - a defined instance or null 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 to relativePath according to indexed symlinks and translate (or not) accordingly.
      Parameters:
      project - the project name or empty string if projects are not used
      relativePath - 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