on 08-21-2018 11:35 PM
Requirement is to display 'compatible products' along with product search result.
Compatible product is also a product(different product extended model) where 1 or more products could be added to a product as compatible products. I've to display this in the category page. For e.g. In Telco, I've to display compatible list of phones for a plan.
Created a multi-value solr property and added a custom value provider to index this attribute.
In the valueprovider, I could fetch the list of compatible product model and returns the product code as fieldValues.
While populating the search result in the category page, I'm querying the DB for these compatible product and populate required attributes like url, name and code. I feel this approach is bad, since I've to query DB for these items every time, whereas right approach would be using solr results.
If anyone had achieved this functionality through any better approach, please provide your ideas. Or similar kind of requirement.
anything like listeners or postprocessor or beforehandlers to handle this functionality?
Thanks,
Hi : We have achieved something similar and what I am proposing is tested to be well performing.
for example you have 2 plans, Plan A and Plan B. Compatible products for Plan A are Apple iPhoneX and Samsung Galaxy Note 9. Compatible products for Plan B are Apple iPhone 8 and Samsung Galaxy 8.
Now create a value provider called CompatibleProductsValueProvider. In your value provider do the following.
List<ProductModel> compatibleProductModels = planAProduct.getCompatibleProducts();
List<CompatibleProductData> compatibleProductsData = new ArrayList<>();
/* convert all compatibleProductModels to compatibleProductsData, only populate the fields that you need to show on the front end, like name, description and price. */
Gson gson = new Gson();
String valueToBeSentToSolr = gson.toJson(compatibleProductsData);
// the above function will convert your list to a json object and return you a string which you will send to solr.
Now when you are retrieving data from solr, you will get this string back from solr, convert this string back to object by doing
Gson gson = new Gson();
List<CompatibleProductData> compatibleProductsData = gson.fromJson(solrProduct.getCompatibleProductsJson());
once you have the data object, you can easily show on the frontend.
The benefits of this approach are as follows:
1) that you will never have to hit DB when user's are querying solr
2) you will avoid text searches which at times do not give the best results,
3) you do not have to create unnecessary text fields. If you do not know, creating many text fields can give unexpected results if solr is not configured properly.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
If you do not want to hit database to fetch the related products data, you can do a text search on Solr by passing the product code in query, That will bring the results from Solr, which is faster and you can use them to display.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
5 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.