lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Uwe Schindler" <...@thetaphi.de>
Subject RE: RangeQuery with multiple ranges ?
Date Fri, 05 Nov 2010 15:52:58 GMT
Why do you use such complicated stuff to build the BQ?

Term term1 = new Term(LuceneIndexField.SCALE, "10000");
Term term2 = new Term(LuceneIndexField.SCALE, "50000");
BooleanQuery bq = new BooleanQuery();
bq.add(new RangeQuery(term1, term1, true), BooleanClause.Occur.SHOULD); 
bq.add(new RangeQuery(term2, term2, true), BooleanClause.Occur.SHOULD);

By the way, your code is outdated, you should better use NumericRangeQuery for numerics! Else
RangeQuery is deprecated and replaced by TermRangeQuery:

String term1 = "10000", term2 = "50000";
BooleanQuery bq = new BooleanQuery();
bq.add(new TermRangeQuery(LuceneIndexField.SCALE, term1, term1, true, true), BooleanClause.Occur.SHOULD);

bq.add(new TermRangeQuery(LuceneIndexField.SCALE, term2, term2, true, true), BooleanClause.Occur.SHOULD);

Uwe
-----
Uwe Schindler
H.-H.-Meier-Allee 63, D-28213 Bremen
http://www.thetaphi.de
eMail: uwe@thetaphi.de


> -----Original Message-----
> From: Alain Camus [mailto:aca@ngi.be]
> Sent: Friday, November 05, 2010 4:26 PM
> To: java-user@lucene.apache.org
> Subject: RangeQuery with multiple ranges ?
> 
> Hello list,
> 
> I'm new to lucene, trying to find out if this is possible :
> 
> In Luke, I can write a query that gets me the results I want, that is :
> +denominator:([10000 TO 10000] OR [20000 TO 20000])
> 
> I'd like to write the same in java. I tried the next code but it doesn't work :
> BooleanClause.Occur scaleOccur =
> LuceneUtils.convertRequiredAndProhibitedToOccur(true, false);
> Term term1 = new Term(LuceneIndexField.SCALE, "10000");
> Term term2 = new Term(LuceneIndexField.SCALE, "50000");
> RangeQuery rangeQuery1 = new RangeQuery(term1, term1, true);
> RangeQuery rangeQuery2 = new RangeQuery(term2, term2, true);
> BooleanQuery booleanQuery = new BooleanQuery();
> booleanQuery .setMinimumNumberShouldMatch(1);
> booleanQuery .add(rangeQuery1, scaleOccur);
> booleanQuery .add(rangeQuery2, scaleOccur);
> BooleanClause scaleRangeClause = new BooleanClause(bq, scaleOccur);
> query.add(scaleRangeClause);
> The resulting query doesn't give me the expected results :
> +((+denominator:[10000 TO 10000] +denominator:[50000 TO 50000])~1)
> 
> Is it possible to do what I want ? Any documentation I could read about this ?
> 
> Alain



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


Mime
View raw message