1
votes

I'm working with some dynamic attributes in a product catalog, indexed under one field (similar to this). A simple example would look like this:

{id: 1,  DYN_ATT:Color||Green,  DYN_ATT:Size||Small}
{id: 2,  DYN_ATT:Color||Red,    DYN_ATT:Size||Small}
{id: 3,  DYN_ATT:Color||Green,  DYN_ATT:Size||Small}
{id: 4,  DYN_ATT:Color||Red,    DYN_ATT:Size||Large}

However, it seems to be impossible to enable multi-select as if these are all different facets.

For example, say the user selects the Green Color facet in the UI:

[ ]Red
[ ]Green
----------
[ ]Small
[ ]Large

The resulting facets should show all possible values for Color (to allow the user to select Red OR Green. But should filter the Size facet based on Green being selected in another (logical) facet.

[ ]Red
[x]Green
----------
[ ]Small

Is there any way to do this? I haven't found any answers and suspect a different approach may be needed. Unfortunately the types of attributes in the data vary wildly.

Neither of these work:

fq={!tag=DYNTAG}DYN_ATT:"Color||Green"&facet.field={!ex=DYNTAG}DYN_ATT

This yields too many results for Size. A facet for [ ]Large should NOT be available, but would be returned. If the user selects it, the two filters would be disjoint and yield no results.

fq={!tag=DYNTAG}DYN_ATT:"Color||Green"&facet.field=DYN_ATT

This yields too few results, excluding Red from facets, so the user would NOT be able to multi-select on Color:

[x]Red
[x]Green

Any ideas?

1

1 Answers

1
votes

I've found a way to solve this problem. It turns out the same facet.field may be reused with different tags, like this:

&facet=true
&fq={!tag=DYN}DYN_ATT:"Color||Green"
&facet.field=DYN_ATT
&facet.field={!ex=DYN key=DYN_ATT_OR}DYN_ATT

This yields two results for the DYN_ATT facet. Something like this:

"facet_fields": {
    "DYN_ATT": [
        // facets filtered based on fq
    ]
    "DYN_ATT_OR": [
        // facets unfiltered
    ]

Then I just had to use the DYN_ATT contents for the unselected facet results, and the DYN_ATT_OR facets for the selected facet results (those I want to allow OR-ing on, for multi-select).