relevanssi_df_query_filter

apply_filters( 'relevanssi_df_query_filter', string $query )

Filters the MySQL query used to calculate the document frequency (df).

Parameters

$query
(string) The MySQL query used to calculate the df value.

More information

Relevanssi uses the tf × idf formula for counting the weight for each search term and post. The idf stands for inverse document frequency and Relevanssi does a query for each search term to calculate the document frequency, ie. how many documents in the database have this term.

This query looks something like this:

SELECT COUNT(DISTINCT(relevanssi.doc))
FROM wp_relevanssi AS relevanssi
WHERE (relevanssi.term LIKE 'gastro%'
OR relevanssi.term_reverse LIKE CONCAT(REVERSE('gastro'), '%'))
AND ((relevanssi.doc IN (SELECT DISTINCT(posts.ID)
FROM wp_posts AS posts
WHERE posts.post_type NOT IN ('revision', 'nav_menu_item', 'custom_css', 'customize_changeset', 'oembed_cache', 'user_request', 'wp_block', 'um_form', 'um_directory', 'acf-field-group', 'acf-field', 'tablepress_table', 'book')))
OR (doc = -1))

The unique part here is the COUNT(DISTINCT(relevanssi.doc)) to make this a query to count the number of documents.

Modifying this query is rarely necessary, but if you do changes in the main searching query with relevanssi_query_filter, the same changes should be done here as well so that the queries match.

Most of the time the changes are made using the relevanssi_fuzzy_query, which is applied in both cases anyway.