I’ve created a custom field at Liferay commerce product Level. Everytime a product is created, I’m storing the user’s organization ID in that custom field. Now, I’ve a requirement to display user specific products in the search results and other related facets.
I’ve tried achieving this with multiple ways but got no success in all of them. I’ve created a Custom Search Context contributor to add a search query to filter out the results but not sure whether I’m going in the right direction or not.
@Component(immediate = true, service = SearchContextContributor.class)
public class UserOrgSearchFilter implements SearchContextContributor {
@Override
public void contribute(SearchContext searchContext, SearchContextContributorHelper searchContextContributorHelper) {
MatchQuery matchQuery = queries.match("expando__keyword__custom_fields__Organization", "64");
BooleanQuery orgIdQuery = queries.booleanQuery();
orgIdQuery.addMustQueryClauses(matchQuery);
searchContext.setBooleanClauses(new BooleanClause[]{orgIdQuery});
}
@Reference
protected Queries queries;
@Reference
protected Searcher searcher;
@Reference
protected SearchRequestBuilderFactory searchRequestBuilderFactory;
}
Can anybody help me out in this?
Thanks in advance!!