2018-07-02 17:44:36 -04:00
|
|
|
[[painless-similarity-context]]
|
|
|
|
=== Similarity context
|
|
|
|
|
|
|
|
Use a Painless script to create a
|
2018-07-25 13:59:25 -04:00
|
|
|
{ref}/index-modules-similarity.html[similarity] equation for scoring
|
2018-07-02 17:44:36 -04:00
|
|
|
documents in a query.
|
|
|
|
|
|
|
|
*Variables*
|
|
|
|
|
|
|
|
`params` (`Map`, read-only)::
|
|
|
|
User-defined parameters passed in as part of the query.
|
|
|
|
|
|
|
|
*Variables*
|
|
|
|
|
|
|
|
`params` (`Map`, read-only)::
|
|
|
|
User-defined parameters passed in at query-time.
|
|
|
|
|
2018-12-03 12:34:15 -05:00
|
|
|
`weight` (`float`, read-only)::
|
2018-12-03 15:38:53 -05:00
|
|
|
The weight as calculated by a <<painless-weight-context,weight script>>
|
2018-12-03 12:34:15 -05:00
|
|
|
|
2018-07-02 17:44:36 -04:00
|
|
|
`query.boost` (`float`, read-only)::
|
|
|
|
The boost value if provided by the query. If this is not provided the
|
|
|
|
value is `1.0f`.
|
|
|
|
|
|
|
|
`field.docCount` (`long`, read-only)::
|
|
|
|
The number of documents that have a value for the current field.
|
|
|
|
|
|
|
|
`field.sumDocFreq` (`long`, read-only)::
|
|
|
|
The sum of all terms that exist for the current field. If this is not
|
|
|
|
available the value is `-1`.
|
|
|
|
|
|
|
|
`field.sumTotalTermFreq` (`long`, read-only)::
|
|
|
|
The sum of occurrences in the index for all the terms that exist in the
|
|
|
|
current field. If this is not available the value is `-1`.
|
|
|
|
|
|
|
|
`term.docFreq` (`long`, read-only)::
|
|
|
|
The number of documents that contain the current term in the index.
|
|
|
|
|
|
|
|
`term.totalTermFreq` (`long`, read-only)::
|
|
|
|
The total occurrences of the current term in the index.
|
|
|
|
|
|
|
|
`doc.length` (`long`, read-only)::
|
2018-12-03 12:34:15 -05:00
|
|
|
The number of tokens the current document has in the current field. This
|
2018-12-03 13:25:18 -05:00
|
|
|
is decoded from the stored {ref}/norms.html[norms] and may be approximate for
|
2018-12-03 12:34:15 -05:00
|
|
|
long fields
|
2018-07-02 17:44:36 -04:00
|
|
|
|
|
|
|
`doc.freq` (`long`, read-only)::
|
|
|
|
The number of occurrences of the current term in the current
|
|
|
|
document for the current field.
|
|
|
|
|
2018-12-03 12:34:15 -05:00
|
|
|
Note that the `query`, `field`, and `term` variables are also available to the
|
2018-12-03 15:17:26 -05:00
|
|
|
<<painless-weight-context,weight context>>. They are more efficiently used
|
2018-12-03 12:34:15 -05:00
|
|
|
there, as they are constant for all documents.
|
|
|
|
|
|
|
|
For queries that contain multiple terms, the script is called once for each
|
|
|
|
term with that term's calculated weight, and the results are summed. Note that some
|
|
|
|
terms might have a `doc.freq` value of `0` on a document, for example if a query
|
|
|
|
uses synonyms.
|
|
|
|
|
2018-07-02 17:44:36 -04:00
|
|
|
*Return*
|
|
|
|
|
|
|
|
`double`::
|
|
|
|
The similarity score for the current document.
|
|
|
|
|
|
|
|
*API*
|
|
|
|
|
|
|
|
The standard <<painless-api-reference, Painless API>> is available.
|