Mailing List Archive

Automatic prefix search in query parser
Hello,

I am using Apache Lucene 8.9.0 to parse queries that are entered by humans.
I am using the
`org.apache.lucene.queryparser.classic.MultiFieldQueryParser` which works
very well so far.

However I would like to automatically use the prefix notation (`*`) for all
terms in the query, instead of searching for exact terms, so the humans
entering the queries don't have to type the `*` after each term.

An example query could be: `author:(murphy OR remender) AND batman AND
release_date:1999`, which should be transformed to `author:(murphy* OR
remender*) AND batman* AND release_date:1999*`.

Is there any way to do this with the Lucene query parsers ? I checked the
classic and standard query parser, but couldn't find any option to do so.

If there was a way to decide which fields could automatically be prefixed,
that would be even better.

Thanks a lot
Re: Automatic prefix search in query parser [ In reply to ]
A comparable alternative would be to use the edge ngram filter to index prefixes instead.

Erik


> On Sep 3, 2021, at 10:49 AM, Gauthier Roebroeck <gauthier.roebroeck@gmail.com> wrote:
>
> Hello,
>
> I am using Apache Lucene 8.9.0 to parse queries that are entered by humans.
> I am using the
> `org.apache.lucene.queryparser.classic.MultiFieldQueryParser` which works
> very well so far.
>
> However I would like to automatically use the prefix notation (`*`) for all
> terms in the query, instead of searching for exact terms, so the humans
> entering the queries don't have to type the `*` after each term.
>
> An example query could be: `author:(murphy OR remender) AND batman AND
> release_date:1999`, which should be transformed to `author:(murphy* OR
> remender*) AND batman* AND release_date:1999*`.
>
> Is there any way to do this with the Lucene query parsers ? I checked the
> classic and standard query parser, but couldn't find any option to do so.
>
> If there was a way to decide which fields could automatically be prefixed,
> that would be even better.
>
> Thanks a lot


---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org
Re: Automatic prefix search in query parser [ In reply to ]
Thank a lot Erik, I didn't thought about changing the index, only about the
query. I will explore that route.

On Fri, 3 Sep 2021, 22:53 Erik Hatcher, <erik.hatcher@gmail.com> wrote:

> A comparable alternative would be to use the edge ngram filter to index
> prefixes instead.
>
> Erik
>
>
> > On Sep 3, 2021, at 10:49 AM, Gauthier Roebroeck <
> gauthier.roebroeck@gmail.com> wrote:
> >
> > Hello,
> >
> > I am using Apache Lucene 8.9.0 to parse queries that are entered by
> humans.
> > I am using the
> > `org.apache.lucene.queryparser.classic.MultiFieldQueryParser` which works
> > very well so far.
> >
> > However I would like to automatically use the prefix notation (`*`) for
> all
> > terms in the query, instead of searching for exact terms, so the humans
> > entering the queries don't have to type the `*` after each term.
> >
> > An example query could be: `author:(murphy OR remender) AND batman AND
> > release_date:1999`, which should be transformed to `author:(murphy* OR
> > remender*) AND batman* AND release_date:1999*`.
> >
> > Is there any way to do this with the Lucene query parsers ? I checked the
> > classic and standard query parser, but couldn't find any option to do so.
> >
> > If there was a way to decide which fields could automatically be
> prefixed,
> > that would be even better.
> >
> > Thanks a lot
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-user-help@lucene.apache.org
>
>