0
votes

We are using SOLR to index products for an eCommerce application, we have products grouped by category and subcategories and the same product can appear in more than one subcategory, We need to retrieve the products in all the subcategories it belongs to and would like to use one single query to achieve this objective. Any pointers would be really helpful. Example illustrated below -

Assume that a product p1 belongs to subcategory sc1 and sc2 which belongs to parent category c1

c1 ----- sc1 ----- p1

c1 ----- sc2 ----- p1

The way we have indexed the product is to have category path information in product p1, p1 - Category path of (c1->sc1 and c1->sc2)

When the user browses through the category c1 the product should appear twice on the page grouped by subcategory sc1 and sc2 as shown below

c1 ----- sc1

          p1

----- sc2
          p1

We want to query from solr so that it returns the same product grouped in 2 different subcategories, effectively duplicating in the result. We could do it programatically after fetching the result from solr but we have pagination and sort order logic which would be hard to maintain in the code.

2
This is useful: stackoverflow.com/questions/8504477/… . Solr faceting returns all facets the searches retrieves.Jesvin Jose

2 Answers

1
votes

This is like tags. You know that when you tag things, a single item can have more than one tag. In SOLR you would represent that as a multivalued field, i.e. an array of values.

You need to make "subcategory" into a multivalued field. I think that your reference to path means that the same subcategory identifier is used in multiple unrelated categories thus you are combining category and subcategory together to get unique keys.

In that case you might have:

p1, [c1>sc1]
p2, [c1>sc2,c1>sc7]
p3, [c1>sc5]
p4, [c1>sc1,c1>sc5]

When you retrieve all products with subcategory matching c1

0
votes

In order to actually return the product multiple times, you would need multiple records in your Solr index for that product. I suspect that would make updating individual product records a bit difficult however -- assuming you're using a unique key, you would need a key based on both product ID and subcategory.

I agree with Michael Dillon's suggestion of making "subcategory" a multiValued field and then formatting the results appropriately.