Search code examples
regexsolrfacetfaceted-search

Using regex in facet.contains Solr


I have solr field stored as -

record1 --> colorDimension : "Purple|91"
record2 --> colorDimension : "Purple|974|91"
record3 --> colorDimension : "Purple|974"

I need to facet on this colorDimension Field in a way such that term contains "Purple" and number "91".

The result I am targeting is -

Purple|91 = 2

I was looking out for facet.contains but did not get any examples that uses regular expressions.


Solution

  • You should expand these while indexing, so that you have a token for Purple|91 and Purple|974 separately. Faceting is quick because it can count tokens, without having to run a regex against each one to find the actual value.

    You'll probably have to do this in your code, since I don't think you can make the pattern regex tokenizer spit out multiple tokens for a given prefix / group.