Continue reading Removing Relevanssi from the quick edit

Removing Relevanssi from the quick edit

Relevanssi Premium adds Relevanssi tools to post edit pages and in the quick edit box. If you want to disable these, there’s an option to hide both. But what if you want to keep the Relevanssi tools on the edit pages, but want to remove them from the quick edit? The option removes both, but…

Read more Removing Relevanssi from the quick edit 0 Comment on Removing Relevanssi from the quick edit
Continue reading The wrong content gets indexed for a post

The wrong content gets indexed for a post

…wrong post ID. The most typical cause for this problem is when you have a post loop element on a page. This may be a block or a shortcode, but it’s something that loops through posts. When Relevanssi sees this element and indexes it, it runs the loop and in……some cases, the loop will change the post ID Relevanssi thinks it’s indexing. Solutions A simple solution is to exclude the loop element from index. The exact method depends on if it’s a block, a shortcode or something else, but if you exclude it, it won’t confuse Relevanssi anymore. If…

Read more The wrong content gets indexed for a post 0 Comment on The wrong content gets indexed for a post
Continue reading Disable in-page highlights on a specific page

Disable in-page highlights on a specific page

Sometimes there’s a need to disable the in-page highlighting on specific pages. Perhaps the feature works fine on most pages, but some pages have content that is broken by the highlighting. In theory, disabling the feature is very simple: remove the relevanssi_highlight_in_docs filter function from the the_content hook for that page. In practise, getting it…

Read more Disable in-page highlights on a specific page 0 Comment on Disable in-page highlights on a specific page
Continue reading Debugging slow searches

Debugging slow searches

Reasonable expectations for Relevanssi searching speeds are measured in seconds. Relevanssi does not generally return results in milliseconds. On the other hand, the searches shouldn’t take more than few seconds in most cases. Multisite searches are a different thing: even if the searching is reasonably fast, searching across many sites will always be slow. Doing…

Read more Debugging slow searches 0 Comment on Debugging slow searches
Continue reading Indexing term descriptions for posts

Indexing term descriptions for posts

Sometimes it is helpful to have Relevanssi index the taxonomy term descriptions for posts. For example, the term description can be a good place to add alternate search terms for the term. By default, Relevanssi only indexes the term name, so you need extra code to get the term descriptions. The filter hook relevanssi_content_to_index is…

Read more Indexing term descriptions for posts 0 Comment on Indexing term descriptions for posts
Continue reading Problems with highlighting in post content

Problems with highlighting in post content

Versions 2.27.5 (Premium) and 4.24.4 (free) added extra security to highlighting search terms in post content. Before that, an attacker with contributor access could inject malicious content in the posts and the highlighting would then trigger that. This is now fixed, but the fix comes with a cost: the post content is passed through the…

Read more Problems with highlighting in post content 0 Comment on Problems with highlighting in post content
Continue reading Integrating Post Views Counter stats

Integrating Post Views Counter stats

…in the weight calculations is straightforward. The best tool to use is the relevanssi_results filter hook. It lets us modify the weights of the posts. For each post, we calculate a weight multiplier based on the visitor stats and then multiple the weight of the post with that. I add……= 1; } $relevanssi_pvc_weights[ $post_id ] = $weight; } } return $relevanssi_pvc_weights[ $post_id ] ?? 1; } add_filter( ‘relevanssi_results’, ‘rlv_pvc_weights’ ); function rlv_pvc_weights( $post_weights ) { foreach ( $post_weights as $post_id => $weight ) { $post_weights[ $post_id ] = rlv_pvc_weight( intval( $post_id ) ) * $weight; } return $post_weights; }……$relevanssi_pvc_weights[ $post_stats->id ] = $post_stats->count; } $max_visits = max( $relevanssi_pvc_weights ); $factor = $max_visits / 1000; // This controls the normalization. foreach ( $relevanssi_pvc_weights as $post_id => $visits ) { $weight = $visits / $factor; if ( $weight < 1 ) { $weight = 1; } $relevanssi_pvc_weights[ $post_id ] =…

Read more Integrating Post Views Counter stats 0 Comment on Integrating Post Views Counter stats
Continue reading GeneratePress: Query Loop

GeneratePress: Query Loop

Relevanssi doesn’t work automatically with the Query Loop block in GeneratePress and GenerateBlocks. Fortunately, the solution is simple: the Query Loop block has a filter hook for adjusting the query parameters, and you can use that filter hook to enable Relevanssi. Add this to your site: Thanks to Ben Knowles. If you are using V2…

Read more GeneratePress: Query Loop 0 Comment on GeneratePress: Query Loop
Continue reading Year filter from the search query

Year filter from the search query

A good question was asked in the post Natural-language date queries: Is it possible to extend this so that I can simply add a the year in the search and only results from that year would show? The answer is yes! Add these functions to your site: The code consists of two functions. The first…

Read more Year filter from the search query 0 Comment on Year filter from the search query