Hi everyone,
I have created this search bar that works pretty well for what I need it for(searching by separate words), however, to make it helpful and functional to visitors, I would need to sort results by most matches, so that more adequate results appear at the top of my repeater, I appreciate any help you can give me.
I attach pictures of my code ( for the search results page) and site so that you can get a better view of everything. (It seems long, but it is just basically the same thing repeated over and over)
Thanks a million!
import wixData from ‘wix-data’;
import wixLocation from ‘wix-location’;
export function box1_viewportEnter() {
wixLocation.to(“/search-results”);
let searchValue = $w(‘#input1’).value;
let searchWords = searchValue.split(’ ');
let query = wixData.query(‘alloperations’)
.contains(‘keywords’, searchWords[0]);
for (let i = 1; i < searchWords.length; i++) {
query = query.or(wixData.query('alloperations')
.contains('keywords', searchWords[i]));
}
query.find()
.then(res => {
$w('#repeater2').data = res.items;
setTimeout(() => {
$w("#input1").value = null;
}, 200000);
let text = $w('#input1').value;
$w("#text18").text = text;
setTimeout(() => {
$w('#repeater2').show();
$w("#text18").show();
}, 500);
setTimeout(() => {
$w("#text19").show();
}, 900);
});
}
export function button3_click() {
wixLocation.to(“/search-results”);
let searchValue = $w(‘#input1’).value;
let searchWords = searchValue.split(’ ');
let query = wixData.query(‘alloperations’)
.contains(‘keywords’, searchWords[0]);
for (let i = 1; i < searchWords.length; i++) {
query = query.or(wixData.query('alloperations')
.contains('keywords', searchWords[i]));
}
query.find()
.then(res => {
$w('#repeater2').data = res.items;
setTimeout(() => {
$w("#input1").value = null;
}, 200000);
let text = $w('#input1').value;
$w("#text18").text = text;
setTimeout(() => {
$w('#repeater2').show();
$w("#text18").show();
}, 500);
setTimeout(() => {
$w("#text19").show();
}, 900);
});
}
export function input1_keyPress(event) {
if (event.key === “Enter”) {
wixLocation.to(“/search-results”);
let searchValue = $w(‘#input1’).value;
let searchWords = searchValue.split(’ ');
let query = wixData.query(‘alloperations’)
.contains(‘keywords’, searchWords[0]);
for (let i = 1; i < searchWords.length; i++) {
query = query.or(wixData.query('alloperations')
.contains('keywords', searchWords[i]));
}
query.find()
.then(res => {
$w('#repeater2').data = res.items;
setTimeout(() => {
$w("#input1").value = null;
}, 20000);
let text = $w('#input1').value;
$w("#text18").text = text;
setTimeout(() => {
$w('#repeater2').show();
$w("#text18").show();
}, 500);
setTimeout(() => {
$w("#text19").show();
}, 900);
});
}
}