java.lang.Object
ch.tocco.nice2.enterprisesearch.impl.searchbuilder.SearchTerm

public class SearchTerm extends Object
SearchTerm is the representation of a lucene search term, which can handle parentheses, asterisks and field prefixes. It can be used to transform an and decorate an input according to the applications needs. By default, a SearchTerm will only match the exact search string, except it already has WILDCARDs in it. If it should match the search string as beginnings or endings, the corresponding methods can be used. Keep in mind that setting withMatchBeginningCondition() and withMatchEndingCondition() results in (example OR example* OR *example), not (*example*).
  • Method Details

    • getInstance

      public static SearchTerm getInstance(String searchInput)
      Creates a new SearchTerm for the given input to be used in lucene queries. By default, the term is created for exact matches.
      Parameters:
      searchInput - the input as retrieved from the application
      Returns:
      the SearchTerm instance
    • withMatchEndingCondition

      public SearchTerm withMatchEndingCondition()
      Adds a condition to also match text which ends with the search string. Done so by adding an OR clause to the final search term containing the search text with an WILDCARD added to the beginning.
      Returns:
      the modified SearchTerm
    • withMatchBeginningCondition

      public SearchTerm withMatchBeginningCondition()
      Adds a condition to also match text which starts with the search string. Done so by adding an OR clause to the final search term containing the search text with an WILDCARD added to the end.
      Returns:
      the modified SearchTerm
    • asString

      public String asString()
      Returns the SearchTerm as string representation as it can be used in lucene queries, taking asterisks, parentheses and field prefixes into account.
      Returns:
      the stringified representation of this SearchTerm