You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@lucene.apache.org by Joel Halbert <jo...@su3analytics.com> on 2011/09/13 15:26:25 UTC

Query to always prefer adjacent terms.

Hi Folks,

What is the simplest method of constructing a multi term query such that
the highest scoring document(s) is always that which contain all terms
in the query adjacent to each other?

i.e. if I search for "federal reserve" I would prefer documents that
contain "Ben Bernake is the chairman of the federal reserve" to score
higher than "the federal government is going to reserve ...".

I'd rather not do this as two separate queries.

Thanks,
Joel






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


Re: Query to always prefer adjacent terms.

Posted by Joel Halbert <jo...@su3analytics.com>.
SpanNearQuery makes sense, thanks for the link.

On Tue, 2011-09-13 at 14:40 +0100, Ian Lea wrote:
> Use a query with multiple clauses including a boosted PhraseQuery, or
> SpanNearQuery.  I think the latter is the most flexible - see
> http://www.lucidimagination.com/blog/2009/07/18/the-spanquery/ for
> good info.
> 
> http://lucene.apache.org/java/3_3_0/queryparsersyntax.html tells you
> how to use boosting if you are using the query parser.
> 
> 
> --
> Ian.
> 
> On Tue, Sep 13, 2011 at 2:26 PM, Joel Halbert <jo...@su3analytics.com> wrote:
> > Hi Folks,
> >
> > What is the simplest method of constructing a multi term query such that
> > the highest scoring document(s) is always that which contain all terms
> > in the query adjacent to each other?
> >
> > i.e. if I search for "federal reserve" I would prefer documents that
> > contain "Ben Bernake is the chairman of the federal reserve" to score
> > higher than "the federal government is going to reserve ...".
> >
> > I'd rather not do this as two separate queries.
> >
> > Thanks,
> > Joel
> >
> >
> >
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> > For additional commands, e-mail: java-user-help@lucene.apache.org
> >
> >
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-user-help@lucene.apache.org
> 



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


Re: Query to always prefer adjacent terms.

Posted by Ian Lea <ia...@gmail.com>.
Use a query with multiple clauses including a boosted PhraseQuery, or
SpanNearQuery.  I think the latter is the most flexible - see
http://www.lucidimagination.com/blog/2009/07/18/the-spanquery/ for
good info.

http://lucene.apache.org/java/3_3_0/queryparsersyntax.html tells you
how to use boosting if you are using the query parser.


--
Ian.

On Tue, Sep 13, 2011 at 2:26 PM, Joel Halbert <jo...@su3analytics.com> wrote:
> Hi Folks,
>
> What is the simplest method of constructing a multi term query such that
> the highest scoring document(s) is always that which contain all terms
> in the query adjacent to each other?
>
> i.e. if I search for "federal reserve" I would prefer documents that
> contain "Ben Bernake is the chairman of the federal reserve" to score
> higher than "the federal government is going to reserve ...".
>
> I'd rather not do this as two separate queries.
>
> Thanks,
> Joel
>
>
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-user-help@lucene.apache.org
>
>

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