lucene-general mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Uwe Schindler" <>
Subject RE: Controlling size of matched results in Lucene
Date Wed, 13 May 2015 07:04:47 GMT
There is one possibility to get *all* documents, if you are happy with the fact that non-matching
documents get a score factor of 0.0:

Scores of SHOULD clauses in a Boolean query get "added". You can combine your original query
("yourOriginalQuery"; with real scores) with another query ("fakeQuery") matching all documents
and having score = 0.0 in a single final BooleanQuery ("finalQuery"=, you get score 0.0 for
non-matching documents, and score 0.0 + realScore => realScore for all others:

BooleanQuery finalQuery = new BooleanQuery(true); // BooleanQuery without coord factors, so
it just adds scores nothing else
finalQuery.add(yourOriginalQuery, BooleanClause.Occur.SHOULD);

Query fakeQuery = new MatchAllDocsQuery();
fakeQuery.setBoost(0); // tune the boost, so this query always returns a score of 0
finalQuery.add(fakeQuery, BooleanClause.Occur.SHOULD);

// execute finalQuery!

Hope that helps!


Uwe Schindler
H.-H.-Meier-Allee 63, D-28213 Bremen

> -----Original Message-----
> From: Susrutha Gongalla []
> Sent: Tuesday, May 12, 2015 12:28 PM
> To:
> Subject: Controlling size of matched results in Lucene
> Hello,
> I am developing a matching algorithm using Lucene 4.10.0 My index consists
> of about 2000 documents.
> When I use the 'search' method on a query term, I get about n results that
> point to the n documents in index along with their corresponding scores.
> What I would like to get is - All the 2000 documents with their lucene scores
> along with whether they are matched/unmatched.
> I would like to control the size of results that lucene returns when I search for
> a query term.
> I have tried altering the default similarity used in lucene by overriding the
> score methods.
> However, this did not affect the size of results generated by lucene.
> I also tried explicitly given 'null' value for filter, when calling the 'search'
> method.
> This also did not affect the size of results.
> I just started working with Lucene.
> Would appreciate any help in this regard!
> Best,
> Susrutha Gongalla

View raw message