Posted on

Premium 1.7.4

I got a bug notice, which I decided to fix right away. I also added couple of small features while I was at it.

  • Fixed a bug related that caused AND queries containing short search terms to fall back to OR searches.
  • The relevanssi_match filter now gets the IDF as an additional parameter to make recalculating weight easier.
  • Added a very nice related searches feature by John Blackbourn.

This update is recommended to all users of Relevanssi Premium and especially so, if you use AND searches.

Relevanssi_match filter

The filter is now passed another parameter in addition to the $match data. The new variable contains the value of IDF, which is necessary for the TF×IDF calculations. This should make certain weighting modifications easier.

Related searches feature

John Blackbourn wrote a really nice function that displays related searches. He was planning to release it as a separate plugin, but decided to share it with us. It took me a while to get it plugged in, but now it’s a part of Relevanssi Premium.

Here’s what John has to say about the function:

As an exercise for myself a while ago I wrote a ‘related searches’ function for Relevanssi. The idea is you can include a ‘related searches’ list similar to Google’s related searches at the bottom of results. Functionally it works great, but in practice none of the sites I use it on have a high enough volume of searches to return useful suggestions.

The function returns queries from the search log which have at least one matching token with the search query. For example, a search for ‘john’ will match previous searches for ‘john blackbourn’ and ‘john smith’ as they both match ‘john’. A search for ‘john blackbourn’ will match a previous search for ‘john smith’ as at least one token within the search query matches.

A search for ‘john blackbourn’ will not suggest a related search of ‘john’ as the function does not suggest previous searches that only consist of one token. Also, it only returns suggestions which have at least two hits and have been queried at least twice. This maintains the relevance and usefulness of suggestions.

As I said, the functionality will only work well on a site which has plenty of previous search queries logged, and includes searches containing multiple terms. You can see an example where it does work here (scroll to the bottom).

In order to use the related searches, you must have search logging enabled and a good log of past searches. Then add the following code to your search results template in a suitable place:

function_exists( 'relevanssi_related' )
  && relevanssi_related(
    get_search_query(),
    '<h3>Related Searches:</h3><ul><li>',
    '</li><li>',
    '</li></ul>',
    5
  );

The first parameter is the search query and the last parameter is the number of searches to show. The rest are about the display.

By the way — when you link to your search results pages like this, it’s highly recommended to tell Google not to display them. Either put robots meta field in your search results pages header saying “noindex”, or use robots.txt to prevent bots from accessing your search results pages. Instructions can be found at Robotstxt.org.

Leave a Reply

Are you a Relevanssi Premium customer looking for support? Please use the Premium support form.

Your email address will not be published. Required fields are marked *