Multiple databases search and merge results on the same page? How to do it. Sample code request - Databases have the same columns.

Hi;

I have several databases of the same structure and format.

For example;

  • Germany collection
  • France Collection
  • Italy Collection.

Is it possible to make the word entered in a single search bar as a common search page for all? how can I do it. Can you send a sample code. This will be very useful to me.

Since the databases are all in the same format, it should be easy to search, all I want is to search the same word with a single search bar and show the results in one repeater.

Multiple databases search and merge results on the same page? How to do it. Sample code request - Databases have the same columns.

#database #search #different #repeater #searchall code

There may be better, faster ways, but right now that’s what comes to mind. Hope it works for you.

export async function input1_change(event) {
 let data1 = await wixData.query("Germany")
        .eq("city", $w('#input1').value)
        .find();
let data2=  data1.items;
 let data3 = await wixData.query("France")
        .eq("city", $w('#input1').value)
        .find();
 let data4=  data3.items;
let data5 = [...data2, ...data4];
    $w('#repeater1').data = data5;
}


//This is how you define the data

export function repeater1_itemReady($item, itemData, index) {
    $item("#textcity").text = itemData.city;
    
  //  It defines only one field called a city.
//If you have any other fields or pictures you will add here accordingly.
}






@Umut If this has helped you, you may want to mark the answer as helpful, helping other users.

Hi; firstly many thanks for the answer
Of course I will share the positive result. But I have one last question. How do I make the display link in the repeater. Do I need to link it to a collection?

To connect the data to the compiler you need to use the code.
You need to use the code tool. properties
I’ve extended the code above to you. See.
https://www.wix.com/corvid/reference/$w.Repeater.html#data

Wonderful; This will help me a lot. Thanks again

So finally I have a question. In order for the results of the data to come quickly, would it be possible to have 10 pieces of 10 pieces piece by piece? If so, how to add the sample code you send.

What do you mean by limiting the number of results in a query?
limit(10)
You do so:

  .eq("city", $w('#input1').value)
       .limit(10)
         .find();


You do not need some repeaters now
It puts you all the results from all the databases into one repiter

why can’t I see the results? where am i wrong, repeater and results are not linked to any database

import wixData from ‘wix-data’ ;

export async function input1_change(event) {

let data1 = await wixData.query( “Germany” )
.eq( “overview” , $w( ‘#input1’ ).value)
.find();
let data2= data1.items;
let data3 = await wixData.query( “SouthAfrica” )
.eq( “overview” , $w( ‘#input1’ ).value)
.find();

let data4 = [data1, data2, data3];
$w( ‘#repeater1’ ).data = data4;

}

export function repeater1_itemReady($item, itemData, index) {
$item( “#text60” ).text = itemData.overview;
$item( “#text59” ).text = itemData.country;

// It defines only one field called a city.
//If you have any other fields or pictures you will add here accordingly.
}

I think you’re wrong here, it’s different than what I suggested.

let data4 = [data1, data2, data3];

It should be like this:


let data4 = data3.items;
let data5 = [... data2, ... data4];
let data4 = data3.items;
let data5 = [... data2, ... data4];

Note that the search will only take place after you finish entering the input field, this is a function that works after the information is finished
You can use the search time in the function
$ w (“# myElement”). onInput ((event) => {
let newValue = event.target.value; "
});

But I would not recommend you because it will slow down your writing, because it executes complex code, it is better that you add a button that presses the filter. Or you can do it by checking ‘Enter’

You can add a button instead, and do the search

Sorry, but I do not fully understand this part. How to do it logically. Can you edit and add for me.

there are two collections: Germany and SouthAfrica
both are looking for the same column: overview

let data1 = await wixData.query( “Germany” )
.eq( “overview” , $w( ‘#input1’ ).value)
.find();
let data2= data1.items;
let data3 = await wixData.query( “SouthAfrica” )
.eq( “overview” , $w( ‘#input1’ ).value)
.find();

let data1 = data1.items;
let data5 = [… data2, … data4];
let data4 = data3.items;
let data5 = [… data2, … data4];

}

export async function input1_change(event) {
 let data1 = await wixData.query("Germany")
        .eq("overview", $w('#input1').value)
        .find();
       let data2=  data1.items;
       
        let data3 = await wixData.query("SouthAfrica")
         .eq("overview", $w('#input1').value)
        .find();
 let data4=  data3.items;
 
let data5 = [...data2, ...data4];
    $w('#repeater1').data = data5;
}

Hi;
I did not understand how to list the search results in the repeater.

But thank you very much for your sharing. I don’t want to ask more questions and take your time.

I will try to find it by researching and trying a little more.