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 Leo BRUVRY-LAGADEC <Le...@partenaire-exterieur.ifremer.fr> on 2016/12/15 11:12:24 UTC

Search only for single value of Solr multivalue field

Hi,

I have a multivalued field in my schema called "idx_affilliation".

<field name="idx_affilliation">IFREMER, Ctr Brest, DRO Geosci Marines, 
F-29280 Plouzane, France.</field>
<field name="idx_affilliation">Univ Lisbon, Ctr Geofis, P-1269102 
Lisbon, Portugal.</field>
<field name="idx_affilliation">Univ Bretagne Occidentale, Inst Univ 
Europeen Mer, Lab Domaines Ocean, F-29280 Plouzane, France.</field>
<field name="idx_affilliation">Total Explorat Prod Geosci Projets 
Nouveaux Exper, F-92078 Paris, France.</field>

I want to be able to do a query like: idx_affilliation:(IFREMER 
Portugal) and not have this document returned. In other words, I do not 
want queries to span individual values for the field.

-----------------------------------------------------------------------------------------------

Here are some further examples using the document above of how I want 
this to work:

idx_affilliation:(IFREMER France) --> Returns it.
idx_affilliation:(IFREMER Plouzane) --> Returns it.
idx_affilliation:("Univ Bretagne Occidentale") --> Returns it.
idx_affilliation:("Univ Lisbon" Portugal) --> Returns it.
idx_affilliation:(IFREMER Portugal) --> DOES NOT RETURN IT.

Does someone known if it's possible to do this ?

Best regards,
Leo.

Re: Search only for single value of Solr multivalue field

Posted by Leo BRUVRY-LAGADEC <Le...@partenaire-exterieur.ifremer.fr>.
Hi Dorian,

Firstly thanks for your response, but it does not seems to work.

Here is another example, I want to search document with affiliations 
contains the NHM (Natural History Museum) of India. So, I want to only 
get the document with id=2 :

<doc>
     <field name"id">1</field>
     <field name="affilliation">NHM, Austria</field>
     <field name="affilliation">Annamalai Univ, India</field>

</doc>
<doc>
     <field name"id">2</field>
     <field name="affilliation">NHM, India</field>
     <field name="affilliation">IRD, FRANCE</field>
</doc>

If I implement your solution, ((NMH in affilliation OR India in 
affilliation) AND NOT (NMH in affilliation AND India in affilliation) it 
doesn't return any document. did I have missed something in you 
explanation ?

In the prvious version of my application I used and had a solution with 
Oracle Full Text, it seem weird that SOLR cannot provide a solution for 
that.

Best regards,
L�o.

Le 15/12/2016 12:44, Dorian Hoxha a �crit :
> You should be able to filter "(word1 in field OR word2 in field) AND
> NOT(word1 in field AND word2 in field)". Translate that into the right
> syntax.
> I don't know if lucene is smart enough to execute the filter only once (it
> should be i guess).
> Makes sense ?
>
> On Thu, Dec 15, 2016 at 12:12 PM, Leo BRUVRY-LAGADEC <Leo.Bruvry.Lagadec@
> partenaire-exterieur.ifremer.fr> wrote:
>
>> Hi,
>>
>> I have a multivalued field in my schema called "idx_affilliation".
>>
>> <field name="idx_affilliation">IFREMER, Ctr Brest, DRO Geosci Marines,
>> F-29280 Plouzane, France.</field>
>> <field name="idx_affilliation">Univ Lisbon, Ctr Geofis, P-1269102 Lisbon,
>> Portugal.</field>
>> <field name="idx_affilliation">Univ Bretagne Occidentale, Inst Univ
>> Europeen Mer, Lab Domaines Ocean, F-29280 Plouzane, France.</field>
>> <field name="idx_affilliation">Total Explorat Prod Geosci Projets Nouveaux
>> Exper, F-92078 Paris, France.</field>
>>
>> I want to be able to do a query like: idx_affilliation:(IFREMER Portugal)
>> and not have this document returned. In other words, I do not want queries
>> to span individual values for the field.
>>
>> ------------------------------------------------------------
>> -----------------------------------
>>
>> Here are some further examples using the document above of how I want this
>> to work:
>>
>> idx_affilliation:(IFREMER France) --> Returns it.
>> idx_affilliation:(IFREMER Plouzane) --> Returns it.
>> idx_affilliation:("Univ Bretagne Occidentale") --> Returns it.
>> idx_affilliation:("Univ Lisbon" Portugal) --> Returns it.
>> idx_affilliation:(IFREMER Portugal) --> DOES NOT RETURN IT.
>>
>> Does someone known if it's possible to do this ?
>>
>> Best regards,
>> Leo.
>>
>

Re: Search only for single value of Solr multivalue field

Posted by Erick Erickson <er...@gmail.com>.
Phrase queries and slop and positionIncrementGap ;)

The fieldType has a positionIncrementGap. This is the token delta
between the end token of one entry and the beginning of the next.

so the first entry: IFREMER, Ctr Brest, DRO Geosci Marines, F-29280
Plouzane, France
IFREMER would have a position of 1 and France would have a position of 9 or so.
If the positionIncrementGap was 100 then this entry:
Univ Lisbon, Ctr Geofis, P-1269102 Lisbon, Portugal.
Univ would have a position of 110.

Now if I seach "IFREMER France"~99 it'd match the first one
but searching "IFREMER Lisbon"~99 it would not match since the
positions are > 99 apart.

So you configure the positionIncrementGap to be greater than the
longest number of tokens you ever expect to have in a single entry.

HTH
Erick

On Thu, Dec 15, 2016 at 3:44 AM, Dorian Hoxha <do...@gmail.com> wrote:
> You should be able to filter "(word1 in field OR word2 in field) AND
> NOT(word1 in field AND word2 in field)". Translate that into the right
> syntax.
> I don't know if lucene is smart enough to execute the filter only once (it
> should be i guess).
> Makes sense ?
>
> On Thu, Dec 15, 2016 at 12:12 PM, Leo BRUVRY-LAGADEC <Leo.Bruvry.Lagadec@
> partenaire-exterieur.ifremer.fr> wrote:
>
>> Hi,
>>
>> I have a multivalued field in my schema called "idx_affilliation".
>>
>> <field name="idx_affilliation">IFREMER, Ctr Brest, DRO Geosci Marines,
>> F-29280 Plouzane, France.</field>
>> <field name="idx_affilliation">Univ Lisbon, Ctr Geofis, P-1269102 Lisbon,
>> Portugal.</field>
>> <field name="idx_affilliation">Univ Bretagne Occidentale, Inst Univ
>> Europeen Mer, Lab Domaines Ocean, F-29280 Plouzane, France.</field>
>> <field name="idx_affilliation">Total Explorat Prod Geosci Projets Nouveaux
>> Exper, F-92078 Paris, France.</field>
>>
>> I want to be able to do a query like: idx_affilliation:(IFREMER Portugal)
>> and not have this document returned. In other words, I do not want queries
>> to span individual values for the field.
>>
>> ------------------------------------------------------------
>> -----------------------------------
>>
>> Here are some further examples using the document above of how I want this
>> to work:
>>
>> idx_affilliation:(IFREMER France) --> Returns it.
>> idx_affilliation:(IFREMER Plouzane) --> Returns it.
>> idx_affilliation:("Univ Bretagne Occidentale") --> Returns it.
>> idx_affilliation:("Univ Lisbon" Portugal) --> Returns it.
>> idx_affilliation:(IFREMER Portugal) --> DOES NOT RETURN IT.
>>
>> Does someone known if it's possible to do this ?
>>
>> Best regards,
>> Leo.
>>

Re: Search only for single value of Solr multivalue field

Posted by Dorian Hoxha <do...@gmail.com>.
You should be able to filter "(word1 in field OR word2 in field) AND
NOT(word1 in field AND word2 in field)". Translate that into the right
syntax.
I don't know if lucene is smart enough to execute the filter only once (it
should be i guess).
Makes sense ?

On Thu, Dec 15, 2016 at 12:12 PM, Leo BRUVRY-LAGADEC <Leo.Bruvry.Lagadec@
partenaire-exterieur.ifremer.fr> wrote:

> Hi,
>
> I have a multivalued field in my schema called "idx_affilliation".
>
> <field name="idx_affilliation">IFREMER, Ctr Brest, DRO Geosci Marines,
> F-29280 Plouzane, France.</field>
> <field name="idx_affilliation">Univ Lisbon, Ctr Geofis, P-1269102 Lisbon,
> Portugal.</field>
> <field name="idx_affilliation">Univ Bretagne Occidentale, Inst Univ
> Europeen Mer, Lab Domaines Ocean, F-29280 Plouzane, France.</field>
> <field name="idx_affilliation">Total Explorat Prod Geosci Projets Nouveaux
> Exper, F-92078 Paris, France.</field>
>
> I want to be able to do a query like: idx_affilliation:(IFREMER Portugal)
> and not have this document returned. In other words, I do not want queries
> to span individual values for the field.
>
> ------------------------------------------------------------
> -----------------------------------
>
> Here are some further examples using the document above of how I want this
> to work:
>
> idx_affilliation:(IFREMER France) --> Returns it.
> idx_affilliation:(IFREMER Plouzane) --> Returns it.
> idx_affilliation:("Univ Bretagne Occidentale") --> Returns it.
> idx_affilliation:("Univ Lisbon" Portugal) --> Returns it.
> idx_affilliation:(IFREMER Portugal) --> DOES NOT RETURN IT.
>
> Does someone known if it's possible to do this ?
>
> Best regards,
> Leo.
>