You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-user@lucene.apache.org by Ellery Leung <el...@be-o.com> on 2011/10/20 11:51:48 UTC

How to return exact set of multivalue field

Hi all

 

I am using Solr 3.4 on Windows 7.

 

Here is the example of a multivalue field:

 

<doc>

<arr name="field_name">

<str>387</str>

<str>386</str>

</arr>

</doc>

 

<doc>

<arr name=" field_name ">

<str>387</str>

<str>386</str>

</arr>

</doc>

 

<doc>

<arr name=" field_name">

<str>387</str>

<str>386</str>

<str>385</str>

<str>382</str>

<str>312</str>

<str>311</str>

</arr>

</doc>

 

I am doing a search on "field_name" and JUST want to return record that IS
387 and 386 (the first and second record).

 

Here is the query:

 

field_name: (387 AND 386)

 

But this query return all 3 records, which is wrong.

 

I have tried using filter: field_name: (387 AND 386) but it still doesn't
work.

 

Therefore I would like to ask, are there any way to change this query so
that it will ONLY return first and second record?

 

Thank you in advance for any help.


RE: How to return exact set of multivalue field

Posted by Chris Hostetter <ho...@fucit.org>.
: Follow up question: what if it is a string instead of number?  While you can
: use [387 TO *] to find out all number that is bigger than 387, how do you
: find specific set of "string"?

range queries should also work on strings, but i think the more general 
solution to your problem is that you should index an additional field that 
contains the total number of values in your multivalued field, and then 
use the count as a constraint as well...

+field_name:(385 386) +field_name_count:2



-Hoss

RE: How to return exact set of multivalue field

Posted by Ellery Leung <el...@be-o.com>.
Thank you very much for your help!

Follow up question: what if it is a string instead of number?  While you can
use [387 TO *] to find out all number that is bigger than 387, how do you
find specific set of "string"?

Thank you again for any help here.

-----Original Message-----
From: dan sutton [mailto:danbsutton@gmail.com] 
Sent: 2011年10月20日 6:09 下午
To: solr-user@lucene.apache.org; elleryleung@be-o.com
Subject: Re: How to return exact set of multivalue field

-field_name:[ * TO 384] +field_name:[385 TO 386]  -field_name:[387 TO *]

On Thu, Oct 20, 2011 at 10:51 AM, Ellery Leung <el...@be-o.com> wrote:
> Hi all
>
>
>
> I am using Solr 3.4 on Windows 7.
>
>
>
> Here is the example of a multivalue field:
>
>
>
> <doc>
>
> <arr name="field_name">
>
> <str>387</str>
>
> <str>386</str>
>
> </arr>
>
> </doc>
>
>
>
> <doc>
>
> <arr name=" field_name ">
>
> <str>387</str>
>
> <str>386</str>
>
> </arr>
>
> </doc>
>
>
>
> <doc>
>
> <arr name=" field_name">
>
> <str>387</str>
>
> <str>386</str>
>
> <str>385</str>
>
> <str>382</str>
>
> <str>312</str>
>
> <str>311</str>
>
> </arr>
>
> </doc>
>
>
>
> I am doing a search on "field_name" and JUST want to return record that IS
> 387 and 386 (the first and second record).
>
>
>
> Here is the query:
>
>
>
> field_name: (387 AND 386)
>
>
>
> But this query return all 3 records, which is wrong.
>
>
>
> I have tried using filter: field_name: (387 AND 386) but it still doesn't
> work.
>
>
>
> Therefore I would like to ask, are there any way to change this query so
> that it will ONLY return first and second record?
>
>
>
> Thank you in advance for any help.
>
>


Re: How to return exact set of multivalue field

Posted by dan sutton <da...@gmail.com>.
-field_name:[ * TO 384] +field_name:[385 TO 386]  -field_name:[387 TO *]

On Thu, Oct 20, 2011 at 10:51 AM, Ellery Leung <el...@be-o.com> wrote:
> Hi all
>
>
>
> I am using Solr 3.4 on Windows 7.
>
>
>
> Here is the example of a multivalue field:
>
>
>
> <doc>
>
> <arr name="field_name">
>
> <str>387</str>
>
> <str>386</str>
>
> </arr>
>
> </doc>
>
>
>
> <doc>
>
> <arr name=" field_name ">
>
> <str>387</str>
>
> <str>386</str>
>
> </arr>
>
> </doc>
>
>
>
> <doc>
>
> <arr name=" field_name">
>
> <str>387</str>
>
> <str>386</str>
>
> <str>385</str>
>
> <str>382</str>
>
> <str>312</str>
>
> <str>311</str>
>
> </arr>
>
> </doc>
>
>
>
> I am doing a search on "field_name" and JUST want to return record that IS
> 387 and 386 (the first and second record).
>
>
>
> Here is the query:
>
>
>
> field_name: (387 AND 386)
>
>
>
> But this query return all 3 records, which is wrong.
>
>
>
> I have tried using filter: field_name: (387 AND 386) but it still doesn't
> work.
>
>
>
> Therefore I would like to ask, are there any way to change this query so
> that it will ONLY return first and second record?
>
>
>
> Thank you in advance for any help.
>
>