Struggling with Fuzzy Search

Options
Brandon Hassler
Brandon Hassler Member
edited September 2023 in ? Transforming data

I don't know what I'm doing wrong (or more likely, what I'm missing) when it comes to fuzzy search.

I've got a database full of monitors that users can search. The first issue I was having made me discover that partial match wasn't a default thing. To fix that, my function stack takes the user's query, breaks it into an array, adds a :* to the end of each word, and then re-assembles the query.

So 144 gaming monitor, which would normally return zero results (because my listings are formatted as "144hz"), would be transformed to 144:* gaming:* monitor:* . Yay!

The next (and even more common) problem I'm seeing with user search activity is if the user adds a word that isn't part of the products meta data.

For example, let's say I have a "Samsung Odyssey G51C Monitor" and the user searches "samsung odyssey G51C gaming monitor". Because the user included that extra word "gaming" which isn't part of the product metadata, nothing is returned.

I know there are great services like Algolia & Elasticsearch that can accomplish this and a lot more, but I feel like what I'm wanting to accomplish here is a very simple version of search and I don't currently need the bells and whistles of the other platforms.

It seems like if at least ONE word in their query matches any of my products they should be getting some results. What should I be doing to make this happen?

Answers

  • Ray Deck
    Ray Deck Trusted Xano Expert ✭✭✭
    Options

    Oof. This use case is a good candidate for embedding-based vector search engine (e.g. pinecone, weaviate, etc), but maybe that's a bridge too far for now?

    For the moment, you might try breaking up your search query into an array of words, and try making versions that exclude say one word. So "samsung ultrawide gaming monitor" could become "samsung gaming monitor", "samsung ultrawide monitor", "samsung ultrawide gaming", "ultrawide gaming monitor" and you could do 4 searches, and then combine the results.

    Then you might see that they are asking about a brand, or maybe you give primacy to the first word, both of which would mean you don't do the last search (because it excludes the first word/brand) and so you only have three searches to do.

    Or other solutions! Give yourself permission to try weird things that seem wrong. Keep in mind that Xano is a first-class relational database with a bit of search functionality, not a first-class search engine. So efforts to use it in this direction will be a bit hacky. We try things and see what seems to work good enough.