Class SearchEngine

java.lang.Object
org.opengrok.indexer.search.SearchEngine

public class SearchEngine extends Object
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 Details

    • LUCENE_VERSION

      public static final org.apache.lucene.util.Version LUCENE_VERSION
      Version of Lucene index common for the whole application.
    • LUCENE_VERSION_HELP

      public static final String LUCENE_VERSION_HELP
  • Constructor Details

    • SearchEngine

      public SearchEngine()
      Creates a new instance of SearchEngine.
  • Method Details

    • isValidQuery

      public boolean isValidQuery()
    • getQuery

      public String getQuery()
      Gets the instance from search(...) if it was called.
      Returns:
      defined instance or null
    • getQueryObject

      public org.apache.lucene.search.Query getQueryObject()
      Gets the instance from search(...) if it was called.
      Returns:
      defined instance or null
    • getQueryBuilder

      public QueryBuilder getQueryBuilder()
      Gets the builder from search(...) 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 from search(...) if it was called.
      Returns:
      defined instance or null
    • search

      public int search(List<Project> projects)
      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 from search(...) if it was called.
      Returns:
      a defined instance if a query succeeded, or null
    • doc

      public org.apache.lucene.document.Document doc(int docId) throws IOException
      Gets the document of the specified docId from search(...) 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

      public void results(int start, int end, List<Hit> ret)
      Get results , if no search was started before, no results are returned. This method will requery if end is more than first query from search, hence performance hit applies, if you want results in later pages than number of cachePages. end has to be bigger than start !
      Parameters:
      start - start of the hit list
      end - end of the hit list
      ret - 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

      public String getDefinition()
      Getter for property definition.
      Returns:
      Value of property definition.
    • setDefinition

      public void setDefinition(String definition)
      Setter for property definition.
      Parameters:
      definition - New value of property definition.
    • getFile

      public String getFile()
      Getter for property file.
      Returns:
      Value of property file.
    • setFile

      public void setFile(String file)
      Setter for property file.
      Parameters:
      file - New value of property file.
    • getFreetext

      public String getFreetext()
      Getter for property freetext.
      Returns:
      Value of property freetext.
    • setFreetext

      public void setFreetext(String freetext)
      Setter for property freetext.
      Parameters:
      freetext - New value of property freetext.
    • getHistory

      public String getHistory()
      Getter for property history.
      Returns:
      Value of property history.
    • setHistory

      public void setHistory(String history)
      Setter for property history.
      Parameters:
      history - New value of property history.
    • getSymbol

      public String getSymbol()
      Getter for property symbol.
      Returns:
      Value of property symbol.
    • setSymbol

      public void setSymbol(String symbol)
      Setter for property symbol.
      Parameters:
      symbol - New value of property symbol.
    • getType

      public String getType()
      Getter for property type.
      Returns:
      Value of property type.
    • setType

      public void setType(String fileType)
      Setter for property type.
      Parameters:
      fileType - New value of property type.