Inquiry. As a beginner in VueJS and JavaScript, I am currently working on setting up a search bar. While it functions properly, I am facing a challenge. I wish to enable the search functionality to look through an object's description even if the input words are not in the correct sequence.
Illustration. For instance, if the description string is "Gucci blue belt" and I type "Gucci blue" in the search bar, the result displays as expected since the description contains the words in that order. I aim to implement a feature where typing "Gucci belt" will also show the item with the description "Gucci blue belt."
The current computed code in VueJS section
filteredsortedobjects (){
return this.sortedobjects.filter(object => {
var Objectslist_n = object.name;
var Objectslist_q = object.quantity;
var Objectslist_c = object.category;
var Objectslist_s = object.section;
var Objectslist_d = object.description;
var Objectslist_date = object.reception_date;
var Input = this.searchQuery;
/* Create arrays with all information in the table */
var Objectslist_nq = Objectslist_n.concat(Objectslist_q);
var Objectslist_nqc = Objectslist_nq.concat(Objectslist_c);
var Objectslist_nqcs = Objectslist_nqc.concat(Objectslist_s);
var Objectslist_nqcsd = Objectslist_nqcs.concat(Objectslist_d);
var Objectslist_nqcsddate = Objectslist_nqcsd.concat(Objectslist_date);
/* Filtered variables */
var F_Objectslist = RemoveAccents(Objectslist_nqcsddate.toLowerCase());
var F_Input = RemoveAccents(this.searchQuery.toLowerCase());
/* Function to remove accents */
function RemoveAccents(str) {
var accents = 'ÀÁÂÃÄÅàáâãäåÒÓÔÕÕÖØòóôõöøÈÉÊËèéêëðÇçÐÌÍÎÏìíîïÙÚÛÜùúûüÑñŠšŸÿýŽž';
var accentsOut = "AAAAAAaaaaaaOOOOOOOooooooEEEEeeeeeCcDIIIIiiiiUUUUuuuuNnSsYyyZz";
str = str.split('');
var strLen = str.length;
var i, x;
for (i = 0; i < strLen; i++) {
if ((x = accents.indexOf(str[i])) != -1) {
str[i] = accentsOut[x];
}
}
return str.join('');
};
console.log(F_Objectslist);
console.log(F_Input);
return F_Objectslist.includes(F_Input)
})
}
I acknowledge that the accent removal function has not been implemented while conducting tests.
Attempted Approach. To address this concern, I have attempted converting variable F_Input (search bar input) and F_Objectslist (an array containing all item details such as names, categories, sections, quantities, descriptions, and dates) into strings using array.split(" "). This resulted in arrays of strings ["word", "word2", ...] for both variables in the console.
At this stage, I am uncertain about how to verify if the strings within my F_Input array exist in the F_Objectslist array regardless of their order.
Thank you for your assistance!