Mailing List Archive

How to create a query to search for 2 words separated by 0-3 gaps?
Does someone know how to create a query for searching 2 words separated by
0, 1, 2 or 3 gaps?

Thanks
Re: How to create a query to search for 2 words separated by 0-3 gaps? [ In reply to ]
Hi Jean,
One thing I could come up with is to use IntervalQuery.

Specifically you could create an IntervalQuery with IntervalSource of:

Intervals.within(Intervals.term(word2), 3, Intervals.term(word1)))

to search for word2 that appears within 3 positions of word1

Best
Patrick

Jean Morissette <jean.morissette@gmail.com> ?2021?3?31??? ??9:00???

> Does someone know how to create a query for searching 2 words separated by
> 0, 1, 2 or 3 gaps?
>
> Thanks
>
Re: How to create a query to search for 2 words separated by 0-3 gaps? [ In reply to ]
Hi Jean,

If you do not care about the order of the words, then use a phrase query
with a slop of 3.

Otherwise, you could use a span query to achieve that.

Regards
Ameer

On Thu, 1 Apr 2021 at 15:00, Jean Morissette <jean.morissette@gmail.com>
wrote:

> Does someone know how to create a query for searching 2 words separated by
> 0, 1, 2 or 3 gaps?
>
> Thanks
>
Re: How to create a query to search for 2 words separated by 0-3 gaps? [ In reply to ]
Thank you for your response. It was exactly what I was looking for.

On Thu, 1 Apr 2021 at 14:40, Haoyu Zhai <zhai7631@gmail.com> wrote:

> Hi Jean,
> One thing I could come up with is to use IntervalQuery.
>
> Specifically you could create an IntervalQuery with IntervalSource of:
>
> Intervals.within(Intervals.term(word2), 3, Intervals.term(word1)))
>
> to search for word2 that appears within 3 positions of word1
>
> Best
> Patrick
>
> Jean Morissette <jean.morissette@gmail.com> ?2021?3?31??? ??9:00???
>
> > Does someone know how to create a query for searching 2 words separated
> by
> > 0, 1, 2 or 3 gaps?
> >
> > Thanks
> >
>