Back

[SOLVED] can i do `Query.search` with multiple keywords?

  • 0
  • General
  • Databases
  • Web
manazo
11 Dec, 2023, 05:47

As per the doc, we can search only one keyword in an attribute with the Query.search method. but I have an array of keywords, and I want to check if any of the keywords are present in the attribute. how can I do that?

Maybe it'll be a good idea if I explain my scenario a little more. I'm working on a car buying-selling marketplace. so each car has a Model, Engine, Color, Manufacturing year, etc. I wanna implement a search functionality where the user can combine anything they want to search a car. i.e. they can type "Volvo Blue", and the search functionality should return all the Volvo cars with Blue color. so to implement that, I can't query any specific attribute. so, what I'm thinking, is to store all the attribute values in a single attribute, maybe named "search_queries". i.e. if a car schema is

TypeScript
brand: "Volvo"
model: "A3"
color: "Blue"
manufacturing_year: 1998

so the search_queries attribute will look like

TypeScript
search_queries: "Volvo A3 Blue 1998"

so that I can only search the search_queries attribute for any searched keyword. To do that, I need to pass an array of keywords in the Query.search method because the user can type a long string (I'll make an array out of it, separated by Space)

So can you think of any other solution for my issue?

Stack: NextJS@14 Appwrite: Cloud

lmk if u need any further info

TL;DR
The user wants to use the `Query.search` method with multiple keywords but the documentation specifies that only one keyword can be searched at a time. They are looking for a solution to implement a search functionality in a car buying-selling marketplace where users can combine different attributes to search for cars. They suggest storing all attribute values in a single attribute called "search_queries" and searching that attribute for any keyword. They want to know if there are any other solutions to their problem. Solution: The user can pass one string with keywords separated by spaces as a single keyword can be searched at a time using the `Query.search` method.
Drake
11 Dec, 2023, 05:57

Pass one string with keywords separated by spaces

manazo
11 Dec, 2023, 06:48

will it work? won't it consider the whole string as one keyword?

Drake
11 Dec, 2023, 14:15

Yes, it should work. No, it won't be considered one word.

manazo
11 Dec, 2023, 14:45

tried it. and it worked. thanks

manazo
11 Dec, 2023, 14:45

can i do Query.search with multiple keywords? [SOLVED]

Drake
11 Dec, 2023, 15:09

[SOLVED] can i do Query.search with multiple keywords?

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