• Resolved Ryan Sechrest

    (@sovereign)


    When “Keyword matching” is set to “Partial words if no hits for whole words,” and I search for “kim,” it returns people that have “kim” as the first or last name– which is expected.

    If I change “Keyword matching” to “Partial words,” and I search for “kim,” it returns both people named “kim” or “kimberly”– which is also expected.

    That said, it doesn’t seem that it favors “kim” over “kimberly,” and partial matches are interwoven with whole word matches.

    I would think that checking “Give boost to exact matches” would do that, but that may only be for 100% exact matches versus exact word matches.

    Is there a way to list all partial matches after whole word matches?

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

    (@msaari)

    Exact match bonus doesn’t help here, because it just looks at the post title and post content to see if the search phrase appears there. With “kim”, both “Kim” and “Kimberly” are exact matches. This makes more sense when there are two words in the search query, like “kim smith”, in which case “Kim Smith” would get the bonus and “Kimberly Smith” wouldn’t.

    Relevanssi doesn’t separate partial matches from whole word matches in any way, but one way to do it is this:

    add_filter( 'relevanssi_match', 'rlv_prefer_whole_words', 10, 3 );
    function rlv_prefer_whole_words( $match, $idf, $term ) {
        if ( $match->term === $term ) {
            $match->weight *= 1000;
        }
        return $match;
    }

    This will multiply the weights for whole word matches by 1000, which should lift them on top.

    Thread Starter Ryan Sechrest

    (@sovereign)

    Your explanation makes sense and your solution worked beautifully. Thank you!

    I have tried the above code with no luck. We have a custom post type that is being indexed and when testing in the Admin Search Test Area I have a post with the Title “210” but it puts that post mid way through the results and other posts with titles like “417N3310-210” when I search “210”. I have tried adjusting the keyword matching and adding the mentioned code above but can’t get it to work. Thoughts?

    Plugin Author Mikko Saari

    (@msaari)

    Please start a new thread instead of posting to a three-month old thread. In your new thread, please report the relevancy scores for the different posts, how they are measuring up?

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Display partials after whole words in results’ is closed to new replies.