All Products
Search
Document Center

:query_term_match_count

Last Updated:Mar 03, 2023

Feature functions

You can use feature functions in sort expressions. Most feature functions can be used only in fine sort expressions. You can combine various syntax and statements to perform complex sorts.

The fields that you reference in the parameters of feature functions must be configured as index fields or attribute fields based on the description of each function.

query_term_match_count: Returns the number of terms in a search query that are hit in a specific field in documents

1. Syntax

query_term_match_count(field_name,index_name)

2. Parameters

  • field_name: optional. The name of the field for which you want to collect statistics. The field must be of the TEXT or SHORT_TEXT type. The analyzer can be the general analyzer for Chinese, a custom analyzer, the single character analyzer for Chinese, an analyzer for English, or the fuzzy analyzer. If you do not specify this parameter, the number of terms that are hit in all fields in documents is returned by default.

  • index_name: optional. The name of the index that is created on the field specified by the field_name parameter.

3. Return value

The return value is of the INT type.

4. Scenarios

Scenario 1: Use if (query_term_match_count(title) > 10, 0.5, 1) to determine how to process data based on the number of terms in a search query that are hit in the title field in documents.

Scenario 2: Use if (query_term_match_count() > 10, 0.5, 1) to determine how to process data based on the number of terms in a search query that are hit in all fields in documents.

5. Usage notes

  • The field that you reference in the parameters of this function must be configured as an index field.

  • You can use this feature function in fine sort expressions.

  • All terms in a search query that are hit in documents are counted. Repeated terms are counted each time they are hit.