We're updating the issue view to help you get more done. 

Move optional predicate DSL parameters to the terminal contexts

Description

For example, the current syntax looks like this:

1 2 3 4 5 .match().fuzzy().onField( "field1" ).orField( "field2" ).matching( value ) .match().withConstantScore().onField( "field1" ).orField( "field2" ).matching( value ) .match().boostedTo( 2.0f ).onField( "field1" ).boostedTo( 2.0f ).orField( "field2" ).matching( value ) // results in a boost of 4 for field1, 2 for field2, but one might think it will be 2 for each? .phrase().slop( 1 ).onField( "field1" ).orField( "field2" ).matching( phrase ) .simpleQueryString().onField( "field1" ).orField( "field2" ).withAndAsDefaultOperator().matching( queryString )

After this change, it would look like this:

1 2 3 4 5 .match().onField( "field1" ).orField( "field2" ).matching( value ).fuzzy() .match().onField( "field1" ).orField( "field2" ).matching( value ).withConstantScore() .match().onField( "field1" ).boostedTo( 2.0f ).orField( "field2" ).matching( value ).boostedTo( 2.0f ) // It hardly makes sense to override the boost at the end, so maybe there's a lesser risk for the syntax to be misunderstood? .phrase().onField( "field1" ).orField( "field2" ).matching( phrase ).slop( 1 ) .simpleQueryString().onField( "field1" ).orField( "field2" ).matching( queryString ).withAndAsDefaultOperator()

Pros:

  1. More consistent: currently, some options are specified before the field path, some after. After this change, every option comes at the end. Note it's also more consistent with the projection/sort DSL, where options always come after we specify the field path.

  2. Easier to read: the main information is specified first (type of predicate, fields, value to match), and the details come later

  3. Clearer errors: some options (for example fuzzy) are supposed to throw an exception when applied to a field that doesn't support it (an integer field, for example). With the new syntax, we would be able to throw the exception when the option is set, because we know of all the targeted fields at that point. Currently we don't, so we throw the exception later, when matching is called, which is slightly confusing.

Cons:

  1. Yet another syntax change. But we're hardly similar to Search 5 anymore, so one more syntax change is not the end of the world...

Environment

None

Status

Assignee

Yoann Rodière

Reporter

Yoann Rodière

Labels

None

Suitable for new contributors

None

Feedback Requested

None

Fix versions

Affects versions

6.0.0.Alpha2

Priority

Major