Uploaded image for project: 'Hibernate Search'
  1. HSEARCH-3207

Search 6 groundwork - Avoid duplicate clauses when .end() is called unnecessarily

    Details

    • Type: Task
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects versions: None
    • Fix versions: 6.0.0.Alpha1
    • Components: engine, query
    • Labels:
      None

      Description

      The following code apparently adds two "match" clauses because of the end() call after matching().

      SearchQuery<DocumentReference> query = searchTarget.query( sessionContext )
      				.asReferences()
      				.predicate().nested().onObjectField( "nestedObject" ).bool( b -> {
      					b.must().match().onField( "nestedObject.string" ).matching( MATCHING_STRING ).end();
      					// This is referred to as "condition 2" in the data initialization method
      					b.must().nested().onObjectField( "nestedObject.nestedObject" ).bool( b2 -> {
      						b2.must().match().onField( "nestedObject.nestedObject.field1" )
      								.matching( MATCHING_SECOND_LEVEL_CONDITION2_FIELD1 );
      						b2.must().match().onField( "nestedObject.nestedObject.field2" )
      								.matching( MATCHING_SECOND_LEVEL_CONDITION2_FIELD2 );
      					} );
      				} )
      				.build();
      

      There's of course a problem in our syntax, because intuitively one would expect the end() call to end the "match" predicate, not the "bool" predicate. That will be discussed during our face-to-face meeting.

      The following problems facts are more pressing:

      1. One can call end on the boolean predicate from the lambda that is supposedly strictly internal to that boolean predicate. But that probably can't be helped.
      2. The end() call has an effect at all? That shouldn't be the case except at the very upper level, and that level should trigger an error if two predicates are added.

        Attachments

          Activity

            People

            • Assignee:
              yrodiere Yoann Rodière
              Reporter:
              yrodiere Yoann Rodière
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: