Search code examples
solrfacet

multiple facets in field separated by semicolon


I have a field with data like this. Here is an example row:

London;Greater London;London City

I would like to end up with the following facets

London (count 10) Greater London (count 5) London City (count 2)

Im just stuck as to the right query to use.

Can Solr have multiple facets within a single field?

Cheers

k


Solution

  • You have two options.

    The best one is to use multi-valued fields. Which means you need to split your content coming in on the semi-colons. This will depend on how you are getting data in. For example, CSV allows you to just declare the field as multi-value and splitting on semi-colon. DataImportHandler has RegexTransformer that also allows you to spit content. Or you could use Request Processor which can apply to any source, but I don't think there is a splitting one out of the box. You would need to write one.

    The other option is to realize that faceted fields use tokenized values rather than stored values. Usually, faceted fields as defined as strings exactly because of it. However, if you cannot get the first approach to work at all (and you should try hard to), you can configure a special field type that just splits the tokens on semi-colons and does no other processing. You would use PatternTokenizerFactory for that.