Mailing List Archive

Update TermInSetQuery Example?
Hi

I recently found TermInSetQuery example at

https://lucene.apache.org/core/9_7_0/core/org/apache/lucene/search/TermInSetQuery.html

but if I understand correctly one should use now BooleanQuery.Builder
instead BooleanQuery itself, right?

BooleanQuery.Builder bqb = new BooleanQuery.Builder();
bqb.add(new TermQuery(new Term("field", "foo")),
BooleanClause.Occcur.SHOULD);
bqb.add(new TermQuery(new Term("field", "bar")),
BooleanClause.Occcur.SHOULD);
Query q2 = new ConstantScoreQuery(bqb.build());

If so, I would be happy to do a minor pull request or feel free to
update it directly.

Thanks

Michael

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@lucene.apache.org
For additional commands, e-mail: dev-help@lucene.apache.org
Re: Update TermInSetQuery Example? [ In reply to ]
Hi Michael,

Go ahead. Maybe scan through the remaining source files with a grep/regex:

$ fgrep -R 'new BooleanQuery(' *
lucene/core/src/java/org/apache/lucene/search/BooleanQuery.java: return
new BooleanQuery(minimumNumberShouldMatch, clauses.toArray(new
BooleanClause[0]));
lucene/core/src/java/org/apache/lucene/search/TermInSetQuery.java: *
BooleanQuery bq = new BooleanQuery();
lucene/queries/src/java/org/apache/lucene/queries/spans/package-info.java:
* Query query = new BooleanQuery();
lucene/spatial-extras/src/java/org/apache/lucene/spatial/bbox/BBoxStrategy.java:
// BooleanQuery qNotDisjoint = new BooleanQuery();

The first one is a false positive (the builder calls the BQ ctor, but
all others should possibly be fixed. There may be other combinations not
detected because of source code formatting.

Uwe

Am 20.10.2023 um 23:46 schrieb Michael Wechner:
> Hi
>
> I recently found TermInSetQuery example at
>
> https://lucene.apache.org/core/9_7_0/core/org/apache/lucene/search/TermInSetQuery.html
>
>
> but if I understand correctly one should use now BooleanQuery.Builder
> instead BooleanQuery itself, right?
>
> BooleanQuery.Builder bqb = new BooleanQuery.Builder();
> bqb.add(new TermQuery(new Term("field", "foo")),
> BooleanClause.Occcur.SHOULD);
> bqb.add(new TermQuery(new Term("field", "bar")),
> BooleanClause.Occcur.SHOULD);
> Query q2 = new ConstantScoreQuery(bqb.build());
>
> If so, I would be happy to do a minor pull request or feel free to
> update it directly.
>
> Thanks
>
> Michael
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@lucene.apache.org
> For additional commands, e-mail: dev-help@lucene.apache.org
>
--
Uwe Schindler
Achterdiek 19, D-28357 Bremen
https://www.thetaphi.de
eMail: uwe@thetaphi.de


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@lucene.apache.org
For additional commands, e-mail: dev-help@lucene.apache.org
Re: Update TermInSetQuery Example? [ In reply to ]
Hi Uwe

Thanks for the hints re the other source code samples, will do this and
will create a PR.

Thanks

Michael

Am 21.10.23 um 09:52 schrieb Uwe Schindler:
> Hi Michael,
>
> Go ahead. Maybe scan through the remaining source files with a
> grep/regex:
>
> $ fgrep -R 'new BooleanQuery(' *
> lucene/core/src/java/org/apache/lucene/search/BooleanQuery.java:
> return new BooleanQuery(minimumNumberShouldMatch, clauses.toArray(new
> BooleanClause[0]));
> lucene/core/src/java/org/apache/lucene/search/TermInSetQuery.java: *
> BooleanQuery bq = new BooleanQuery();
> lucene/queries/src/java/org/apache/lucene/queries/spans/package-info.java:
> * Query query = new BooleanQuery();
> lucene/spatial-extras/src/java/org/apache/lucene/spatial/bbox/BBoxStrategy.java:
> // BooleanQuery qNotDisjoint = new BooleanQuery();
>
> The first one is a false positive (the builder calls the BQ ctor, but
> all others should possibly be fixed. There may be other combinations
> not detected because of source code formatting.
>
> Uwe
>
> Am 20.10.2023 um 23:46 schrieb Michael Wechner:
>> Hi
>>
>> I recently found TermInSetQuery example at
>>
>> https://lucene.apache.org/core/9_7_0/core/org/apache/lucene/search/TermInSetQuery.html
>>
>>
>> but if I understand correctly one should use now BooleanQuery.Builder
>> instead BooleanQuery itself, right?
>>
>> BooleanQuery.Builder bqb = new BooleanQuery.Builder();
>> bqb.add(new TermQuery(new Term("field", "foo")),
>> BooleanClause.Occcur.SHOULD);
>> bqb.add(new TermQuery(new Term("field", "bar")),
>> BooleanClause.Occcur.SHOULD);
>> Query q2 = new ConstantScoreQuery(bqb.build());
>>
>> If so, I would be happy to do a minor pull request or feel free to
>> update it directly.
>>
>> Thanks
>>
>> Michael
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: dev-unsubscribe@lucene.apache.org
>> For additional commands, e-mail: dev-help@lucene.apache.org
>>


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@lucene.apache.org
For additional commands, e-mail: dev-help@lucene.apache.org