lucene-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Erik Hatcher <>
Subject Re: how to write my own query?
Date Fri, 04 Jun 2010 15:35:27 GMT
This is perhaps best discussed on the java-user list instead.  Here's  
some thoughts...

On Jun 4, 2010, at 2:36 AM, Li Li wrote:

> hi all,
>   I want to implement a query that taking position and terms'
> relative positions into consideration. It only supports multiterm
> queries like boolean or query.
>   But I want to consider term postion and terms relative positions.
>   e.g. there are two docs
>  doc1         apache lucene is a open source project
>  doc2         apache is a http server and lucene ...
>  if user search "apache lucene"  doc1 will win because apache lucene
> appear closer than doc2

A PhraseQuery will do that.  It's common-place to OR in a (sloppy)  
phrase query for the users query in order to get proximity to boost  
things.  No custom query needed to accomplish this.

>  e.g.
>  doc1        some other text apache lucene is a open source project
>  doc2         apache lucene is a open source project some other text
>  doc2 wins because "apache lucene" appear at the first position

And here, SpanFirstQuery is your friend.  So OR'ing a PhraseQuery and  
a SpanFirstQuery (with nested SpanNearQuery, or whatever is  
appropriate) seems to accomplish your goals.

Give those a try and report back if things still aren't quite what  
you're after.


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

View raw message