Search code examples
solrlucenesolrjfacet

Solr filter on facets


Each of my documents can have one or more entries of a field called Classes, describing some properties of the document, always of the form:

<field name="Classes">"<Description> - <TypeLabel> - <OriginLabel>"</field>

So for instance a document about food might have the two fields:

<field name="Classes">"Yellow orange - Fruit - California"</field>
<field name="Classes">"Small broccoli - Vegetable - Florida"</field>

I am using Solr 5.0 and a schema.xml file, where I have a multiValued "text_en" field Classes that I copy to a "string" field Classes_asString so that I can do faceting on the whole field and treat is as a big label.

With facet.field on Classes_asString I am getting the facet counts that I want, but now I would like to additionally filter these results.

For example, how do I only get facet results that end with "California"?

Or, in another example, how do I only get facet results that have "Vegetable" between the two "-"?

I have seen the option facet.prefix, but this is not applicable in my case. I would appreciate any help or suggestions.


Solution

  • Maybe this scenario is a good place to use:

    • Index the Classes info as Child documents. You have at least 3 fields in those fields, so it's worth using their own doc for that?
    • Then you should be able to facet on the specific child field, either with a current Solr version if it is supported (not sure), or with work in this ticket that is not merged yet