Class BooleanQuery

  • All Implemented Interfaces:
    Expandable<SearchQuery>, SearchQuery

    @SearchPrimitive
    public class BooleanQuery
    extends Object
    implements SearchQuery

    A boolean query that allows and/or and not combinations of sub queries.

    TODO: This SearchQuery implementation does not work with the QuerySerializer (or parser) since that mechanism relies on all parameters returned by getParameters having the same meaning; this is not currently true in this implementation.

    • Constructor Detail

      • BooleanQuery

        public BooleanQuery​(Collection<? extends SearchQuery> must,
                            Collection<? extends SearchQuery> should,
                            Collection<? extends SearchQuery> mustNot)
        Construct a new BooleanQuery encapsulating the supplied sub queries with a default boost value.

        At least one of must, should or mustNot subquery must contain value. Neither of them can contain a null value.

        Parameters:
        must - the queries that must match.
        should - the queries that may match.
        mustNot - the queries that must not match.
        Throws:
        IllegalArgumentException - if the parameters are not correct.
      • BooleanQuery

        public BooleanQuery​(Collection<? extends SearchQuery> must,
                            Collection<? extends SearchQuery> should,
                            Collection<? extends SearchQuery> mustNot,
                            float boost)
        Construct a new BooleanQuery encapsulating the supplied sub queries without any filters.

        At least one of must, should or mustNot bquery must contain value. Neither of them can contain a null value.

        Parameters:
        must - the queries that must match.
        should - the queries that may match.
        mustNot - the queries that must not match.
        boost - the boost factor.
        Throws:
        IllegalArgumentException - if the parameters are not correct.
      • BooleanQuery

        public BooleanQuery​(Collection<? extends SearchQuery> must,
                            Collection<? extends SearchQuery> should,
                            Collection<? extends SearchQuery> mustNot,
                            Collection<? extends SearchQuery> filters)
        Construct a new BooleanQuery encapsulating the supplied sub queries with the default boost.
        Parameters:
        must - the queries that must match.
        should - the queries that may match.
        mustNot - the queries that must not match.
        filters - the filters that must match.
        Since:
        7.20
      • BooleanQuery

        public BooleanQuery​(Collection<? extends SearchQuery> must,
                            Collection<? extends SearchQuery> should,
                            Collection<? extends SearchQuery> mustNot,
                            Collection<? extends SearchQuery> filters,
                            float boost)
        Construct a new BooleanQuery encapsulating the supplied sub queries.

        At least one of must, should or mustNot or filter subquery must contain value. Neither of them can contain a null value.

        Parameters:
        must - the queries that must match.
        should - the queries that may match.
        mustNot - the queries that must not match.
        filters - the filters that must match.
        boost - the boost factor.
        Throws:
        IllegalArgumentException - if the parameters are not correct.
        Since:
        7.20
    • Method Detail

      • composeAndQuery

        public static SearchQuery composeAndQuery​(Set<? extends SearchQuery> subqueries)
        Return a query that "ANDs" together a list of queries. If the list contains no entries then an AllQuery is installed. If it contains only a single entry, then that entry is returned. Otherwise a BooleanQuery combining the full list is returned.
        Parameters:
        subqueries - a list of SearchQuerys to combine. Must have size >= 1.
        Returns:
        a SearchQuery combining the subqueries.
        Throws:
        IllegalArgumentException - if the list of subqueries is empty.
      • composeOrQuery

        public static SearchQuery composeOrQuery​(Set<? extends SearchQuery> subqueries)
        Return a query that "ORs" together a list of queries. If the list contains no entries then an AllQuery is installed. If it contains only a single entry, then that entry is returned. Otherwise a BooleanQuery combining the full list is returned.
        Parameters:
        subqueries - a list of SearchQuerys to combine. Must have size >= 1.
        Returns:
        a SearchQuery combining the subqueries.
        Throws:
        IllegalArgumentException - if the list of subqueries is empty.
      • orQuery

        public static SearchQuery orQuery​(SearchQuery... queries)
        Create a query that is the OR of the provided sub-queries
        Parameters:
        queries - the queries to OR
        Returns:
        the OR of the provided queries
      • expand

        public SearchQuery expand()
        Description copied from interface: SearchQuery
        Expands this query into a composite query (that composes other queries). By overriding this method, one can specify a new query that is composition of the behaviour of the composed queries.
        Specified by:
        expand in interface Expandable<SearchQuery>
        Specified by:
        expand in interface SearchQuery
        Returns:
        a query
      • getParameters

        public List getParameters()
        Description copied from interface: SearchQuery
        List of parameters as Strings or SearchQuerys.
        Specified by:
        getParameters in interface SearchQuery
        Returns:
        a List containing all the sub queries combined. I'm not sure if this is ever useful to anyone.
      • getBoost

        public float getBoost()
        Description copied from interface: SearchQuery
        Return boost factor of this query. It will take effect when the query is used in combination with others e.g. in BooleanQuery.
        Specified by:
        getBoost in interface SearchQuery
        Returns:
        boost factor
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object