• Hi,
    There is a product with the code “TRIDENT”.
    It doesn’t come up when you search for “tr?dent.”

    Since I don’t use “?, ?, ? ..” etc in product codes, can I make “i” instead of “?”?

    Regards

    • This topic was modified 5 years, 5 months ago by doyuk.

    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)

    Yes. The easiest solution is to just convert all cases of “?” to “i” automatically:

    add_filter( 'relevanssi_punctuation_filter', 'rlv_i' );
    function rlv_i( $array ) {
        $array['?'] = 'i';
        return $array;
    }

    Add this to your theme functions.php and rebuild the index, and now “?” and “i” are the same as far as Relevanssi is concerned.

    If you want to make this product code specific, it gets slightly trickier this way (it’d be easier to make “tr?dent” match “trident” than to make “trident” match “trident” and “tr?dent”).

    Thread Starter doyuk

    (@doyuk)

    Dear Mikko,
    Thank you for your support.

    Can I only do this for SKU?

    Best Regards

    Plugin Author Mikko Saari

    (@msaari)

    It gets more complicated, but instead of the other function, use this:

    add_filter( 'relevanssi_custom_field_value', 'rlv_i_customfield', 10, 2 );
    function rlv_i_customfield( $values, $field ) {
        if ( '_sku' !== $field ) return $values;
        $new_values = array();
        foreach ( $values as $value ) {
            $new_value = str_replace( 'i', '?', relevanssi_strtolower( $value ) );
            if ( $new_value !== $value ) {
                $new_values[] = $new_value;
            }
            $new_values[] = $value;
        }
        return $new_values;
    }

    This will index values like “trident” as both “trident” and “tr?dent” for the SKU field.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Search Details’ is closed to new replies.