I'm working on a search
functionality and my current code works for searching using the name_lower
field in my firestore document.
Supposed I have this document in my collections:
{
name_lower: 'burnik',
keywords: ['gago', 'sira']
}
const searchArr = searchParams.split(' ');
const snap = await productsRef
.where('name_lower', 'in', searchArr)
.limit(12)
.get();
But how do I query if I also want to query for matched keywords
in my document
This is not valid since I have combined a in
and array-contains-any
filter as the error says.
const snap = await productsRef
.where('name_lower', 'in', searchArr)
.where('keywords', 'array-contains-any', searchArr) // <------- invalid
.limit(12)
.get();
I thought of a possible solution by making another query for matched keywords then filter and combine them.
const matchedNameSnap = await productsRef
.where('name_lower', 'in', searchArr)
.limit(12)
.get();
const matchedKeySnap = const snap = await productsRef
.where('keywords', 'array-contains-any', searchArr)
.limit(12)
.get();
// ... map and filter matchedKeySnap and matchedNameSnap
IS THERE AN 'OR' statement in Firebase or at least a better workaround how to query either of the WHERE clause?