Continue reading Boosting shorter posts with higher keyword density

Boosting shorter posts with higher keyword density

By default, Relevanssi tends to prefer longer posts. The default TF × IDF weights Relevanssi uses simply count the term frequency, ie. how many times a word appears in the post. That prefers longer posts as they usually have the search term appear more often. However, a 500-word post with 15 search term appearances might…

Read more Boosting shorter posts with higher keyword density 0 Comment on Boosting shorter posts with higher keyword density
Continue reading WooCommerce: Return only exact matches for SKU searches

WooCommerce: Return only exact matches for SKU searches

This little filter function works on relevanssi_hits_filter. When a search query is made that matches an SKU (or any other custom field, but SKUs are the most likely scenario here), only results that match the SKU will be returned. For this to work, Relevanssi must be set to index the _sku custom field (because otherwise,…

Read more WooCommerce: Return only exact matches for SKU searches 1 Comment on WooCommerce: Return only exact matches for SKU searches
Continue reading Partial matches to just one custom field

Partial matches to just one custom field

Is it possible to set (with filters and/or actions/functions) Relevanssi to use whole words keyword matching for post titles and 2 custom fields, and partial keyword matching only for a specific custom field (sku in this case)? Indeed it is! That is, you can’t set different keyword matching methods to different parts of the post,…

Read more Partial matches to just one custom field 0 Comment on Partial matches to just one custom field
Continue reading Restrict search by author from the search query

Restrict search by author from the search query

You can set Relevanssi to index the post author, which will then let you find posts by searching for the name of the author. But what if you want a stricter filter? Where searching for an author would only show posts by that one author and nothing else? That’s possible too. Add this function to…

Read more Restrict search by author from the search query 0 Comment on Restrict search by author from the search query
Continue reading Restricting the search for non-logged-in users

Restricting the search for non-logged-in users

There was an interesting support question: I have website with logged-in users as well as non-logged-in users. The logged-in user should be able to search through everything on the website, but the non-logged-in users should only be able to search the user profiles. Is it at all possible to differentiate the searches like this? The…

Read more Restricting the search for non-logged-in users 3 Comments on Restricting the search for non-logged-in users
Continue reading Using AND and NOT for Boolean operators

Using AND and NOT for Boolean operators

Relevanssi Premium has support for in-query Boolean operators. Relevanssi uses + and – for the operators: cats -dogs and cats +kittens. If you prefer instead to use the verbal AND and NOT operators, it only takes one small function. Add this to your site: This function (on the relevanssi_search_filters hook) looks at the search query…

Read more Using AND and NOT for Boolean operators 6 Comments on Using AND and NOT for Boolean operators
Continue reading Showing only one recurring event

Showing only one recurring event

Some event calendar plugins do recurring events by creating many posts. That’s fine until those cloned posts fill up your search results. This function will only show one of each post with the same title and will take the one with the first date. The date is checked from _EventStartDate custom field, but it’s easy…

Read more Showing only one recurring event 2 Comments on Showing only one recurring event
Continue reading Scroll result page to the search term

Scroll result page to the search term

Relevanssi can highlight search terms on the posts. But how about scrolling the page to show the location where the search results are? That is also possible. It requires a bit of JavaScript on the post page. This script needs to run on the post page: The easiest way is to just add this to…

Read more Scroll result page to the search term 11 Comments on Scroll result page to the search term
Continue reading Category filter for search results pages

Category filter for search results pages

Sometimes it’s nice to have a category filter on the search results pages: a simple dropdown where you can choose the category you want to show. It’s easy to create one using wp_dropdown_categories() but on a search results page, that’s slightly problematic, as it’ll include all categories, not just those included in the search results.…

Read more Category filter for search results pages 33 Comments on Category filter for search results pages
Continue reading Adding extra boost for exact title matches

Adding extra boost for exact title matches

Every now and then, somebody wants to see exact title matches higher in the results. Usually, the best way to do this is to increase the title weight, maybe switch the default operator to AND and let the Relevanssi algorithm lift the best results. If that is not enough, you can use this code to…

Read more Adding extra boost for exact title matches 13 Comments on Adding extra boost for exact title matches