Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SOLR query field with single or multiple values

I am new to SOLR, Currently my query returns companies with their respective postCodes, postCode is an array-type field, Some of result contains multiple values for their postCode node and some has only one single value.

RESULTS SET:

<doc>
 <str name="company">Alien Technology</str>
 <arr name="postCode">
   <str>2068</str>
   <str>2065</str>
   <str>2066</str>
   <str>2061</str>
   <str>2077</str>
 </arr>
 ....
</doc>

<doc>
 <str name="company">Cris' Sports</str>
 <arr name="postCode">
   <str>2068</str>
 </arr>
 ...
</doc>

<doc>
 <str name="company">Hyper Consultation Firm</str>
 <arr name="postCode">
   <str>2068</str>
   <str>2000</str>
   <str>2071</str>
 </arr>
 ...
</doc>

<doc>
 <str name="company">DJ Goods & Gadgets</str>
 <arr name="postCode">
   <str>2068</str>
 </arr>
 ...
</doc>

...

My question here is, Is it possible to fetch only data that has only one value for their postCode or vice versa fetch those data that contains multiple value for their postCode field and exclude others that has only one value for their postCode. Is this possible using SOLR Query?

EXAMPLE:

I searched for postCode = 2068

My first query would return only Cris Sports and DJ Goods and Gadgets because they only have one value for the postCode field.

My Second query would return only Alien Technology and Hyper Consultation Firm since both of them contains mulitple values for their postCode field.

Thanks Everyone!

like image 682
aslarona.charles Avatar asked Dec 20 '25 15:12

aslarona.charles


1 Answers

There is no direct way to get the count of items in a multivalued field or a function query to calculate the same.
You can always maintain the field count during indexing and use it during Query time.

like image 125
Jayendra Avatar answered Dec 23 '25 04:12

Jayendra



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!