Class BooleanQuery

java.lang.Object
com.atlassian.confluence.search.v2.query.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.

  • Field Details

  • Constructor Details

    • 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
    • BooleanQuery

      public BooleanQuery(Collection<? extends SearchQuery> must, Collection<? extends SearchQuery> should, Collection<? extends SearchQuery> mustNot, Collection<? extends SearchQuery> filters, float boost, boolean disableCoord)
      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.
      disableCoord - disable similarity coord in scoring.
      Throws:
      IllegalArgumentException - if the parameters are not correct.
      Since:
      8.7
  • Method Details

    • getKey

      public String getKey()
      Specified by:
      getKey in interface SearchQuery
      Returns:
      the plugin key
    • 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.
    • andQuery

      public static SearchQuery andQuery(SearchQuery... queries)
      Build an AND query from one or more subqueries.
      Parameters:
      queries - the SearchQuerys to combine. Must be >= 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
    • getMustQueries

      public Set<SearchQuery> getMustQueries()
    • getShouldQueries

      public Set<SearchQuery> getShouldQueries()
    • getMustNotQueries

      public Set<SearchQuery> getMustNotQueries()
    • getFilters

      public Set<SearchQuery> getFilters()
    • 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
    • getSubClauses

      public Stream<SubClause<SearchQuery>> getSubClauses()
      Description copied from interface: SearchQuery
      Returns a stream of nested queries.
      Specified by:
      getSubClauses in interface SearchQuery
    • 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
    • isCoordDisabled

      public boolean isCoordDisabled()
      Returns:
      true if similarity-coord is disabled
      Since:
      8.7
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • builder

      public static BooleanQuery.Builder builder()