Tim Mackey
08/31/2024, 12:59 PMfilter_by:$categories(id:12345)
, I get the products I want (hurray!), but I want to be able to sort the products based on the order of ids stored in the categories table. I get an error when I try to edit the schema and set sort: true
on the array reference field, so is there any way to accomplish this?
For reference, I’m trying to support manual sort orders for product categories (the sort order having been set on Shopify’s backend).Kishore Nallan
08/31/2024, 2:44 PMTim Mackey
08/31/2024, 8:48 PMTim Mackey
09/02/2024, 6:41 AM$categories(id)
is type string[]
, containing an array of product IDs.Harpreet Sangar
09/02/2024, 12:50 PMsort: true
on the array reference field
Can you share the specific error you're getting?Harpreet Sangar
09/02/2024, 12:52 PMTo clarify my question, is there any way to sort my products collection by the order of ids in the JOINed categories id field?https://github.com/typesense/typesense/issues/1582 This is a related issue. Can you provide more details for your use case there?is type$categories(id)
, containing an array of product IDs.string[]
Tim Mackey
09/03/2024, 1:50 AMCan you share the specific error you’re getting?With the following schema attribute:
{
"name": "product_ids",
"type": "string[]",
"sort": true
}
I get the error:
400: Field `product_ids` cannot be a sortable field.
I think this is just because arrays can’t be sortable (since similar to that issue you posted, which value would you sort on?)Tim Mackey
09/03/2024, 2:02 AMThis is a related issue. Can you provide more details for your use case there?Thanks for the suggestion. My issue is different enough to probably be a separate issue I think. Here’s an example
// Products
[
{id: "1"},
{id: "2"},
{id: "3"},
{id: "4"}
]
// Categories
[
{
id: "A"
category_title: "Featured Products",
product_ids: ["3","1","2"]
},
{
id: "B"
category_title: "On Sale",
product_ids: ["4","1"]
}
]
If I do a lookup on the products table with _*filter_by*_ set to $categories(id:A)
, I get a response giving me only the products listed in product_ids
field for Category “A” (this is correct).
What I’d like is to have the products sorted by the order specified in product_ids
(3,1,2). Typesense doesn’t see that order though, so I the products are returned sorted as (1,2,3). Likewise, if I filter by $categories(id:B)
, I’d expect to get the products in order (4,1) but I get them in order (1,4).Harpreet Sangar
09/03/2024, 4:51 AMProducts
collection. If not, you can achieve this by:
collection: Categories
q: *
filter_by: id:A
include_fields: $Products(*)
Tim Mackey
09/03/2024, 3:10 PM