search multiple collections at the same time

key press event in text input
search that text in 3 or more different collections
result will display in table one column with the name of the collection the corresponding the text input matches

collection1 “vegetables” {tomato, green pepper, red pepper, onion}
collection2 “fruits” {green apple, red apple, orange}
collection 3 “green items” {green pepper,green apple, lettuce , broccoli}

user enter search for … green apple for example
result in table will be :
“fruits”
“green items”

list all the groups that an item is belong to

Hello dss,

do you wanna use Data-Collections or Datasets for searching?
I think, you could do it with …

$w("#myDataset").getItems(3, 2)
  .then( (result) => {
    let items = result.items;
    let totalCount = result.totalCount;
    let offset = result.offset;
  } )
  .catch( (err) => {
    let errMsg = err.message;
    let errCode = err.code;
  } );

If you want to use datasets

Or by using Data-Query…

import wixData from 'wix-data';

// ...

wixData.query("myCollection")
  .find()
  .then( (results) => {
    if(results.items.length > 0) {
      let firstItem = results.items[0]; //see item below
    } else {
      // handle case where no matching items found
    }
  } )
  .catch( (err) => {
    let errorMsg = err;
  } );

thanks
this query only for one collection “myCollection” where is the reference to the other collection I need to search ?
where is the table element to display the data ?

You would be much better off by creating one collection with fields for color and type (vegetable, fruit) and then you would just need to query one collection using the filter with color and type .

See the Content examples to see how it’s done.

Or use reference fields in each collection if they’re vastly different.

thanks Israel, but i see you use the multi reference field on each collection where you have to reference each item to be related to the other collection. how can i do that without a multi reference field. just to present a simple search in multiple collection at the same time and the result to be the name of the collection
in this example if you search for “green apple” you get a list stating the groups that it belong (collection 2 and collection 3)

search green apple
result :
collection2
collection3

Hello dss,

perhaps this example here will help you (TEST-FILTER 00004)
https://russian-dima.wixsite.com/meinewebsite