Hi
Ive been trying to find any way for a search to return results that don’t exactly match the search phrase. For example if my collection contains the result “The big apple” , I would like someone to be able to find it in a search for “The apple”
Im using a lightly modified version of the code from “Corvid by Wix | How to Create a Search for Your Database”
let debounceTimer;
export function Ititle_keyPress(event) { if (debounceTimer) {
$w(“#text8”).scrollTo();
clearTimeout(debounceTimer);
debounceTimer = undefined;
}
debounceTimer = setTimeout(() => {
filter($w(‘#Ititl’).value); if ($w(“#iconButton1”).show);
$w(“#iconButton1”).hide(“FadeIn”) if (event.code === 13){
$w(“#iconButton1”).hide()}
}, 200);
}
//Add your code for this event here: let lastFilterTitle; function filter(title) { if (lastFilterTitle !== title) {
Ive had the idea of using .split(" ") with “if (event code===32)” . I think I can use this with result with hasAll() but i’m stuck at how to get a variable number of list elements into the filter.
I love the infinite scrolling of the code i’m using now, but by this point id be willing to switch to a table with next page buttons to use querys instead of a filter.
like all my problems I think it should be simple but it just keeps getting more complicated…
I appreciate your time!
There’re some available npm you can install and maybe it will help you with fuzzy search (I’ve never tried any of them, so I can’t tell you).
(search for: “search”, and you’ll get some npm’s).
But you’ll need to learn how to use them.
But if you only want to have some matches based on simple rules you can use split(), and hasSome or hasAll depends on what you want.
(I didn’t get your question about the filter. Can you elaborate?
Thanks J.D! That npm looks promising, but if it is possible to stay in the api i’d prefer that option. The filter question was because i thought this ‘fuzzy search’ could only be understood in a query. But if its possible using my current structure that’s perfect, the error i was running into was:
“Failed to build a filter.” “.hasAll field must be a String.”
This is that code
var name_elements = let debounceTimer;
export function Ititl_keyPress(event) { if (debounceTimer) {
$w(“#topTitle”).scrollTo();
clearTimeout(debounceTimer);
debounceTimer = undefined;
" +" was a javascript trick i found for handling more that one space in a row, but I see it does not work here and .split(" ") does! I dont think i need that trick anyways
I would like case insensitivity to be a feature but I just want to see it work at all first, I think i can add this in later
3-6. Thankyou thankyou thankyou!!
Everything looks good in the console now and no errors: [“word1”, “word2”]
0: "word1"1: "word2"length: 2__proto__: Array(0)
But my repeater still isn’t being populated by any results, they all disappear when you type anything into the search bar.
import wixData from “wix-data”; var name_elements = let debounceTimer;
export function Ititl_keyPress(event) { if (debounceTimer) {
$w(“#text8”).scrollTo();
clearTimeout(debounceTimer);
debounceTimer = undefined;
}
debounceTimer = setTimeout(() => {
filter($w(‘#Ititl’).value); if ($w(“#iconButton1”).show);
$w(“#iconButton1”).hide()
if (event.code === 13){
$w(“#iconButton1”).hide()}
}, 200);
} let lastFilterTitle; function filter(title) { if (lastFilterTitle !== title) { //console.log(title)
name_elements = title.split(" ");
$w(‘#dataset1’).setFilter(wixData.filter().hasAll(“thethingname”, name_elements)).then(lastFilterTitle = title, console.log(name_elements));
If i change :
$w(‘#dataset1’).setFilter(wixData.filter().hasAll(“thethingname”, name_elements)).then(lastFilterTitle = title, console.log(name_elements));
to:
$w(‘#dataset1’).setFilter(wixData.filter().contains(“thethingname”, title)).then(lastFilterTitle = title, console.log(name_elements));
then the search still works. So i think i’m still not using hasSome properly, but I dont know what i should be changing.
Thanks again!