Class SearchTextParser

java.lang.Object
ch.tocco.nice2.toolbox.api.string.SearchTextParser
All Implemented Interfaces:
Iterable<SearchTextParser.QueryTerm>

public class SearchTextParser extends Object implements Iterable<SearchTextParser.QueryTerm>
Parses fulltext search input text as expected.

Rules:

  • Any text appearing in quotes is treated as a single search token.
  • Duplicates are removed in a case sensitive way.
  • Tokens are returned in the order they are found (LinkedHashMap).
  • Tokens are trimmed. The only place where (multiple) whitespace remains is within quotes between words, eg "foo bar".
  • Wildcard characters in terms are preserved, eg auto*

Limits:

  • Does not handle operators AND, OR, NOT.
  • Does not handle brackets.

Original source: http://www.javapractices.com/topic/TopicAction.do?Id=87

  • Field Details

  • Constructor Details

    • SearchTextParser

      public SearchTextParser(String aSearchText)
      Parameters:
      aSearchText - May be empty, and represents what the user has input in a search box.
  • Method Details