Hi,
I’m implementing a search for a booking system. User can search for bookings (which are called offers
in the index names) using multiple combinations of search filters. I’ve built the logic very close to the “Option 3” in this article.
I use separate indexes for each criterion I want to search for, like:
{
name: "offers_by_country",
unique: false,
serialized: true,
source: "offers",
terms: [
{
field: ["data", "startBase", "country"],
transform: "casefold"
}
],
values: []
}
and I have one which I use to join
it by ref
getting me all the values I want to display a search result.
{
name: "offers_all_values_by_ref",
unique: false,
serialized: true,
source: "offers",
terms: [
{
field: ["ref"]
}
],
values: [
{
field: ["data", "x"]
},
{
field: ["data", "y"]
},
{
field: ["data", "z"]
},
{
field: ["data", "uid"]
}
]
}
I join each offers_by_foo
index with the offers_all_values_by_ref
index as in:
q.Join(
q.Match(q.Index("offers_by_country"), q.Casefold("italy")),
q.Lambda(
["ref"],
q.Match(q.Index("offers_all_values_by_ref"), q.Var("ref"))
)
)
push those different join
s into an array, and I query in the end using an Intersection
of the array items.
This works well.
But I get multiple results with the same uid
(see the offers_all_values_by_ref
's last value). This is normal as they are different offers. But for my use case, I want a single result per uid
. They are already sorted by price, so I’m happy with getting the first one.
I hope I haven’t put myself into a corner using this technique but I can’t find an easy way to get what I want. I’d appreciate any help.
Thanks