lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Steven A Rowe <>
Subject RE: Need help : SpanNearQuery
Date Thu, 16 Apr 2009 17:04:35 GMT
Hi Radha,

On 4/16/2009 at 8:35 AM, Radhalakshmi Sredharan wrote:
> I have a question related to SpanNearQuery.
> I need a hit even if there are 2/3 terms found with the span being
> applied for those 2 terms.
> Is there any custom implementation in place for this? I checked
> SrndQuery but that also doesn't work.
> This is my workaround currently:
> 1)      For a list of terms ( ab,bc, cd,ef) , make a set like ( ab,bc)
> , ( bc,cd) ( ab,cd) (bc,ef) ( ab,bc,cd) ( ab,bc,cd,ef)..... and so on.
> 2)      Create a spanNearQuery for  each of these terms
> 3)      Add it to the booleanQuery with a  SHOULD clause.
> However this approach gives me puzzling scores
>  eg If my document has  only ( ab,bc,cd) the penalty for the missing ef
> is very high and my score comes down quite a bit.

Do you know about the scoring documentation on the Lucene site: <>
?  In particular, see the link from there to the Searcher.explain() javadocs - this functionality
will help you understand what's happening with your queries.

I suspect that the penalty is due to fewer sub-queries matching; that is, not only does (ab,bc,cd,ef)
fail to match, but (ab,bc,ef), (ab,cd,ef), (ab,ef) etc. also fail to match, and since all
of these contribute to the final score, you will see a large drop off if you don't get a full

Instead of putting all of the alternatives together in a single large disjunction, if you
package them such that the shorter alternatives don't influence the final score when larger
ones match, you may get something more like what you want.  I think DisjunctionMaxQuery <>,
along with judicious boosting, will do the trick, e.g.:

    ((ab,bc,cd)^10 (ab,bc,ef)^10 (ab,cd,ef)^10 ...),
    ((ab,bc) (ab,cd) (ab,ef) ...))


To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message