forked from opensearch-project/OpenSearch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Avoid negative scores returned from multi_match query with cross_fields
Under specific circumstances, when using `cross_fields` scoring on a `multi_match` query, we can end up with negative scores from the inverse document frequency calculation in the BM25 formula. Specifically, the IDF is calculated as: ``` log(1 + (N - n + 0.5) / (n + 0.5)) ``` where `N` is the number of documents containing the field and `n` is the number of documents containing the given term in the field. Obviously, `n` should always be less than or equal to `N`. Unfortunately, `cross_fields` makes up a new value for `n` and tries to use it across all fields. This change finds the minimum (nonzero) value of `N` and uses that as an upper bound for the new value of `n`. Signed-off-by: Michael Froh <[email protected]>
- Loading branch information
Showing
3 changed files
with
38 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
rest-api-spec/src/main/resources/rest-api-spec/test/search/50_multi_match.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
"Cross fields do not return negative scores": | ||
- do: | ||
index: | ||
index: test | ||
id: 1 | ||
body: { "color" : "orange red yellow" } | ||
- do: | ||
index: | ||
index: test | ||
id: 2 | ||
body: { "color": "orange red purple", "shape": "red square" } | ||
- do: | ||
index: | ||
index: test | ||
id: 3 | ||
body: { "color" : "orange red yellow purple" } | ||
- do: | ||
indices.refresh: { } | ||
- do: | ||
search: | ||
index: test | ||
body: | ||
query: | ||
multi_match: | ||
query: "red" | ||
type: "cross_fields" | ||
fields: [ "color", "shape^100"] | ||
tie_breaker: 0.1 | ||
explain: true | ||
- match: { hits.total.value: 3 } | ||
- match: { hits.hits.0._id: "2" } | ||
- gt: { hits.hits.2._score: 0.0 } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters