John
03/20/2023, 1:23 PMname="Blue", h=0, s=10, l=20
, facet by that, and then have the frontend nicely display the name along with the actual color. However, it doesn’t seem like faceting based on objects is working, you just get the empty string.
Is this something you could implement support for or do we have to try to find a workaround? I imagine you could hash the objects and facet by that as a string under the hood or something. Code in thread.John
03/20/2023, 1:23 PMimport json
import typesense
COLLECTION = "example"
client = typesense.Client(
{
"api_key": "TYPESENSEDEV",
"nodes": [{"host": "localhost", "port": "8108", "protocol": "http"}],
"connection_timeout_seconds": 2,
}
)
try:
client.collections[COLLECTION].delete()
except:
pass
fields = [
{
"name": "title",
"type": "string",
},
{
"name": "color",
"type": "object",
"facet": True,
},
]
client.collections.create(
{
"name": COLLECTION,
"fields": fields,
"enable_nested_fields": True,
}
)
products = [
{
"title": "foo",
"color": {
"name": "red",
"h": 0,
"s": 100,
"l": 50,
},
},
{
"title": "bar",
"color": {
"name": "blue",
"h": 240,
"s": 100,
"l": 50,
},
},
{
"title": "baz",
"color": {"name": "Multi-colored", "special_type": "multi"},
},
]
client.collections[COLLECTION].documents.import_(products, {"action": "create"})
facet_counts = client.collections[COLLECTION].documents.search(
{
"q": "*",
"facet_by": "color",
}
)["facet_counts"]
print(json.dumps(facet_counts, indent=4))
Kishore Nallan
03/20/2023, 1:24 PMcolor.*
in the facet_by?John
03/20/2023, 1:27 PMtypesense.exceptions.ObjectNotFound: [Errno 404] Could not find a facet field named `color.*` in the schema.
John
03/20/2023, 1:27 PMcolor.name
for example worksJohn
03/20/2023, 1:27 PMKishore Nallan
03/20/2023, 1:28 PMKishore Nallan
03/20/2023, 1:30 PM0.25.0.rc14
John
03/20/2023, 1:31 PMJohn
03/20/2023, 1:35 PM0.25.0.rc14
but it still seems to facet the fields independently, whereas what I’d want is something like
{
"value": {"name": "blue", "rgb": "#123456"},
"count": 3
},
{
"value": {"name": "black", "rgb": "#000000"},
"count": 2
}
Kishore Nallan
03/20/2023, 1:40 PMJohn
03/20/2023, 1:43 PMKishore Nallan
03/20/2023, 1:44 PMJohn
03/20/2023, 1:45 PMKishore Nallan
03/20/2023, 1:45 PMJohn
03/20/2023, 1:45 PMJohn
03/21/2023, 8:10 AM