Continue reading Only return exact title matches if possible

Only return exact title matches if possible

We have posts with titles like “A perfect match”. If a user searches for this exact title, only this post should show up in the results. Otherwise, the search should run as default. There are several approaches to this, but the best is relevanssi_hits_filter. This function goes through all the posts, checks if the post…

Read more Only return exact title matches if possible 0 Comment on Only return exact title matches if possible
Continue reading Search form: Search only in titles

Search form: Search only in titles

If you want to add an option to search only in titles to your search form, here’s how. First, you need to modify the search form to add the selection. To add a simple dropdown, add this to your search form: This select element will create a small dropdown with the option to search everything…

Read more Search form: Search only in titles 0 Comment on Search form: Search only in titles
Continue reading Integrating Koko Analytics stats

Integrating Koko Analytics stats

It’s possible to integrate all kinds of external data to Relevanssi weights. Koko Analytics is a great analytics plugin. It collects stats about your visitors and stores them in the local database, which means those stats are available for Relevanssi. For some sites, this makes a lot of sense. For example, I have Kirjavinkit, a…

Read more Integrating Koko Analytics stats 0 Comment on Integrating Koko Analytics stats
Continue reading How to block searches without a search term

How to block searches without a search term

By default, Relevanssi returns all posts when searching without a search term. That’s the default WordPress behaviour. Sometimes it may not be the wanted behaviour. One reason is performance: returning all results can be very slow. To stop Relevanssi from running when there’s no search term, add this to your site: This little function will…

Read more How to block searches without a search term 2 Comments on How to block searches without a search term
Continue reading Adding a search form in the navigation menu

Adding a search form in the navigation menu

WordPress doesn’t make it easy to add a search form in the navigation menu. It’s a popular request, though, and having access to the search in the site header is typical. Relevanssi itself doesn’t have opinions on the user interface. Some themes come with a built-in search feature in the header, like Twenty Twenty. That’s…

Read more Adding a search form in the navigation menu 0 Comment on Adding a search form in the navigation menu
Continue reading Modifying the search form on the fly

Modifying the search form on the fly

I set up a short coded search box to search my Learndash e-course for one specific category only: [ searchform ld_topic_category=”156″ ] It works perfectly except one thing: if no results show, it takes you to the default WordPress page and presents you with the standard search box that no longer searches category 156. This…

Read more Modifying the search form on the fly 0 Comment on Modifying the search form on the fly
Continue reading Forced phrase search with fallback

Forced phrase search with fallback

Relevanssi by default does not consider the search query a phrase, or value posts where the words in the search query appear together. Sometimes people do expect that, especially in AND searches. Relevanssi however does not have the information about the nearby words, so it’s not possible for Relevanssi to factor that in. Relevanssi does…

Read more Forced phrase search with fallback 0 Comment on Forced phrase search with fallback
Continue reading Multi-part excerpts

Multi-part excerpts

Relevanssi Premium 2.11 introduces a new feature: multi-part excerpts. There’s a new setting on the Excerpts & Highlights settings tab, “Number of excerpt snippets”, and that lets you define the maximum number of excerpt snippets Relevanssi generates for each post. How does it work This option is only available when the excerpt length is defined…

Read more Multi-part excerpts 0 Comment on Multi-part excerpts
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