How to show label instead of values in facets.
For example: Consider following facets
country_data: [ { title: "Wrangell–St1", country : "US" }, { title: "Wrangell–St2", country : "IN" } ]
Where i have to show countries in facet based on custom display names at client side rendering.
map displayNames / label's from : countyNames: {"US" : "United States", "IN" : "India" }
which is getting from backend.
Country
- United States (1)
- India (2)
Is there anything like label or title that I can use to show this?
Thanks in advance!
Regards
JasonStoltz
(Jason Stoltzfus)
October 20, 2020, 3:48pm
2
Hi @Swapnil_Ghorpade , this is something you'll need to code yourself on the front end. There's no way to provide labels for facet values automatically.
JasonStoltz
(Jason Stoltzfus)
October 20, 2020, 3:49pm
3
Your other option would be to do it at Index time. You could index two fields ... country
and country_display
.
@JasonStoltz Thanks for the response.
Yes, I tried other thing which gives me expected output.
I can able to show any custom string as label to facet value.
please correct me if I am doing anything wrong
here is the Code:
const apiConnector = new AppSearchAPIConnector({
searchKey: searchKey,
engineName: engineName,
hostIdentifier: hostIdentifier,
beforeSearchCall: async (existingSearchOptions, next) => {
const existingFilters = existingSearchOptions.filters || { none: [] };
const existingFiltersAll = existingFilters.all ? existingFilters.all : [];
existingFiltersAll.map((allFilter) => {
const existingFiltersAny = allFilter.any;
return existingFiltersAny.map((filter) => {
const obj = filter;
// Replace type value label with actual index id to search
if (filter.type) {
obj.type = getIdByLabel(filter.type);
}
return obj;
});
});
const results = await next({
...existingSearchOptions,
filters,
});
// Replace Types id with display name in facets
results.facets.type[0].data = results.facets.type[0].data.map((result) => {
const obj = result;
obj.value = getLabelById(result.value);
return obj;
});
return results;
},
});
1 Like
system
(system)
Closed
November 18, 2020, 3:25pm
5
This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.