You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-user@lucene.apache.org by Lance Snell <la...@gmail.com> on 2021/01/26 17:48:43 UTC

Nested documents (parent,child,grandchild), multi-select facets

 Hey all,

I am having trouble finding current examples of multi-select faceting for
nested documents.  Specifically ones with *multiple *levels of nested
documents.

Any help/direction would be appreciated.Solr. 8.6

Hopefully my terminology is correct, I'm still new to solr.

My current schema has a parent document, two child documents(siblings), and
a grandchild document.  I am using the JSON API .

Product -> Item-> Price
   |
   \/
ProductCategory

I created my schema to represent a multi-store, and multi-customer setup.

I am looking for multi-select facets from *each* document.
Product document - General product information.  *Same for all customers*
Item document - Size/Color/etc.  Product variations.  *Same for all
customers*
Price document - Customer pricing.  *Unique per customer*
ProductCategory- Ids for linking Product to Store and Catalogs.  *Unique
per customer*

I was attempting to traverse from the child documents upwards, filtering on
( ProductCategory ), (Price/Item), and then finally combine the result of
both to get (Product).
Originally I was using '_nest_path_' for my blockMasks.  However I ended up
adding a 'path' field for each document, thinking this would give me more
control?? (ex. '1.product.item.price', '1.product.item', '1.product',
'2.product.item.price' , '2..product.item', etc. )


Below is my current query.

Currently when I remove the nested {!filters tag=ITEM...}, I get the
correct number of ProductCategory documents.  When I remove the nested
{!filters tag=PRODUCT_CATEGORY...},I get the correct number of Item
documents.
When I combine them both, I get *0* results.

Is this because the two nested filters ITEM and PRODUCT_CATEGORY are not
mutually exclusive?  If so could you point or provide an example.

OR

Is this because the ITEM and PRODUCT_CATEGORY filters are not filtering on
the Product documents yet, and they are both children of the Product
document?

OR

Am I not even close??


I thought I had seen some well written examples or videos of this in the
past, but I can't seem to find those examples anymore.   Any
help/direction/links would be greatly appreciated.


{
    "params": {
        "omitHeader": "true",
        "defType": "edismax",
        "df": "pdocname_txt_en_1",
        "qf":
"pdocname_txt_en_1^2.0 description_txt_en_1^1.5
longDescription_txt_en_1^1.5 custItemNum_txt_en_split_tight_1^1.5"
,
        "pf":
"pdocname_txt_en_1^3.0 description_txt_en_1^2.0
longDescription_txt_en_1^2.0 custItemNum_txt_en_split_tight_1^3"
,
        "ps": "2",
        "qs": "2",
        "LIMIT": 0,
        "prdoc_Q2":
"prefixes:ASB000000434166111481 prefixes:ASB00000043416611148All",
//Query entry point for price documents
        "pcdoc_Q2":
"categoryPrefixes:ASB000000434166111481
categoryPrefixes:ASB00000043416611148All"
,   //Query entry point for product category
        "BRAND_FILTER":"sku:SMB505",
        "COLOR_FILTER":"",
        "SIZE_FILTER":"",
        "PRICE_FILTER":"fprice:[29 TO 30]",
        "CATEGORY_FILTER":"categoryIds:2921",
        "STORECATALOG_FILTER":"",
        "productFQ":"{!parent filters=$pidocFQ which='path:2.product.item'}"
,
        "productFilters":
"+{!parent which='path:2.product.item' v=$prdoc_Q2} +{!child
of='path:1.product.productCategory'}{!parent
which='path:1.product.productCategory' v=$pcdoc_Q2}"
,



        "priceFilters":
"prefixes:(ASB000000434166111481 ASB00000043416611148All)",
//product filters
        "productCategoryFilters":
"categoryPrefixes:(ASB000000434166111481 ASB00000043416611148All)",
//productCategory filters
        "itemFilters":"docType:pidoc"
,                                               //item(skudocument) filters
        "itemFQ":
"+(${priceFilters}) +{!child of='path:2.product.item'}{!q.op=AND
v=$itemFilters}"
, //Item filter query
        "productCategoryFQ":"+(${productCategoryFilters})",
//ProductCategory filter query
        "baseQ":
"categoryPrefixes:(ASB000000434166111481 ASB00000043416611148All)
prefixes:(ASB000000434166111481 ASB00000043416611148All) docType:pidoc
docType:pdoc -docType:catdoc -docType:stdoc -docType:cupsd"
,

        "groupingFilter1":
"{!parent filters=$itemFQ which='path:2.product.item'}",
//Filter for priceDocument -> itemDocument
        "groupingFilter2":"{!q.op=AND v=$productCategoryFQ}",
//Filter for productCategoryDocument -> productDocument
        "test":
"{!filters tag=ITEM param=$groupingFilter1} {!filters
tag=PRODUCT_CATEGORY param=$groupingFilter2}"
,
        "topQuery_product":""

    },
    "fields":
"*, [child fl=$returnFields limit=-1
childFilter='/productItems/{!filters v=$child_FQ2}']"
,
    "filter": [

// "${prdoc_Q2} {!parent which='*:* -_nest_path_:\\\\/*' v=$prdoc_Q2}
{!parent which='*:* -_nest_path_:\\\\/productItems\\\\/*' v=$prdoc_Q2}
categoryPrefixes:(ASB000000434166111481 ASB00000043416611148All)"

"_query_:(${prdoc_Q2} ${pcdoc_Q2} docType:pcdoc docType:prdoc
docType:pidoc docType:pdoc)"
,
        "{!filters tag=MID param=$test v=$baseQ}"
    ],
    "sort":
"{!parent which='*:* -_nest_path_:*' score=max v='+docType:prdoc
+{!func}fprice'} asc"
,
    "offset": 0,
    "limit": "${LIMIT}",
    "facet": {
        "testing": {
            "type": "terms",
            "field": "docType",
            "limit": -1,
            "facet": {
                "parentCount": "unique(_root_)",
            },
            "domain":{
                "excludeTags":[
                    "TOP",
                    //"MID",
                    // "LOW"
                    ]
            }
        },
        "testing2": {
            "type": "terms",
            "field": "docType",
            "limit": -1,
            "facet": {
                "parentCount": "unique(_root_)",
            },
            "domain":{
                "excludeTags":[
                    "TOP",
                    "MID",
                    // "LOW"
                    ]
            }
        }
    }
}


-- 
Thanks,

Lance