[ 
https://issues.apache.org/jira/browse/LUCENE-6570?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14592706#comment-14592706
 ] 

Adrien Grand commented on LUCENE-6570:
--------------------------------------

Agreed that MIGRATE.txt needs more information about the API changes to 
PhraseQuery and BooleanQuery, I'll work on it.

Are you suggesting that this new builder should be backported to 5.x and that 
the setters on BooleanQuery should be marked as deprecated? I did not consider 
this option because it would make BooleanQuery have the API of an immutable 
query while nothing would guarantee that it cannot be modified since we would 
need to keep the old deprecated setters. So I just made it a breaking change 
for 6.0.

I am willing to document the fact that we clone sub queries, but I am on the 
fence about removing it, since without defensively cloning, the BooleanQuery 
would still be mutable while this issue is about making sure it cannot change. 
For instance, consider the following sequence of operations:

{code}
TermQuery tq1 = new TermQuery(new Term("field", "value"));
BooleanQuery bq1 = new BooleanQuery.Builder()
    .add(tq1, Occur.MUST)
    .build();

TermQuery tq2 = new TermQuery(new Term("field", "value"));
BooleanQuery bq2 = new BooleanQuery.Builder()
    .add(tq2, Occur.MUST)
    .build();

assertEquals(bq1, bq2); // passes
tq1.setBoost(2f);
assertEquals(bq1, bq2); // fails if we did not clone because the boost of the 
sub query changed
{code}

One motivation behind this change is to be able to enable the query cache by 
default in IndexSearcher (currently off), which we can only do if queries can 
reliably be used as cache keys.

The cloning of the sub queries is also important for LUCENE-6305. It fixes 
BooleanQuery to ignore clause order by putting queries into a multiset, but if 
boosts of sub queries can change after the boolean query has been built then 
again the fix would not be applicable.

> Make BooleanQuery immutable
> ---------------------------
>
>                 Key: LUCENE-6570
>                 URL: https://issues.apache.org/jira/browse/LUCENE-6570
>             Project: Lucene - Core
>          Issue Type: Task
>            Reporter: Adrien Grand
>            Assignee: Adrien Grand
>            Priority: Minor
>             Fix For: 6.0
>
>         Attachments: LUCENE-6570.patch
>
>
> In the same spirit as LUCENE-6531 for the PhraseQuery, we should make 
> BooleanQuery immutable.
> The plan is the following:
>  - create BooleanQuery.Builder with the same setters as BooleanQuery today 
> (except setBoost) and a build() method that returns a BooleanQuery
>  - remove setters from BooleanQuery (except setBoost)
> I would also like to add some static utility methods for common use-cases of 
> this query, for instance:
>  - static BooleanQuery disjunction(Query... queries) to create a disjunction
>  - static BooleanQuery conjunction(Query... queries) to create a conjunction
>  - static BooleanQuery filtered(Query query, Query... filters) to create a 
> filtered query
> Hopefully this will help keep tests not too verbose, and the latter will also 
> help with the FilteredQuery derecation/removal.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to