#community-help

Faceting Nested Information with Single Field and Separator

TLDR Jainil asked about faceting by an object, but Jason suggested storing data in a single field using a separator. Jainil considered using JSON but Jason reaffirmed any unique string can be used.

Powered by Struct AI
12
4mo
Solved
Join the chat
May 17, 2023 (4 months ago)
Jainil
Photo of md5-bea1e4531665b4608c47d00462429d3a
Jainil
02:20 PM
I have nested information about a field that I’m using to facet my records - I.e
• type of source
• name of source
Is it possible to facet by an object? If not, what’s the recommended way of faceting such that I’m able to get both properties in the faceting menu (I.e both name and type)
02:21
Jainil
02:21 PM
My thoughts is either just encode both fields into a single field (stringified json) and then decode and use decoded
02:22
Jainil
02:22 PM
But if I don’t have to go through the encode/decode process as to not have duplicate data that’d be awesome.
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
07:57 PM
It is not possible to facet by a whole object, only on values within an object individually
07:58
Jason
07:58 PM
I would recommend storing this data in a single field using a special separator that you can parse out at display time.

So for eg, create a new field called type_name_facet and store the value as typeA|||nameA
07:59
Jason
07:59 PM
then facet on this field, and when you want to display the facets to users, split the value on ||| and then use the appropriate component for display purposes
May 18, 2023 (4 months ago)
Jainil
Photo of md5-bea1e4531665b4608c47d00462429d3a
Jainil
06:40 PM
Would there be any reason not to just encode it as a json?
06:41
Jainil
06:41 PM
So the type_name_facet becomes '{"type": "typeA", "name": "nameA"}'
06:43
Jainil
06:43 PM
My goal is to allow for full flexibility of all fields (some information might take in user input, and so we're not guaranteed the user ever doesn't use the specified delimiter)
06:43
Jainil
06:43 PM
i.e. name = "This ||| is my name"
06:43
Jainil
06:43 PM
Perhaps an over optimization
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
06:59 PM
Yeah, you could store a JSON string too (not a parsed object)… just any string that would be unique