ft2_relevancy_algorithm

The ft2_relevancy_algorithm system variable selects the relevance algorithm used by the FULLTEXT2 engine to rank search results. It defaults to BM25 and also accepts TF-IDF. It is distinct from the classic fulltext engine’s ft_relevancy_algorithm.

The ft2_relevancy_algorithm system variable controls how the FULLTEXT2 index engine scores matching documents. BM25 (the default) and TF-IDF are supported. Membership is stable across the two algorithms: the set of documents that match a query does not change, only their relative ranking does.

Syntax

SET SESSION ft2_relevancy_algorithm = ‘TF-IDF’; SET SESSION ft2_relevancy_algorithm = ‘BM25’;

Query the current value:

SHOW VARIABLES LIKE ‘ft2_relevancy_algorithm’; SELECT @@ft2_relevancy_algorithm;

Arguments

Property

Value

Variable Type

string

Scope

Both

Dynamic

Yes

Default Value

BM25

Optional Value

BM25, TF-IDF

Examples

DROP DATABASE IF EXISTS ft2_relevancy_demo;
CREATE DATABASE ft2_relevancy_demo;
USE ft2_relevancy_demo;

SELECT @@ft2_relevancy_algorithm;

SET ft2_relevancy_algorithm = 'TF-IDF';
SELECT @@ft2_relevancy_algorithm;

SET ft2_relevancy_algorithm = 'BM25';

DROP DATABASE ft2_relevancy_demo;

Constraints

  • ft2_relevancy_algorithm applies only to the FULLTEXT2 engine. The classic fulltext engine has its own ft_relevancy_algorithm variable.

  • Changing the algorithm changes document ranking, not the set of matching documents.