I can’t find solution to write query like:
SELECT FROM myIndex WERE a=1 AND b=2 AND c=3
I can’t find solution to write query like:
SELECT FROM myIndex WERE a=1 AND b=2 AND c=3
for now i’m solve it with creating index for each field that need be queried, and using Intersection:
q.Intersection(
q.Match('index_name_1', someVal)
q.Match('index_name_1', someVal2)
...
)
For exact matches it’s easier to just an index with multiple terms:
CreateIndex({
name: "MyIndex",
source: Collection("MyCollection"),
terms: [
{field: ["data", "a"]},
{field: ["data", "b"]},
{field: ["data", "c"]}
],
})
And then:
Paginate(
Match(
Index("MyIndex"),
[1,2,3]
)
)
Yes, but in my case, i am not sure about which of arguments will be passed.
If we have index with three terms fields all three arguments must be provided, is it’s true?
So this not return data:
Paginate(
Match(
Index("MyIndex"),
[1,2,undefined]
)
)
Depends.
You can do this:
Paginate(
Match(
Index("MyIndex"),
[1,2, null]
)
)
That will match the documents that do not have the third index term.
If you want some sort of wild card with an index, that’s not possible AFAIK.
OTOH you can express any condition you want with FQL. There are a couple of examples in this article.
Awesome post, @pier!
It can get complex, but you can build an intersection query with a bunch of conditionals. Here is a similar discussion:
One basic formula could be to create a UDF along these lines
CreateFunction({
name: 'search_comments',
body: Query(
Lambda(
['a', 'b', 'c'],
Let(
{
with_a: If(
IsNull(Var('a')),
[],
[Match(Index('index_a'), Var('a'))]
),
with_b: If(
IsNull(Var('b')),
Var('with_a'),
Append(Var('with_a'), [
Match(Index('index_b'), Var('b'))
])
),
with_c: If(
IsNull(Var('c')),
Var('with_b'),
Append(Var('with_b'), [
Match(Index('index_c'), Var('c'))
])
),
// keep repeating for more options
// ...
computed_set: If(
IsEmpty(Var('with_c')),
Documents(Collection('things')), // simplify if no filters
Intersection(Var('with_c'))
)
},
Paginate(Var('computed_set'))
)
)
)
})
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.