I am attempting to implement a vehicle selector for an auto parts site. I want to implement the year / make / model choice in the form of facets. I'm running into a problem, for which I've thought of several solutions.
The problem: products have multiple vehicle compatibilities. The compatibility of a product is defined as the set of unique combinations of terms assigned to products. To group the term selections I've used a multigroup (cck 3), so I have node properties like this:
$node->field_year[0]['value'] = 2005
$node->field_make[0]['value'] = Mazda
$node->field_model[0]['value'] = Millenia
...
and so forth. So what I want to search is 2005 and Mazda and Millenia where these terms appear with the same delta. I can't just search for products with 2005 and Mazda and Millenia, because the 2005 term might apply to Ford Taurus in some other delta.
If I were doing this with a relational database, I'd create an association table that keyed unique combinations of the three terms. Then, I'd refer in my product to a row in that table and join on it in my query.
My question is how I would do this in Solr.
At first I thought I would create a multi valued field of arrays, like a multidimensional array in php:
$doc->setField('sm_year_make_model', array(year,make,model));
But this doesn't seem possible. The array value simply gets indexed as "Array".
So the best solution I've found is to create a field that contains the concatenated year + make + model values, like so:
$doc->setField('sm_year_make_model', implode('_', array(year, make, model));
As the user selects facets these are grabbed from the filters in hook_apachesolr_prepare_query() and sm_year_make_model:2005_Mazda_* is ANDed onto the query (depending on which tids are in the filters). The field would then act as a kind of mask, ensuring that the selected terms are being found together.
A second solution I've thought of would be to add multiple sm_year_make_model_ fields. So products have fields like
sm_field_year_make_0 = 2005 Mazda
sm_field_year_make_1 = 2007 Mazda
sm_field_year_make_model_0 = 2005 Mazda Millenia
...
So I just query these, and forget about taxonomy filters.
Sorry for the long post. Just wanted to make my question clear.
Sorry for the long post. I've been thinking through this for a while, and I'm by no means a Solr guru.
Comments
Comment #1
pwolanin commentedThe first solution seems better at first reading, since you would only need to query the one field in Solr.
Comment #2
cmjns commentedThanks, pwolanin. I thought so too. Still, it feels a bit awkward-- which probably stems more from the fact that I'm trying to make solr act like an relational db. If anyone thinks of a better way I'll be happy to hear about it.
Comment #3
cmjns commentedOn further research, I see that what I'm really after is the polyField functionality in the current solr dev (future 4.0). Of course, this isn't in 1.4.x, so I'm out of luck. Unless there were a way to make the apachesolr.module and friends work against the dev branch of solr? Just for giggles, I tried it. Tried messing around with the schema.xml to see if I could get it to work... but I don't know enough to know whether or not I should even bother trying. ?
Comment #4
pwolanin commented