Class AbstractSearchQuery

java.lang.Object
org.opencastproject.elasticsearch.impl.AbstractSearchQuery
All Implemented Interfaces:
SearchQuery
Direct Known Subclasses:
EventSearchQuery, SeriesSearchQuery, ThemeSearchQuery

public abstract class AbstractSearchQuery extends Object implements SearchQuery
Base implementation for search queries.
  • Field Details

    • types

      protected List<String> types
      The document types
    • fields

      protected List<String> fields
      The list of fields to return
    • fuzzySearch

      protected boolean fuzzySearch
      True if the search text should be matched using wildcards
    • text

      protected List<SearchTerms<String>> text
      Query terms
    • filter

      protected String filter
      Filter terms
    • offset

      protected int offset
      The query offset
    • limit

      protected int limit
      The query limit
  • Constructor Details

    • AbstractSearchQuery

      protected AbstractSearchQuery()
      Creates a search query that is executed on all document types.
    • AbstractSearchQuery

      public AbstractSearchQuery(String documentType)
      Creates a search query that is executed on the given document type.
      Parameters:
      documentType - the document type
  • Method Details

    • withTypes

      public SearchQuery withTypes(String... types)
      Description copied from interface: SearchQuery
      Return documents of the given types.
      Specified by:
      withTypes in interface SearchQuery
      Parameters:
      types - the resource types to look up
      Returns:
      the query extended by this criterion
    • getTypes

      public String[] getTypes()
      Description copied from interface: SearchQuery
      Returns the document types or or an empty array if no types were specified.
      Specified by:
      getTypes in interface SearchQuery
      Returns:
      the type
    • withField

      public AbstractSearchQuery withField(String field)
      Description copied from interface: SearchQuery
      Adds a field that needs to be returned by the query. If no fields are being set, all fields will be returned.
      Specified by:
      withField in interface SearchQuery
      Parameters:
      field - the field name
      Returns:
      the query
    • withFields

      public AbstractSearchQuery withFields(String... fields)
      Description copied from interface: SearchQuery
      Adds the fields that need to be returned by the query. If no fields are being set, all fields will be returned.
      Specified by:
      withFields in interface SearchQuery
      Parameters:
      fields - the field names
      Returns:
      the query
    • getFields

      public String[] getFields()
      Description copied from interface: SearchQuery
      Returns the fields that should be returned by the query. If all fields should be returned, the method will return an empty array.
      Specified by:
      getFields in interface SearchQuery
      Returns:
      the names of the fields to return
    • withLimit

      public SearchQuery withLimit(int limit)
      Description copied from interface: SearchQuery
      Sets the number of results that are returned.
      Specified by:
      withLimit in interface SearchQuery
      Parameters:
      limit - the number of results
      Returns:
      the search query
    • getLimit

      public int getLimit()
      Description copied from interface: SearchQuery
      Returns the number of results that are returned, starting at the offset returned by getOffset(). If no limit was specified, this method returns -1.
      Specified by:
      getLimit in interface SearchQuery
      Returns:
      the maximum number of results
    • withOffset

      public SearchQuery withOffset(int offset)
      Description copied from interface: SearchQuery
      Sets the starting offset. Search results will be returned starting at that offset and until the limit is reached, as specified by getLimit().
      Specified by:
      withOffset in interface SearchQuery
      Parameters:
      offset - the starting offset
      Returns:
      the search query
    • getOffset

      public int getOffset()
      Description copied from interface: SearchQuery
      Returns the starting offset within the search result or 0 if no offset was specified.
      Specified by:
      getOffset in interface SearchQuery
      Returns:
      the offset
    • withText

      public SearchQuery withText(String text)
      Description copied from interface: SearchQuery
      Returns documents that contain the given text.
      Specified by:
      withText in interface SearchQuery
      Parameters:
      text - the text to look up
      Returns:
      the query extended by this criterion
    • withText

      public SearchQuery withText(boolean fuzzy, String text)
      Description copied from interface: SearchQuery
      Returns documents that contain the given text.
      Specified by:
      withText in interface SearchQuery
      Parameters:
      fuzzy - True to perform a (much slower) wildcard search
      text - the text to look up
      Returns:
      the query extended by this criterion
    • withText

      public SearchQuery withText(boolean fuzzy, SearchTerms.Quantifier quantifier, String... text)
      Description copied from interface: SearchQuery
      Returns documents that contain the given text.

      Depending on the quantifier, either documents are returned that contain at least one of the terms are only documents containing all of the terms.

      Specified by:
      withText in interface SearchQuery
      Parameters:
      fuzzy - true to perform a fuzzy search
      quantifier - whether all or some of the terms need to be matched
      text - the text to look up
      Returns:
      the query extended by this criterion
    • getTerms

      public Collection<SearchTerms<String>> getTerms()
      Description copied from interface: SearchQuery
      Returns the search terms or an empty collection if no terms were specified.
      Specified by:
      getTerms in interface SearchQuery
      Returns:
      the terms
    • getQueryString

      public String getQueryString()
      Description copied from interface: SearchQuery
      Returns the search text or null if no text was specified.
      Specified by:
      getQueryString in interface SearchQuery
      Returns:
      the text
    • isFuzzySearch

      public boolean isFuzzySearch()
      Description copied from interface: SearchQuery
      Returns true if the current search operation should be performed using fuzzy searching.
      Specified by:
      isFuzzySearch in interface SearchQuery
      Returns:
      true if fuzzy search should be used
    • withFilter

      public SearchQuery withFilter(String filter)
      Description copied from interface: SearchQuery
      Returns documents that match the search query and the text filter.
      Specified by:
      withFilter in interface SearchQuery
      Parameters:
      filter - the filter text
      Returns:
      the search query
    • getFilter

      public String getFilter()
      Description copied from interface: SearchQuery
      Returns the filter expression.
      Specified by:
      getFilter in interface SearchQuery
      Returns:
      the filter
    • withSortOrder

      public SearchQuery withSortOrder(String field, SortCriterion.Order order)
      Description copied from interface: SearchQuery
      Sort the result set by the field and the given order. The insertion-order is kept.
      Specified by:
      withSortOrder in interface SearchQuery
      Parameters:
      field - the field name, must not be null
      order - the order direction, must not be null
      Returns:
      the updated search query
    • getSortOrders

      public Map<String,SortCriterion.Order> getSortOrders()
      Description copied from interface: SearchQuery
      Returns all the known sort orders. The insertion-order is kept.
      Specified by:
      getSortOrders in interface SearchQuery
      Returns:
      a map with all known sort orders
    • getSortOrder

      public SortCriterion.Order getSortOrder(String field)
      Description copied from interface: SearchQuery
      Returns the sort order of a field. If no sort order has been set for the given field, SortCriterion.Order.None is returned.
      Specified by:
      getSortOrder in interface SearchQuery
      Parameters:
      field - the field name, must not be null
      Returns:
      the sort order
    • sortOrderFieldName

      protected abstract String sortOrderFieldName(String field)