Anders
Anders

Reputation: 1042

How to get both key and value to use in in facet and filter

I have facets I want to use for filtering, as I assume most common use of facets is.

The filter in the UI is through a multi-select dropdown. However, the text labels in the facets are quite long, and when selecting multiple, I end up with very long strings to use in the filter. Therefore I want to use keys/ids for each facet text. But how do I get a key out of a facet, and not just the value?

--- Facet example ---

Id  |  Value
-------------------------------------------------------------------------- 
1   |  This is a very long facet text with many characters, including æøå. 
2   |  And there are other texts, also with / and & and more æ, ø og å.

If I had an id in the facet, retrieved from the index, where the facet would be a complex type with key and value, then I could use that when selected in the UI and do a filter on the id instead of the long text(s).

Ideas, input?

Thanks!

Upvotes: 1

Views: 379

Answers (1)

Arvind - MSFT
Arvind - MSFT

Reputation: 569

Unfortunately, there isn't a concept of "complex" facets, which is what you are requesting. Facets only return the text and the count indicating how often it occurs in the source documents.

  1. When you complain about very long strings in the filter, is it because you are running into request size limits? Have you considered POST vs GET when making your query?
  2. Have you considered using search.in if your search term cardinality is quite high (as described here)?

Facets in general are not meant to have extremely long values, as they serve the purpose of quick filtering/hierarchical navigation for the end-user. Although technically you can make any field facet-able, usually fields which represent full text(s), or possibly having a high cardinality should not be used as facets

One possible work around, would be to have another field in your index, which uses some fixed length hashing on your text field (this should be quite possible using the push API; we don't have this facility via indexers); then once you get back a list of facets, you can apply the same hash function on the client side (UI) and then use the generated (presumably small) fixed length string and query against that "new" field.

Upvotes: 2

Related Questions