[SOLVED] Create OR query to receive documents where one or multiple attributes fits a search term
- 0
- Databases
- Web
- Self Hosted

Excellent. so that works, and I would want to use variables.

right...so if you're passing in variables, you can put Query.search("attr", "value")
for the variable value

It's confusing when you switch between different syntax.

I tried this query
queries: ["search(\"group_a\", \"hello\")","search(\"group_b\", \"hello\")"]
ERROR:
Search method requires fulltext index: group_a,group_b
Is there an $or operator?

no you can't search against multiple attributes like that. that will be treated like AND. you must execute multiple queries

How would I fix this in a single request?

with graphql you can make muliple api calls in 1

yes

query search($databaseId: String!, $collectionId: String!, $search1: String, $search2: String) {
search1: databasesListDocuments (
databaseId: $databaseId
collectionId: $collectionId
queries: [$search1]
) {
total
documents{
_id
_createdAt
_updatedAt
_permissions
data
}
}
search2: databasesListDocuments(
databaseId: $databaseId
collectionId: $collectionId
queries: [$search2]
) {
total
documents{
_id
_createdAt
_updatedAt
_permissions
data
}
}
}

Thanks. I can't figure out how to escape the usage of the search variable in the queries

Why do some Strings! contain a bang?

what exactly is your code?

That's graphQL syntax for non-nulable. see https://graphql.org/learn/schema/

search1: databasesListDocuments (
databaseId: $databaseId
collectionId: $collectionId
queries: ["search(\"group_a\", \"$search1\")"]
) {
total
documents{
_id
_createdAt
_updatedAt
_permissions
data
}
}
search2: databasesListDocuments(
databaseId: $databaseId
collectionId: $collectionId
queries: ["search(\"group_b\", \"$search1\")"]
) {
total
documents{
_id
_createdAt
_updatedAt
_permissions
data
}
}
}```

This is just your query. What's your actual code in your app?

Do you mean what am I trying to do?

no...i expect expect this to be in some javascript code if you're making a javacsript based app.

Currently I am playing around with this query in graphql explorer. I have a React based website where I am attempting to display search results with this graphql query

ok so you would use our SDK and write something like:
import { Client, Graphql, Query } from "appwrite";
const client = new Client()
.setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your Appwrite Endpoint
.setProject('[PROJECT_ID]'); // Your project ID
const graphql = new Graphql(client);
const query = graphql.query({
query: `query search($databaseId: String!, $collectionId: String!, $search1: String, $search2: String) {
search1: databasesListDocuments (
databaseId: $databaseId
collectionId: $collectionId
queries: [$search1]
) {
total
documents{
_id
_createdAt
_updatedAt
_permissions
data
}
}
search2: databasesListDocuments(
databaseId: $databaseId
collectionId: $collectionId
queries: [$search2]
) {
total
documents{
_id
_createdAt
_updatedAt
_permissions
data
}
}
}`,
variables: {
databaseId: '...',
collectionId: '...',
search1: Query.search('group_a', value),
search2: Query.search('group_b', value)
}
});

in the explorer it would have been something like

Is it too soon to say I love you?

Let me check this out..

Thank you

This worked thank you

[SOLVED] Create OR query to receive documents where one or multiple attributes fits a search term
Recommended threads
- Sharing cookies
Hi, I’m using Appwrite Cloud, and I have a setup where my Appwrite backend is hosted on a subdomain (e.g., api.example.com), while my frontend (Next.js app) and...
- Organization not exists anymore
Hello! We have a problem with a cloud database. We are on the Free plan, but after a refresh the site wants me to create a new organisation, and I not see the c...
- JSON and Object Support in Collection do...
I am working with Next.Js and Appwrite Cloud, I am relatively New to Appwrite but i have noticed there is no direct support of JSON and Object support in attrib...
