on ‎2018 Aug 08 12:31 PM
Request clarification before answering.
ok, I little tricky to do because solr does not support relations like any relational DB would do. create a field called category hierarchy and pass the entire category hierarchy as json in a single field.
For example, you have a product which is under Bags, while doing solr indexing, create a value provider that pushes the whole category hierarchy as JSON to solr.
sample json will be { "categoryName": "Bags" subcategories: { "Linen Bags", "Leather Bags", "Plastic Bags" } }
when creating facets, retrieve the JSON from categoryHierarchy field and convert it into Java object
public class CategoryHierarchy {
private String categoryName;
private List<String> subCategories;
public String getCategoryName() {
return this.categoryName;
}
}
and do
CategoryHierarchy ch = convertFromJson(categoryHierarchySolrField); <br>
if(categorySearchedFor.equalsIgnoreCase(ch.getCategoryName())) {
createFacet()
}
else {
// do nothing.
}
See google GSON api for converting between Java & Json. it is very lightweight API.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi . Can you please elaborate ? If you have a category structure like below
Categories -> Women -> Accessories -> Bags -> Bag-Product
What do you wish to display as a facet ?
Note: Bag-Product is a product here.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi when i search for a category it should return sub categories of that category in category facet. Suppose if i search for Accessories it should return only sub-categories of Accessories.
Actually solr returns facets based on indexed products, some products mapped to multiple products, so when search for a category it returns other subcategories also.
if Bag-Product mapped to bags and belts, when i click on bags category page i am getting belts also in fecet.
| User | Count |
|---|---|
| 4 | |
| 2 | |
| 1 | |
| 1 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.