- Print
- PDF
Ranking formula
- Print
- PDF
Available in Classic and VPC
You can utilize ranking formulas to sort your search results the way you want. This describes how to create ranking formulas and apply them when searching.
If you do not set a sorting method, it will sort the search results in order of highest document weight (qds).
Ranking formula
A ranking formula is an expression to calculate a ranking score that is the criterion to sort search results. Ranking scores are usually expressed as relevance (_relevance) and calculated as the sum of similarity (_similarity) and quality (_quality).
<Example> Ranking formula of the basic ranking (clous) provided upon creation of domain
_ratio=0.5;
_quality=1.0;
_similarity=qds;
_relevance = _similarity * _ratio + _quality * (1 - _ratio);
You can write your own ranking formula to sort your search results in an order appropriate for each search service.
Writing a ranking formula
The way to write a ranking formula is as follows.
- Use only assignment statements in the form of a single function.
relevance = qds; relevance() = qds; // exactly the same as above. relevance( x ) = x*qds;
- Enter all lines as a string separated by semicolons (;).
- Write using various variables, attribute values, expressions, and built-in functions.
<Example> Example of writing a ranking formularelevance = min(qry_mtc("q1"), qry_mtc("q2")); normalized_qds = qds/qtermc; normalized_qds_of_q1 = qry_qds("q1") / qry_qtermc("q1"); mtratio = mtc/qtermc;
Ranking variables and attribute values
When creating ranking formulas, you can use various attribute values along with ranking variables.
- All variables internally have a type (bool, int, double, string).
- Variables starting with an underscore (_) are reserved for internal use.
Ranking variables
Available ranking variables when creating a ranking formula are as follows.
- A function with document attribute values (
dp_섹션이름
): a ranking variable set when creating a section
<Example> Ranking formula with document attribute values_ratio=0.5; _quality= dp_like_cnt * 0.09 + dp_dislike_cnt * 0.01; _similarity=qds; _relevance = _similarity * _ratio + _quality * (1 - _ratio);
- Define the desired variables
Query property
Available property values of queries when creating a ranking formula are as follows.
qtermc
: the number of search words of a query, the number of added search words (Query-Term-Count) to qdsqry_qtermc(query_name)
: the number of search words of a specific query (query_name), a compound query is used to obtain the number of search words of individual queriesqry_exist(query_name)
: return whether a specific query (query_name) existsepoch_time
: the time at the start of executing a query
Document score
Available property values of documents when creating a ranking formula are as follows.
qds
: document weight, similarity of query document (Query-Document-Score)qry_qds(query_name)
: document weight for a specific query (query_name)mtc
: the number of query terms included in the search target documents (Matched-Term-Count)qry_mtc(query_name)
: the number of query terms included in the search target document for a specific query (query_name) (mtc)
Other
Other available property values when creating a ranking formula are as follows.
total_document_count
: total number of search result documents (estimated)- The total number of documents is subject to change when requests for uploading document are in progress.
Expressions and built-in functions
You can use a variety of expressions and built-in functions when writing ranking formulas.
Expressions
Available expressions when creating a ranking formula are as follows.
- Arithmetic operators:
+
,-
,*
,/
- Comparison operators:
>
,<
,>=
,<=
,==
,!=
- Logical operators:
|
,&
,!
- Constant expressions: integer, real,
true
,false
- Condition expressions:
if - then - else
<Example> Ranking formula written in an expression
mtr = mtc/qtermc;
quality = 1.0;
relevance = if mtr >= 0.6 then qds + quality else quality;
Built-in functions
Available built-in functions when creating a ranking formula are as follows.
min(a, b)
: minimum valuemax(a, b)
: maximum valueexp(x)
: indexlog(x)
: natural logarithmlog10(x)
: logsqrt(x)
: square rootpow(x, y)
: y-square of x
Using ranking formula
You can use the created ranking formula by writing a search query during search as follows.
- If you save the ranking formula in the ranking module
- Specifies the ranking module to use in the
ranking
field - Specifies the ranking variable calculated in the ranking formula as a parameter of the
sort
field- If you set the ranking module to the default, you are not required to set up the
ranking
field.
- If you set the ranking module to the default, you are not required to set up the
- Specifies the ranking module to use in the
- If you enter a ranking formula directly into your search query
- Enter the ranking formula directly in the
ranking
field - Specifies the ranking variable calculated in the ranking formula as a parameter of the
sort
field
- Enter the ranking formula directly in the
- For how to create a ranking module and set the default ranking, see Ranking formula.
- For how to write the
ranking
andsort
field, see ranking and sort.
<Example> Search query that specifies the ranking variable (relevance) of the basic ranking as a sort
field parameter
{
"search": {
"index_name": {
"main": [
{
"name": "q1",
"query": "term"
},
{
"name": "q2",
"query": "test"
}
]
}
},
"sort" : {
"relevance": "desc"
}
}