I have a database. I have already added the search feature through code (I will paste the code towards the end for the perusal). Now currently if the search term only gives the results when the exact search word matches with the original database entry.
For instance, if the database entry is “A song of ice and fire” and if we search “ice fire” we will not get the result. However, if we search “ice and fire” we will get the result.
Therefore, I wanted to tweak my code in a way where it can search individual words and give results even if certain words are matching from the search input. Please assist me. I am not very comfortable with coding and cannot understand how to implement this feature in the code.
Here is the code which I already have:
import wixData from ‘wix-data’ ;
//wait until the page is loaded
$w.onReady( function () {
//when the search button is pressed on screen
$w( ‘#searchButton1’ ).onClick((event) => {
//wait until the dataset is fully loaded or else we may be searching a partially loaded dataset
$w( “#dataset1” ).onReady(() => {
//here we call the function called filter and execute it
filter();
//here we detail what the filter function does function filter() {
let searchInput = ($w( ‘#input1’ ).value);
//we console log the search variable for debugging purposes
console.log($w( ‘#input1’ ).value);
I have simplified my codes (after multiple attempts).
However, my problem is still not resolved. I am unable to do searching in the manner as I above described. For instance, if the text says, " M/s Gloob Interior Design Pvt. Ltd. v Mode Finserver Pvt. Ltd." I will only get this result if I type any word or full sentence like “gloob” or “design”, or “gloob interior”. But I won’t get this result, if I search for “gloob design”. How can I get that kind of searching?
We can use stopwords to filter the phrase to keywords. The output will be on a array.
Then use Dataquery.hasany() to get the filtered items from dataset
import wixData from "wix-data"
//wait until the page is loaded
$w.onReady(function () {
//wait until the dataset is fully loaded or else we may be searching a partially loaded dataset
$w("#dataset1").onReady(() => {
$w("#searchButton1").onClick(event => {
filter($w("#input1").value)
})
})
})
function filter(value) {
//Creates an array of words
let searchList = value.split(" ")
//Search for any word inside the array
$w("#dataset1").setFilter(wixData.filter().hasSome("title", searchList))
}