Question:
Hello !
I have set a search bar to my website and the base settings are “fuzzy” :
When for example I search “Bastiani” it will show me also articles with “Bastia” and I don’t want that. Is there a way to interfere with theses settings ? Or do I have to made a search bar myself ? (and so do you have tips xD)
Thx !
It is possible to create a search bar using Wix Site Search that allows you to toggle the fuzzy search off.
In order to implement this, you will need to create your own custom search bar using a TextInput element. This is because you cannot use the Search API to control the default Wix Search Bar or Search Results page. You may also need to build a custom search result preview under the search bar using Repeaters if you would like that functionality.
Once you add your custom search bar element, you can use the .fuzzy() method to set the search results to return exact matches.
Example
import wixSearch from 'wix-search';
$w.onReady(function () {
//#searchInput is a TextInput Element representing a custom Wix Search Bar
$w("#searchInput").onKeyPress((keyPress) => {
if (keyPress.key === "Enter") {
const phrase = $w("#searchInput").value;
wixSearch.search(phrase)
.fuzzy(false)
.find()
.then((results) => {
if (results.documents.length > 0) {
let documents = results.documents;
let firstDocument = documents[0];
let facets = results.facets;
let totalCount = results.totalCount;
let pageSize = results.pageSize;
let currentPage = results.currentPage;
let totalPages = results.totalPages;
let hasNext = results.hasNext();
let hasPrev = results.hasPrev();
let length = results.length;
} else {
console.log("No matching results");
}
})
.catch((error) => {
console.log(error);
});
}
});
});