Back

how can I search given string in multiple attribute of a documents and return the matching documents

  • 0
  • Databases
  • General
  • Web
  • Cloud
debashish
18 Feb, 2024, 19:56

how can I search given string in multiple attribute of a documents and return the matching documents. for example I have string "xyz" which could be present in attribute "cityname" or "countryname" . how can I list those documents which contains "xyz" either in "cityname" or "countryname".

Right now I am not able to find a way to find this. Please help.

TL;DR
To search a given string in multiple document attributes, you can create a new attribute to combine all searchable strings, apply a full-text index on that field, and then search it. Appwrite will support "OR" queries in version 1.5 to make this process easier.
Binyamin
18 Feb, 2024, 20:03

As of now there is no direct way of doing so.

Binyamin
18 Feb, 2024, 20:05

What's common is to:

  1. Create another attribute named search
  2. And then, create a function that will get trigger for each time the a document is updated in that collection.
  3. Then, in that field you can concat all the searchable strings separate by empty space.
  4. Apply Full text index on that field
  5. Search that filed and it will search over all the searchable attributes.
debashish
19 Feb, 2024, 13:26

this is a common scenario. i thought there would be direct solution to it.

Guille
19 Feb, 2024, 13:30

Appwrite will add support to "OR" queries in v1.5 and it will be released very soon. It will be possible to do what you're looking without any extra effort

debashish
19 Feb, 2024, 15:47

thats so good to hear

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more