Question

I am completely new in solr and have the issue to have to go on developing our new search-engine, because my collegue is is not here anymore.

My problem: I want to get facetted (hierarchical)categories with itemcount.

example

Search for 'Galaxy'

Items found: 123

Shown Categories:

    Electronics (83)
        Mobiles (60)
        Tablets (23)
        Smartphones (37)
        ..... 
    Books (40)
      ....

....

my category-fields (in solr) for each article contain several category-trees, seperated by comma. e.g.:

    "categories_raw": "Electronics/Mobiles/Tablets,Books/MobilePhones"

A query sent to my solr with the following parameters results facet_fields with item counts, but only with counts from the items own subcategory:

    q=samsung&q.alt=samsung&...&facet=true&facet.field=categories_raw&facet.mincount=1

results (at the end of resulting JSON):

    "facet_counts": {
        "facet_queries": {},
        "facet_fields": {
          "categories_raw": [
            "Electronics/Mobiles/Smartphones",
            37,
            "Books/MobilePhones",
            20,

....

How can I get a count on each category like on my example on top?
Is it possible to break down my hierarchical category-string in field "categories_raw" by solr? Did I miss something?

Hope someone could help ;) thx

Was it helpful?

Solution

Solr counts what you give it. Try using multivalued fields and putting the values you want to count in there. So:

Electronics/Mobiles/Tablets 
Electronics/Mobiles 
Electronics

Then, the facets will give you counts for each of those. To create those, you can either do them on client side or look at writing a custom Update Request Processor to do it when the entry is created (before indexing).

Solr has also some support to extra hierarchical information from the structured path.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top