Charles-Antoine Demers
03/11/2025, 10:22 PMfilter_by: $mandated_candidates(mandate_id:=X) && !$mandated_candidates(mandate_id:=Y)
I get this error : More than one joins found for collection mandated_candidates
in the filter_by
. Instead of providing separate join conditions [...]
I found this issue on GitHub that might be related : https://github.com/typesense/typesense/issues/2145
Is what I'm trying to do possible?
Thanks !Jason Bosco
03/11/2025, 10:25 PMcandidates
collection, then a reference field should exist in that collection that references a field in mandated_candidates
for you to be able to mention that $collectionName in the filter_byCharles-Antoine Demers
03/11/2025, 10:31 PMCharles-Antoine Demers
03/11/2025, 10:33 PM// Get all the candidats that are assigned to mandate X
filter_by: $mandated_candidates(mandate_id:=X)
// Get all the candidates that are NOT assigned to mandate Y
filter_by: !$mandated_candidates(mandate_id:=Y)
It's really when I try to combine the two that I have some issuesJason Bosco
03/11/2025, 10:34 PMHarpreet Sangar
03/11/2025, 11:41 PMfilter_by: $mandated_candidates(mandate_id:=X) && !$mandated_candidates(mandate_id:=Y)
be logically equivalent to
filter_by: $mandated_candidates(mandate_id:=X)
Unless mandate_id
is an array field š¤
The use case of the github issue is different from your scenario. This should work for you:
filter_by: $mandated_candidates(mandate_id:=X && mandate_id:!=Y)
Charles-Antoine Demers
03/12/2025, 12:18 AMfilter_by: $orders(item_name:=iPhone 16) // returns customer A and customer B
I can also get everyone that has never ordered an iPhone 16 :
filter_by: !$orders(item_name:=iPhone 16) // returns customer C
I want to get is the customers that have ordered an iPhone 16, but have not ordered a Samsung S25. This query doesn't work :
filter_by: $orders(item_name:=iPhone 16 && item_name:!=Samsung S25) // returns customer A and B, should not return customer A since they also have an order for the S25
Does this example make a bit more sense?Charles-Antoine Demers
03/12/2025, 12:35 AMselect * from "customers" where exists (select * from "orders" where "customers"."id" = "orders"."customer_id" and "item_name" LIKE "iPhone") and not exists (select * from "orders" where "customers"."id" = "orders"."customer_id" and "item_name" LIKE "Samsung")
Harpreet Sangar
03/12/2025, 12:37 AMfoo
and the following docs:
foo: [X, Y]
foo: [X, Z]
foo: [Z]
You want a way to get all the docs where foo
is X
but not Y
. So only second doc should be a match?Charles-Antoine Demers
03/12/2025, 12:39 AMHarpreet Sangar
03/12/2025, 12:43 AMfoo:=X && foo:!=Y
would return only the second document.
Similarly, this would only return B. IfCopy codefilter_by: $orders(item_name:=iPhone 16 && item_name:!=Samsung S25) // returns customer A and B, should not return customer A since they also have an order for the S25
filter_by: $mandated_candidates(mandate_id:=X && mandate_id:!=Y)
isn't returning the expected results, can you share a reproducible example?Charles-Antoine Demers
03/12/2025, 12:51 AMHarpreet Sangar
03/12/2025, 1:02 AMit's not a one to one relationshipNo need for reproduction steps. I can now imagine a scenario like
candidate_a
{id:0, mandate_id: X}
{id:1, mandate_id: Y}
candidate_b
{id:2, mandate_id: X}
{id:3, mandate_id: Z}
candidate_c
{id:4, mandate_id: Z}
Only
filter_by: $mandated_candidates(mandate_id:=X) && !$mandated_candidates(mandate_id:=Y)
would return candidate_b
.Charles-Antoine Demers
03/12/2025, 1:04 AMHarpreet Sangar
03/12/2025, 1:12 AMCharles-Antoine Demers
03/12/2025, 1:13 AM