search-ui icon indicating copy to clipboard operation
search-ui copied to clipboard

[Question] Independent facet labels and values

Open julianklotz opened this issue 4 years ago • 9 comments

Dear community,

here’s an interesting case I have. I’d like to use MultiCheckBox facets for filtering. My facets aren’t string-only, but objects with ID and name field, because we do have some ambiguous labels:

// pseudo code – structure of facets
let facets = {
  seasons: [{
    id: 123,
    name: "Season 1981/82"
  }, {
    id: 123,
    name: "Season 1982/83"
  }
}

I’d like to use the object’s ID for filtering, but use its name as label for MultiCheckBox facets. From what I’ve seen, I think that Search UI facets (except for range fields) only works with string-only (or other primitives) facets.

What is the intended way to go in such a case?

julianklotz avatar Aug 03 '21 14:08 julianklotz

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.

botelastic[bot] avatar Oct 02 '21 15:10 botelastic[bot]

Any ideas here? Still haven’t found what I’m looking for 🎶

julianklotz avatar Oct 04 '21 07:10 julianklotz

Sorry for the delay. Are you using this with App Search? Or Elasticsearch? Or some other backend?

I'm having trouble wrapping my head around your problem.

I'm going to close this issue for now because I'm pretty sure the answer is "no, it's not possible", but feel free to add more color to the conversation, I might be missing something.

JasonStoltz avatar Oct 11 '21 19:10 JasonStoltz

Thanks @JasonStoltz – I guess you’re right. I was looking for a way to use objects (with label and value properties) for faceting.

My use case is this:

  • My website has a search page that is backed by plain ElasticSearch (without app & site search connectors)
  • Let’s say you can use the search page (build with Search UI) to filter photos by their period of creation, using aggregations by seasons (it’s about performing arts :-))
  • The website is multi-language, so my filter value is something like “Season 1981/82” (EN), “Saison 1981/82” (FR), …
  • I’d like to deep-link the search results page from various other places, e.g. “Search all photos for season 1981/1982“, pointing to /search/?season=123&type=456. The important thing here is using season and type IDs instead of (translatable) strings, so I don’t need to keep track of various translations, but can use IDs for deep linking.

What I wanted to do: Find a way to set season ID 123 as filter value internally, but display „Season 1981/82“ (or any other label from aggregations).

Here’s my actual solution: Before rendering the search results page, I parse the params (?season=123&type=456) and run an aggregation query. I use the buckets to map the IDs to the labels that ES uses.

julianklotz avatar Oct 11 '21 19:10 julianklotz

That's a really good point. Being able to handle this scenario would be really valuable, especially given i18n requirements.

I actually think it'd be easy enough to add support for this use case to search-ui. I'm going to reopen this and handle it as a feature request.

Good call, thanks for adding your explanation!

JasonStoltz avatar Oct 12 '21 13:10 JasonStoltz

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.

botelastic[bot] avatar Dec 11 '21 14:12 botelastic[bot]

Following. This is a rather common requirement for us.

marcvangend avatar Mar 25 '22 16:03 marcvangend

Got it. For what it's worth, in the meantime, you should be able to create a "Custom" view for this.

The process describing how to do this can be found in the Advanced guide.

So it shouldn't be a total dead-end right now, but we could definitely make it easier in the future.

JasonStoltz avatar Apr 11 '22 17:04 JasonStoltz

Thanks Jason. In fact we did create a custom view, but like you say, it could be much easier.

marcvangend avatar Apr 14 '22 18:04 marcvangend