Hello,
I created a page with a search box and a submit button to display my clients’ companies names. It works well. But the companie’s name are often made up of several words. And if the visitor does not write these words in the right order or incompletely, then the results are not optimal, or incomplete
Here my code velo :
import wixData from 'wix-data';
$w.onReady(function () {
const myCollection = "Groupes";
const button = $w('#searchButton');
const focusTrap = $w('#inputname');
$w("#bandeRepeter").hide();
const search = () => {
let query = $w("#inputname").value;
wixData.query(myCollection)
.contains("clientName", query)
.ascending("clientName")
.limit(6)
.find()
.then((results) => {
$w("#bandeRepeter").show();
console.log(results.items);
$w("#repeater1").data = results.items;
})
.catch((err) => {
console.log(err);
});
}
button.onClick(search);
focusTrap.onKeyPress((event) => {
if (event.key === 'Enter') {
search();
}
});
});
EXAMPLE i have on my “nameClient” : “CISI SCCF Strasbourg” “SCCF CISI Lyon” “CISI SCCF REGION LIMOGES”
IF i search “CISI” all the client are shown
if i search “CISI SNCF” only the clientName in the good orders are shown
if i search “CISI LIMOGES”, i haven’t result because the real name is “CISI SNCF REGION LIMOGES”
I need that the search can show the results again if there are several words on the search and again if the words aren’t on the good order.
then i need to sort this list with “ascending”, in first the results which have more words corresponding.
Can we improve this search, for example by extracting each word from the search and doing a search for each word and comparing each word to the name of the customer’s company?