relevanssi_count_term_occurrances()

relevanssi_count_term_occurrances( string $query, string $mode = 'array' )

This function displays how many times each search term in the query appears in the database.

Source: /lib/utils.php

Parameters

$query
(string) The search query. From get_search_query(), for example.

$mode
(string) The return value mode. The default value is “array” for an array of term => count pairs; the value can also be “string” for a string representation that you can directly echo out.

Usage

This function counts how many times each word in the search query appears in the Relevanssi index. The function does not count posts; the return value is how many times the word appears in all documents. If a word appears two times in one post and six times in another post, this function will return eight.

If you use the “string” mode, the function will return a string with all the search terms and the count for each in a list ready to echo. Terms and counts are wrapped in span tags to help style the output. The “array” mode gives you an array where the terms are the keys, and the counts are the values.