I use Solr to store products. Each product can have multiple categories.
<field name="id" type="string" indexed="true" stored="true" required="true" multiValued="false" />
<field name="sku" type="text_en_splitting_tight" indexed="true" stored="true" omitNorms="true"/>
<field name="cat" type="string" indexed="true" stored="true" multiValued="true"/>
<field name="cat_left" type="int" indexed="true" stored="true" multiValued="true"/>
<field name="cat_right" type="int" indexed="true" stored="true" multiValued="true"/>
I would like to find all products which fall into a certain category and following subcategories. To avoid recursive search I calculate LEFT/RIGHT value for each category node. In SQL database it works well. An example query would look like this:
SELECT * FROM Products p JOIN Categories c WHERE c.left > 2 AND c.right < 8
I can’t do the same in Solr because multiple left and right values are not paired. If I have 2 pairs assigned to a product:
{left: 2, right: 3}
{left: 6, right: 8}
and I will query:
+cat_left:[4 TO *] +cat_right:[* TO 5]
The product will be obviously returned because the smallest left value is 2 and highest right is 8. Solr doesn’t know that for left equals 2 right end on 3. Those fields are not associated.
I like the Left/Right approach because it’s fast way to query a tree but is it possible to use it with Solr? Perhaps I over complicate and Solr have a good tree support?
Thew answer to my question was 1 dimensional Poly Field (Solr query if value matches one of several intervals)