Class SearchQuery

java.lang.Object
com.codename1.backend.search.SearchQuery

public final class SearchQuery extends Object

What to search for: text, exact filters, an order, a page, and the fields to count facet values of.

SearchQuery q = new SearchQuery("red running shoes")
        .fields("name", "description")
        .filter("brand", "acme")
        .facet("color")
        .page(0, 20);
  • Constructor Details

    • SearchQuery

      public SearchQuery(String text)
      A query for text; null or empty matches every document.
  • Method Details

    • fields

      public SearchQuery fields(String... names)
      Matches only in these fields instead of every string.
    • filter

      public SearchQuery filter(String field, Object value)
      Keeps only documents whose field equals value exactly. Several filters must all hold.
    • sort

      public SearchQuery sort(String field, boolean ascending)
      Orders by a field instead of by relevance.
    • page

      public SearchQuery page(int from, int size)
      The page: skip from hits and return at most size.
    • facet

      public SearchQuery facet(String field)
      Counts the values of field over all matches, in SearchResult.getFacets(). On Elasticsearch and OpenSearch the field must be a keyword field -- with dynamic mapping, name.keyword for name.
    • highlight

      public SearchQuery highlight(boolean on)
      Asks for highlighted fragments of the matched text.
    • getText

      public String getText()
      The text, trimmed; empty matches everything.
    • getFields

      public List getFields()
      The fields to match in; empty for all.
    • getFilters

      public Map getFilters()
      Field to exact value.
    • getFacets

      public List getFacets()
      The facet fields.
    • getSortField

      public String getSortField()
      The sort field, or null for relevance.
    • isSortAscending

      public boolean isSortAscending()
      Whether the sort is ascending.
    • getFrom

      public int getFrom()
      Hits skipped.
    • getSize

      public int getSize()
      Hits returned at most.
    • isHighlight

      public boolean isHighlight()
      Whether highlights were asked for.