Reputation: 33
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!
Upvotes: 3
Views: 2476
Reputation: 1183
when you sort by score (desc), the field with only one value will have higher score so will be listed before the others. Not sure if there is a way to limit result set to only have documents with score matching max-score. May be that can be done in client?
Upvotes: 0
Reputation: 52809
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.
Upvotes: 1