Search with a single character or fuzzy search?

I’m building a small website to buy some kids clothes. Overall the search works great except, I’d like to search for the size of a product with just a single character or a fuzzy search to ensure I get all similar sizes back.

Example…

  • Product A – 5/6T
  • Product B – 5T
  • Product C – 6T

I want to get Product A and Product B

  • If I search “5” I get No Results.
  • If I search “5T” I get Product B.

I want to get Product A and Product C

  • If I search “6” I get No Results.
  • If I search “6T” I get Product A and Product C.

So my questions are…

  1. Is it possible to search with a single character some how?
  2. If not, how might I implement a fuzzy search so that a search for 5T will pull back Product A and Product B?
  3. Or, do you have a suggestion on how to better structure my size field?

Thanks!

The minlength parameter’s default is 2 characters, so you would have to pass 1 in the options array to be able to search for a single character match.

But maybe you should change something like 5/6T to 5T/6T, because otherwise a search for 5T would not surface that item.

1 Like

@texnixe That worked perfectly! Thanks!

I’m curious though, why aren’t the options for that method not shown on the cheatsheet? Did you just look up the method in pages class?

I knew there was a parameter like that, but I checked the source code for the default setting.

Yes, you are right, the documentation is not very complete :thinking:.