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 hariram ravichandran <ha...@gmail.com> on 2016/11/28 11:24:53 UTC

Query expansion

I need to perform *fuzzy search* for the whole search term. I
extended MultiFieldQueryParser and overridden getFieldQuery()


protected Query getFieldQuery(String field, String fieldText,boolean
quoted) throws ParseException{
           return *super.getFuzzyQuery(field,fieldText,3.0f);
//constructing fuzzy query*
}

For example, If i give search term as "(apple AND orange) OR (mango)", the
query should be expanded as "(apple~ AND orange~) OR (mango~)".

I need to search in multiple fields and also i need to implement this
without affecting any of the lucene features. Is there any other simple way?

Re: Query expansion

Posted by hariram ravichandran <ha...@gmail.com>.
I am overriding getFieldQuery(String field, String fieldText,boolean
quoted). And in case of phrase query,

getFieldQuery(String field, String queryText, int slop) will be called.


And prefix query will not be my use case. So, we can ignore prefix query.


Assume this is my only case. Sequence of words (apple orange mango) as
input, and i need result for (apple~ orange~  mango~).

And I use default conjunction operator as AND (parser.setDefaultOperator(
QueryParser.Operator.AND)) for providing better relevance in results.



That method works as I expected. Is there any drawbacks of using this?


And is there any better method to expand query like this?







On Wed, Nov 30, 2016 at 4:37 AM, Michael McCandless <
lucene@mikemccandless.com> wrote:

> This is likely tricky to do correctly.
>
> E.g., MultiFieldQueryParser.getFieldQuery is invoked on whole chunks
> of text.  If you search for:
>
>   apple orange
>
> I suspect it won't do what you want, since the whole string "apple
> orange" is passed to getFieldQuery.
>
> How do you want to handle e.g. a phrase query (user types "apple
> orange", with the double quotes)?  Or a prefix query (app*)?
>
> Maybe you could instead override newTermQuery?  In the example above
> it would be invoked twice, once for apple and once for orange.
>
> Finally, all this being said, making everything fuzzy is likely a big
> performance hit and often poor results (massive recall, poor
> precision) to the user!
>
> Mike McCandless
>
> http://blog.mikemccandless.com
>
>
> On Mon, Nov 28, 2016 at 6:24 AM, hariram ravichandran
> <ha...@gmail.com> wrote:
> > I need to perform *fuzzy search* for the whole search term. I
> > extended MultiFieldQueryParser and overridden getFieldQuery()
> >
> >
> > protected Query getFieldQuery(String field, String fieldText,boolean
> > quoted) throws ParseException{
> >            return *super.getFuzzyQuery(field,fieldText,3.0f);
> > //constructing fuzzy query*
> > }
> >
> > For example, If i give search term as "(apple AND orange) OR (mango)",
> the
> > query should be expanded as "(apple~ AND orange~) OR (mango~)".
> >
> > I need to search in multiple fields and also i need to implement this
> > without affecting any of the lucene features. Is there any other simple
> way?
>

Re: Query expansion

Posted by Michael McCandless <lu...@mikemccandless.com>.
This is likely tricky to do correctly.

E.g., MultiFieldQueryParser.getFieldQuery is invoked on whole chunks
of text.  If you search for:

  apple orange

I suspect it won't do what you want, since the whole string "apple
orange" is passed to getFieldQuery.

How do you want to handle e.g. a phrase query (user types "apple
orange", with the double quotes)?  Or a prefix query (app*)?

Maybe you could instead override newTermQuery?  In the example above
it would be invoked twice, once for apple and once for orange.

Finally, all this being said, making everything fuzzy is likely a big
performance hit and often poor results (massive recall, poor
precision) to the user!

Mike McCandless

http://blog.mikemccandless.com


On Mon, Nov 28, 2016 at 6:24 AM, hariram ravichandran
<ha...@gmail.com> wrote:
> I need to perform *fuzzy search* for the whole search term. I
> extended MultiFieldQueryParser and overridden getFieldQuery()
>
>
> protected Query getFieldQuery(String field, String fieldText,boolean
> quoted) throws ParseException{
>            return *super.getFuzzyQuery(field,fieldText,3.0f);
> //constructing fuzzy query*
> }
>
> For example, If i give search term as "(apple AND orange) OR (mango)", the
> query should be expanded as "(apple~ AND orange~) OR (mango~)".
>
> I need to search in multiple fields and also i need to implement this
> without affecting any of the lucene features. Is there any other simple way?

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