Uploaded image for project: 'Couchbase Java Client'
  1. Couchbase Java Client
  2. JCBC-2100

FTS BooleanQuery fails unless all 3 of "must", "should", and "mustNot" are specified

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • Major
    • 3.5.0
    • 3.4.5, 3.4.6, 3.4.7, 3.4.8, 3.4.9, 3.4.10, 3.4.11
    • FullText
    • None
    • RHLE 7 / JDK 11 Corretto
    • 1
    • SDK40

    Description

      Suggested release note:

      Fixed a regression introduced in version 3.4.5 that caused a Full-Text Search `BooleanQuery` to throw `InvalidArgumentException: Compound query has no child query` unless all 3 of "must", "should", and "mustNot" were specified.

       

      Method com.couchbase.client.java.search.SearchQuery#booleans throws an InvalidArgumentException

      com.couchbase.client.core.error.InvalidArgumentException: Compound query has no child query
              at com.couchbase.client.core.error.InvalidArgumentException.fromMessage(InvalidArgumentException.java:28)
              at com.couchbase.client.core.api.search.queries.CoreDisjunctionQuery.<init>(CoreDisjunctionQuery.java:41)
              at com.couchbase.client.java.search.queries.DisjunctionQuery.toCore(DisjunctionQuery.java:57)
              at com.couchbase.client.java.search.queries.BooleanQuery.toCore(BooleanQuery.java:71)
              at com.couchbase.client.java.AsyncCluster.searchQuery(AsyncCluster.java:423)
              at com.couchbase.client.java.Cluster.searchQuery(Cluster.java:457) 

      This issue is caused by the following code block on lines 35-40 in com.couchbase.client.java.search.queries.BooleanQuery

      public BooleanQuery() {
          super();
          this.must = new ConjunctionQuery();
          this.should = new DisjunctionQuery();
          this.mustNot = new DisjunctionQuery();
      } 

      New ConjunctionQuery / DisjunctionQuery classes are instantiated in the above BooleanQuery constructor without a SearchQuery parameter.

      This ultimately results in a call to the com.couchbase.client.core.api.search.queries.CoreDisjunctionQuery#CoreDisjunctionQuery constructor in core-io - which is imported transitively at version 2.4.10 - with an empty 'List<CoreSearchQuery> queries' parameter.
       
      Version 2.4.10 of CoreDisjunctionQuery has a guard at line 40 which throws an 
      InvalidArgumentException when the List<CoreSearchQuery> parameter is empty, as per below code:

      public CoreDisjunctionQuery(List<CoreSearchQuery> queries, @Nullable Integer min, @Nullable Double boost) {
        super(queries, boost);
        this.min = min;
       
        if (childQueries.isEmpty()) {
          throw InvalidArgumentException.fromMessage("Compound query has no child query");
        }
        if (min != null && childQueries.size() < min) {
          throw InvalidArgumentException.fromMessage("Disjunction query has fewer children than the configured minimum " + min);
        }
      } 

      Attachments

        Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

              david.nault David Nault
              fvalton Fred Valton
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes

                  PagerDuty