How can I create a custom search function in VueJS that allows me to input partial product names and receive relevant results?
For example, I have 2 products named PlayStation Plus 90 Days IE
and PlayStation Plus 90 Days NO
.
Currently, I have to input the full name to find a product, but I want to be able to input just PlayStation 90
and see both products in my search results. How can I achieve this?
I attempted to create a search function using the code snippet below, but it did not work as expected:
computed: {
customSearch() {
return this.result.filter(product => {
return product.text
.toLowerCase()
.includes(this.searchInput.toLowerCase())
})
}
Additionally, I considered splitting the string into an array of keywords like
["PlayStation", "Plus", "90", "Days", "IE"]
and searching based on those keywords, but I am unsure how to implement this. Can someone provide guidance?
Thank you for your assistance!