Search of quality with several words

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?

If the Groupes content collection corresponds to dynamic pages on your website then you can use https://www.wix.com/velo/reference/wix-search/introduction to do a fuzzy search.

Other options/thoughts:

  • Definitely add a debounce delay on the queries so the code doesn’t start a new query for every keypress which can result in a lot of queries
  • When a user does get matches store those and display them in case they typo a later word and get no results. You can then swap to the previous results.
  • Show the groups as dropdowns and filters and let users filter that way instead of a normal search
  • Consider accumulating query results as a user types, deduplicate them, and then do a fuzzy search with the user’s query using an npm library built for fuzzy searching (ex. fuzzy - npm)