20

Can I, within a Solr function query, count the number of values in a multivalued field? How would I write a function query that returns documents with, say, 3 or more values for a particular field?

Dave
  • 1,204
  • 2
  • 14
  • 25

1 Answers1

17

Here's the function query reference, and it doesn't list anything like that, so I think it's safe to assume that there's no such thing.

If the value count is somehow relevant in your case, add it as a separate int field, then operate on that field.

Mauricio Scheffer
  • 98,863
  • 23
  • 192
  • 275
  • Thanks. It was, as you guessed, pretty easy to just store the count in a separate field and operate on that. – Dave Jun 05 '11 at 20:16
  • 3
    @Dave did you store the count manually, or is there a way for the count field to refer to the multivalued field so that as soon as the multivalued field changes, the count updates itself ? – gaurav5430 Jun 27 '16 at 06:14
  • Take a look at [CountFieldValuesUpdateProcessorFactory](http://lucene.apache.org/solr/4_0_0/solr-core/org/apache/solr/update/processor/CountFieldValuesUpdateProcessorFactory.html) as mentioned here in another SO question [solr-count-multi-valued-fields-query](https://stackoverflow.com/questions/38769405/solr-count-multi-valued-fields-query) – genonymous Mar 07 '18 at 00:46