Hello !
I’m very new to Wix and I’ve been stuck on two things for my Search page.
Objective : Have a search bar for user input that searches in several databases/collections at the same time and show all results in one table.
Each database/collection is basically a set list for stickers with the sticker numbers, names type and image. Each database/collection item have the same datapath.
My code below works for one database, it displays everything correctly in the table however the field “setname” doesn’t show for some reason (set name in the collection is a reference from another database listing the basic info of all the sets)
//this code should be in your search page
import wixData from 'wix-data';
$w.onReady(function () {
//TODO: import wixData from 'wix-data';
});
export function search(event) {
wixData.query('Toppu1997')
.or(wixData.query('Amada3'))
.contains('title', $w('#searchinput').value)
.find()
.then(res => {
$w('#resultsTable').rows = res.items;
});
}
$w.onReady(function () {
$w("#resultsTable").columns = [
{
"id": "col1",
"dataPath": "stickernumber",
"label": "Sticker Number",
"width": 100,
"visible": true,
"type": "number"
} ,
{
"id": "col2",
"dataPath": "title",
"label": "Name",
"width": 100,
"visible": true,
"type": "string"
},
{
"id": "col3",
"dataPath": "Stickersetlist.title",
"label": "Set Name",
"width": 100,
"visible": true,
"type": "string"
},
{
"id": "col4",
"dataPath": "manu_year",
"label": "Year",
"width": 80,
"visible": true,
"type": "Number",
} ,
{
"id": "col5",
"dataPath": "type",
"label": "Type",
"width": 100,
"visible": true,
"type": "string",
} ,
{
"id": "col6",
"dataPath": "image",
"label": "Image",
"width": 300,
"visible": true,
"type": "image",
} ,
];
});
I’ve found some other code in the wix forums that allows to search multiple fields in multiple databases, but I can’t seem to find how to display all results stored in the console.log into a table. I don’t know if there’s a way to fuse both of these codes.
import wixData from 'wix-data'
$w.onReady(function () {
$w('#searchButton1').onClick(function () {
wixData.query("firstCollectionName")
.contains("collectionFieldKey1", $w("#searchInput1").value)
.or(wixData.query("firstCollectionName")
.contains("collectionFieldKey2", $w("#searchInput1").value))
.find()
.then((results1) => {
let results1Items = results1.items;
console.log(results1Items);
wixData.query("secondCollectionName")
.contains("collectionFieldKey1", $w("#searchInput1").value)
.find()
.then((results2) => {
let results2Items = results2.items;
console.log(results2Items);
const allResults = results1Items.concat(results2Items);
console.log(allResults);
})
})
})
})
Is my objective possible or is it better to make one giant database with thousands of items to search in ?
Have a great day,
Dominic