I just saw this great tutorial: https://m.youtube.com/watch?v=tKgS2e9_ChY
Is there a way to extend the method to match multiple string inputs? For example, I want to search a bunch of book. In my CMS I have the title, author, keywords, genre etc. If I type 'asimov' lIl get all of isaac Asimov's books returned but is the there a way to, say, type 'asimov foundation' and only get returned matches for asimov and foundation across all fields? In the method in the video I believe it would treat the two strings as one and therefore not match anything because the individual strings dont appear together in any field.
Hope that makes sense!
Hi Charles, Thanks for watching the tutorial and sharing your question!
One approach to this would be to split the string into an array of words and query each one individually using a .or() filter. For example:
import wixData from 'wix-data'; //later inside a function let terms = inputString.trim().split(/\s+/); let query = wixData.query("ExampleCollection"); terms.forEach((term, index) => { if (index === 0) { query = query.contains("exampleField", term); } else { query = query.or(wixData.query("ExampleCollection").contains("exampleField", term)); } }); try { let results = await query.find(); return results.items; // Return the found items } catch (error) { console.error("Query failed: ", error); } }
Hope that helps!
Eitan