Tarun Balotia
Tarun Balotia

Reputation: 21

dynamic fields as facet in solr

I am trying to develop a filter system using dynamic fields in solr. These dynamic fields may vary from product to product and have a prefix attribute_filter_ to help me recognize the filter field. So given a search query, I want to get faceted results based on these dynamic fields.

For example, I have 3 products as docs in solr

{ID:1, attribute_filter_color:"white", attribute_filter_brand:"Dell"}
{ID:2, attribute_filter_color:"red", attribute_filter_category:"electronics"}
{ID:3, attribute_filter_size:"mobiles", attribute_filter_brand:"samsung"}

When my search query matches doc 1 and doc2, I want only filters color, brand and category and so facet fields are attribute_filter_color, attribute_filter_brand and attribute_filter_category.

When my search query matches doc 2 and doc3, I want filters color, size, category and brand and so facet fields are attribute_filter_color, attribute_filter_size, attribute_filter_category and attribute_filter_brand.

When my search query matches doc 1 and doc3, I want filters color, brand and size and so facet fields are attribute_filter_color,attribute_filter_brandand attribute_filter_size.

Also these filters can be ~300 total over 10^5 products. This creates another problem for making a GET URL with 300 facet fields which might cross the limit for GET URL.

This jira ticket shows how regex could have helped in this situation.

Upvotes: 2

Views: 671

Answers (1)

MatsLindh
MatsLindh

Reputation: 52792

My solution would be to index the field names to an additional field, so that you have "facet_fields": ["attribute_filter_color","attribute_filter_brand"] for the documents containing the fields as well.

Generate a facet across your document result set, then use that result in a new query to generate facets across the fields you're interest in. It will be an extra query, but should scale decently. The part that will be expensive will be the larger number of different fields you're faceting on anyway - the facet_fields field will be quick to calculate and return.

Upvotes: 1

Related Questions