Class SearchQuery


  • @StableMinor(version="16.0",
                 sinceVersion="9.0")
    public class SearchQuery
    extends java.lang.Object
    Represents search criteria used to find matching information by a searcher.
    Since:
    8.1.0
    Version:
    $Revision: 25808 $ $Date: 2023-07-04 15:20:55 -0300 (Tue, 04 Jul 2023) $
    See Also:
    IBigDataSearcher
    • Constructor Detail

      • SearchQuery

        public SearchQuery()
        Constructs a SearchQuery object with neither user query and attributes.
        Since:
        8.1.0
      • SearchQuery

        public SearchQuery​(java.lang.String query)
        Constructs a SearchQuery object with the given user query and no attributes.
        Parameters:
        query - user query
        Since:
        8.1.0
    • Method Detail

      • getUserQuery

        public java.lang.String getUserQuery()
        Returns the user query, which is the user-defined portion of the query, usually entered by the final user using front-end interfaces.

        The searcher can and usually perform a tokenization in the user query in the same way they do in the contents during the indexing process.

        Returns:
        the user query
        Since:
        8.1.0
      • setUserQuery

        public SearchQuery setUserQuery​(java.lang.String query)
        Sets the user query.
        Parameters:
        query - the user query. If the given user query is a blank string or null, it is equivalent to not having an user query.
        Since:
        8.1.0
      • getMaxRows

        public int getMaxRows()
        Returns the maximum number of hits to be returned by the query execution.

        Usually this setting is used to paginate the search results.

        Returns:
        the maximum number of hits
        Since:
        8.1.0
      • getStartAt

        public int getStartAt()
        Returns the number of the first hit to be returned by the query execution.

        Usually this setting is used to paginate the search results.
        This number is 1-based (the first result is the result number 1).

        Returns:
        the number of the first hit
        Since:
        8.1.0
      • getControlFilter

        public ISearchQueryFilter getControlFilter()
        Returns a query filter to be applied to the search.
        Returns:
        the query filter, or null if none was specified.
        Since:
        8.1.0
        See Also:
        #getControlQuery()
      • setControlFilter

        public SearchQuery setControlFilter​(ISearchQueryFilter controlFilter)
        Sets the query filter to be applied to the search.
        Parameters:
        the - query filter.
        Since:
        8.1.0
        See Also:
        #setControlQuery(String)
      • addSort

        public SearchQuery addSort​(ISearchQuerySort sort)
        Adds a sort definition in this search.
        Parameters:
        sort - the sort definition.
        Since:
        8.1.0
      • getSorts

        public java.util.List<ISearchQuerySort> getSorts()
        Returns an unmodifiable list of added sorts.
        Returns:
        an unmodifiable list of added sorts.
        Since:
        8.1.0
      • setHighlight

        public SearchQuery setHighlight​(HighlightConfig highlight)
        Sets the highlight configuration.
        Parameters:
        highlight - the highlight configuration.
        Returns:
        this search query.
        Since:
        8.1.0
      • getHighlight

        public HighlightConfig getHighlight()
        Returns the highlight configuration.
        Returns:
        the highlight configuration.
        Since:
        8.1.0
      • addAggregation

        public SearchQuery addAggregation​(IAggregation aggregation)
        Adds the given aggregation in this search query. Returns this search query.
        Parameters:
        aggregation - the aggregation.
        Returns:
        this search query.
        Since:
        9.0.0
      • addAggregations

        public SearchQuery addAggregations​(IAggregation... aggregations)
        Adds the given aggregations in this search query. Returns this search query.
        Parameters:
        aggregations - the aggregations.
        Returns:
        this search query.
        Since:
        9.0.0
      • addAggregations

        public SearchQuery addAggregations​(java.util.List<IAggregation> aggregations)
        Adds the given aggregations in this search query. Returns this search query.
        Parameters:
        aggregations - the aggregations.
        Returns:
        this search query.
        Since:
        9.0.0
      • getAggregations

        public java.util.List<IAggregation> getAggregations()
        Returns an unmodifiable list of the added aggregations.
        Returns:
        an unmodifiable list of the added aggregations.
        Since:
        9.0.0
      • addFieldBoost

        public SearchQuery addFieldBoost​(java.lang.String fieldId,
                                         float boost)
                                  throws PortalObjectNotFoundException
        Adds a field boost to search. This configuration is only used when a user query is present in search query.
        Parameters:
        fieldId - the identifier of the field to be boosted.
        boost - the boost value.
        Returns:
        this search query.
        Throws:
        PortalObjectNotFoundException - if no field with the given identifier could be found.
        Since:
        11.1.0
      • addFieldBoost

        public SearchQuery addFieldBoost​(DocumentTypeField documentTypeField,
                                         float boost)
        Adds a field boost to search. This configuration is only used when a user query is present in search query.
        Parameters:
        documentTypeField - the field to be boosted.
        boost - the boost value.
        Returns:
        this search query.
        Throws:
        PortalObjectNotFoundException - if no field with the given identifier could be found.
        java.lang.IllegalArgumentException - if the field is not indexed.
        java.lang.IllegalArgumentException - if the boost value is not positive.
        Since:
        11.1.0
        See Also:
        DocumentTypeField.getIndexMode()
      • addDocumentTypes

        public SearchQuery addDocumentTypes​(DocumentType... documentTypes)
        Adds the given document types to the scope for this search query.

        By default a search query searches in all existing document types, but if any document type is added to the search query, it will limit its search to the added document types.

        Parameters:
        documentTypes - the document types to add.
        Returns:
        this search query for chaining operation.
        Since:
        12.5.0
      • addDocumentTypes

        public SearchQuery addDocumentTypes​(java.util.Collection<? extends DocumentType> documentTypes)
        Adds the given document types to the scope for this search query.

        By default a search query searches in all existing document types, but if any document type is added to the search query, it will limit its search to the added document types.

        Parameters:
        documentTypes - the document types to add.
        Returns:
        this search query for chaining operation.
        Since:
        12.5.0
      • addDocumentTypeIds

        public SearchQuery addDocumentTypeIds​(java.lang.String... documentTypes)
        Adds the given document types to the scope for this search query.

        By default a search query searches in all existing document types, but if any document type is added to the search query, it will limit its search to the added document types.

        Parameters:
        documentTypeIds - the identifiers of document types to add.
        Returns:
        this search query for chaining operation.
        Since:
        12.5.0
      • addDocumentTypeIds

        public SearchQuery addDocumentTypeIds​(java.util.Collection<java.lang.String> documentTypeIds)
        Adds the given document types to the scope for this search query.

        By default a search query searches in all existing document types, but if any document type is added to the search query, it will limit its search to the added document types.

        Parameters:
        documentTypeIds - the identifiers of document types to add.
        Returns:
        this search query for chaining operation.
        Since:
        12.5.0
      • getDocumentTypeIds

        public java.util.Set<java.lang.String> getDocumentTypeIds()
        Returns the identifiers of document types set as the scope for this search query.
        Returns:
        a unmodifiable set with the document type identifiers. If no document type was set as the scope for this search query then an empty set is returned.
        Since:
        12.5.0
      • getFieldsBoost

        public java.util.Map<DocumentTypeField,​java.lang.Float> getFieldsBoost()
        Returns the field boosting configuration.
        Returns:
        the field boosting configuration.
        Since:
        11.1.0