• automaton

    (@automaton)


    I’m preparing a presentation about how site search works on a site I maintain, and how posts are ranked, and for that purpose I am doing some research on Relevanssi, since this is the plugin we use for search.

    I’m a bit puzzled as to how the relevancy score of a post is calculated. I’ve created a test post with a word that is unique for the entire site and then searched for that word. I’ve echoed $post->relevancy_score in the search results to experiment with how I can influence the score by modifying the post.

    A few odd things that I’ve noticed, and for which I didn’t find any info in the knowledge base:

    • When I mention the word once in the body of the article, and search for it, the score of the post is 52.29. Where does this number come from?
    • When I modify the post, without changing the frequency of the word (moving it about, putting it at the top or bottom of the body, etc.), the relevancy score increases by varying amounts. This happens each time I save the post. The increase is not constant, but varies between 1 and 1.6, approximately. I’d love to know why this is.
    • Is there any way of accessing/displaying the inverse document frequency of a term?

    https://wordpress.org/plugins/relevanssi/

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

    (@msaari)

    Relevancy score is calculated based on inverse document frequency (how rare the word is in the whole database) and term frequency (how common the word is in the post). There are some complications to it.

    You can use relevanssi_match filter hook to gain some insight into the process. The first parameter for the filter hook is a match object, which has the post ID ($match->doc) and the term counts for various parts of the post. It also has the relevancy score in $match->weight. The second parameter is the IDF for the term.

    As for the constantly changing values, that’s a weird bug. Relevanssi stores the number of different posts in the database in a WP option. For some reason, every post save action increases that option. At the moment I have no idea what is causing that, but I’ll investigate. What a fiendish little bug, thanks for catching it!

    Plugin Author Mikko Saari

    (@msaari)

    Ok, found the bug and the fix version 3.5.4 is already available.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How are initial weights/relevancy scores determined?’ is closed to new replies.