Relevanssi - A Better Search
Specifying Weight For Individual Pages? (4 posts)

  1. suntower
    Posted 2 years ago #

    Is there a way to force the weighting of certain specific pages?

    IOW: If I have 5 pages with the key word 'toast', I would like to make sure that post->ID 1002 -always- appears first in the result list.

    How can this be done?


  2. Mikko Saari
    Plugin Author

    Posted 2 years ago #

    Using relevanssi_hits_filter filter is the best way - the filter has two parameters: the results and the query. If the query is 'toast', you can make sure the post 1002 is first in the results.

  3. suntower
    Posted 2 years ago #

    Hi Mikko,

    I'm a bit surprised. I thought I'd want to use something like this:

    add_filter('relevanssi_match', 'custom_tag_weights');
    // force a given post ID to top
    if($match->doc == 3246)
      $match->weight = $match->weight * 10;

    ...what's the difference? Or rather, why is relevanssi_hits_filter a better solution?



  4. Mikko Saari
    Plugin Author

    Posted 2 years ago #

    That is a good way, too, but adjusting the weights is just a suggestion, while relevanssi_hits_filter lets you modify the order exactly. Of course, if you give enough extra weight, the post will come on top, but with relevanssi_hits_filter, you can place it first, period.

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Relevanssi - A Better Search
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic