search-ui
search-ui copied to clipboard
Exclude values (such as "") from Facet component
Is your feature request related to a problem? Please describe. I am building a facet component for a field that is blank for some records or otherwise has a field I don't want visible. I would like an option within the component that allows me to exclude certain values from the facet component.
Describe the solution you'd like It'd be great to have this be an array that I can set within the React component itself. This is the pattern that we used in Searchkit.
<Facet
field="get_major_filter"
label="Major"
filterType="any"
isFilterable={true}
**exclude={["", "Non-degree"]}**
/>
Describe alternatives you've considered I can't think of a way to do this outside of building a custom facet component, which I really don't want to do. For now, allowing "" and "Non-degree" to display is good enough, but it looks pretty bad (the blank string is just a checkbox).
Hey Thanks for the suggestion!
Right now, we’d recommend handling this kind of logic via filters instead of excluding values inside the component. That way, you have full control over what gets included in the query, and the facet counts stay accurate.
Example:
filters: [{ field: "get_major_filter", type: "none", values: ["Non-degree"] }]
Documentations
Not sure though if it's gonna work for empty string
If we were to exclude values in the component itself (like exclude={["", "Non-degree"]}), it could lead to weird UX — for example, the user might see “4 results”, but in Elasticsearch there are actually 6, because we silently skipped some. That breaks transparency and can confuse.
So while we understand the need, filtering those values out at the query level is a safer and more consistent approach. Let us know if that setup doesn’t cover your use case.
I'll close this issue
@tanza-s feel free to open it if filter: "none" won't solve problem
Hi, I don't know if this solves my problem.
We don't want to filter out the results. Some of the fields we want to hide from the component are optional fields, so we want the users to be able to see them. There isn't a case where we want to, for example, have the user filter out people who have not included an address, or do not have a "state" in their address because they live in another country.
Additionally, the empty string is the value we want to exclude. This is what it looks like.
I do not have permission to re-open this issue. I can make another one with more detail if that's helpful.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Is this issue still important to you? If so, please leave a comment and let us know. As always, thank you for your contributions.