Class SearchQuery

    • Constructor Detail

      • SearchQuery

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

      • getUserQuery

        public 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​(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 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​(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 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​(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
      • 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​(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​(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​(Collection<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 Set<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 Map<DocumentTypeField,​Float> getFieldsBoost()
        Returns the field boosting configuration.
        Returns:
        the field boosting configuration.
        Since:
        11.1.0