get models by example in Hybris
Sometimes, we are required to fetch data from our custom Item type in Hybris. So first thing comes to our mind is to write flexible search query. But you really don't need to do that if you know Hybris OOTB has
getModelByExample
and getModelsByExample
API of flexibleSearchService, using which we can easily get the desired results.Scenario
Find CustomProduct having the same name
Solution
You can create a method in DAO class. In which you need to create example model by setting required field (e.g name). Now call getModelsByExample method of the flexibleSearchService with exampleModel.
public List<CustomProductModel> findProductHavingSameName(final String name)
{
CustomProductModel exampleModel = new CustomProductModel();
exampleModel.setName(name);
return getFlexibleSearchService().getModelsByExample(exampleModel);
}
Other than Equals qualifier, can we use other parameters here as well, like starts with, greater than etc?
ReplyDeleteFor models by example, flexibleSearchService only supports tow methods getModelByExample and getModelsByExample. So you can't use other parameters here.
ReplyDelete