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 Tom Mortimer <to...@flax.co.uk> on 2018/06/08 14:46:42 UTC

Matching a single instance of a multivalued field

Hi!

I have a requirement to be able to restrict search results to a single
instance of a multivalued field. e.g. with the doc:

    text: [ "striped skunk", "spotted hyena" ]

the queries (skunk AND striped), (spotted AND hyena) should return the
document, but (striped AND hyena), (skunk AND spotted) should not.

Can anyone give me any suggestions how to do this? I was thinking that
setting a massive position increment gap between multiple values and then
using a SpanNearQuery with a large (but smaller than the gap) slop might do
the job, but the field values could be quite long (I don't know if there's
a limit). Is there a neater way?

cheers,
Tom

Re: Matching a single instance of a multivalued field

Posted by Tom Mortimer <to...@flax.co.uk>.
Ah, that's an interesting idea - thanks Adrien!

On Fri, Jun 8, 2018 at 3:54 PM Adrien Grand <jp...@gmail.com> wrote:

> Hi Tom,
>
> One way to solve this could be to use block joins by indexing each value in
> its own document and joining the parent document using
> ToParentBlockJoinQuery.
>
> Le ven. 8 juin 2018 à 16:46, Tom Mortimer <to...@flax.co.uk> a écrit :
>
> > Hi!
> >
> > I have a requirement to be able to restrict search results to a single
> > instance of a multivalued field. e.g. with the doc:
> >
> >     text: [ "striped skunk", "spotted hyena" ]
> >
> > the queries (skunk AND striped), (spotted AND hyena) should return the
> > document, but (striped AND hyena), (skunk AND spotted) should not.
> >
> > Can anyone give me any suggestions how to do this? I was thinking that
> > setting a massive position increment gap between multiple values and then
> > using a SpanNearQuery with a large (but smaller than the gap) slop might
> do
> > the job, but the field values could be quite long (I don't know if
> there's
> > a limit). Is there a neater way?
> >
> > cheers,
> > Tom
> >
>

Re: Matching a single instance of a multivalued field

Posted by Adrien Grand <jp...@gmail.com>.
Hi Tom,

One way to solve this could be to use block joins by indexing each value in
its own document and joining the parent document using
ToParentBlockJoinQuery.

Le ven. 8 juin 2018 à 16:46, Tom Mortimer <to...@flax.co.uk> a écrit :

> Hi!
>
> I have a requirement to be able to restrict search results to a single
> instance of a multivalued field. e.g. with the doc:
>
>     text: [ "striped skunk", "spotted hyena" ]
>
> the queries (skunk AND striped), (spotted AND hyena) should return the
> document, but (striped AND hyena), (skunk AND spotted) should not.
>
> Can anyone give me any suggestions how to do this? I was thinking that
> setting a massive position increment gap between multiple values and then
> using a SpanNearQuery with a large (but smaller than the gap) slop might do
> the job, but the field values could be quite long (I don't know if there's
> a limit). Is there a neater way?
>
> cheers,
> Tom
>