• Resolved polsola

    (@polsola)


    Hello, I think I’m missing something on the configuration for the plugin as I have some issues when searching for numbers

    If you check the link below the search works perfect, but if you search for just 502 I doesn’t return the right products

    I’ve configured the minium word index to 2, and preserved the dashes and rebuilt the index, but I still can get the right searches when typing numbers

    Can you put some light here?

    Thanks!

    The page I need help with: [log in to see the link]

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Mikko Saari

    (@msaari)

    Relevanssi doesn’t search inside words. When the product code is “MVH502AH”, you can find it when you search for “MVH502” or “502AH”, but not just for “502”.

    You have a couple of options here. You can enable inside-word matching by adding this to your theme functions.php:

    add_filter( 'relevanssi_fuzzy_query', 'rlv_match_inside_words' );
    function rlv_match_inside_words( $query ) {
      return "(relevanssi.term LIKE '%#term#%') ";
    }

    Now “502” will find these products. Note that this will increase the number of garbage results in general.

    The other option is to add a filter that would look for product codes in the titles and index “MVH502AH” as “MVH502AH 502”. This would make these products easier to find with just the number.

    Thread Starter polsola

    (@polsola)

    Hello Mikko,

    Thanks a lot, this seems to work pretty well

    If I understand that right if I just one to apply this on a numbers search I only need to do a preg_match with the $query param to apply the LIKE or not right?

    Thanks!

    Plugin Author Mikko Saari

    (@msaari)

    Yes. This should work:

    add_filter( 'relevanssi_fuzzy_query', 'rlv_match_inside_words', 10, 2 );
    function rlv_match_inside_words( $query, $term ) {
      if ( is_numeric( $term ) ) {
        return "(relevanssi.term LIKE '%#term#%') ";
      }
      return $query;
    }
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Problem with searches with numbers’ is closed to new replies.