From ba900f4ad6a61d854e203af0ba0bb085e6d3b506 Mon Sep 17 00:00:00 2001 From: "byte[]" Date: Thu, 18 Mar 2021 01:29:21 -0400 Subject: [PATCH] boost values must be non-negative since ES7 (bm25 forbids negative scores) --- lib/philomena/search/parser.ex | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/philomena/search/parser.ex b/lib/philomena/search/parser.ex index 00bbed6a..f89290ee 100644 --- a/lib/philomena/search/parser.ex +++ b/lib/philomena/search/parser.ex @@ -107,9 +107,12 @@ defmodule Philomena.Search.Parser do defp search_boost(parser, tokens) do case search_not(parser, tokens) do - {:ok, {child, [{:boost, value} | r_tokens]}} -> + {:ok, {child, [{:boost, value} | r_tokens]}} when value >= 0 -> {:ok, {%{function_score: %{query: child, boost: value}}, r_tokens}} + {:ok, {_child, [{:boost, _value} | _r_tokens]}} -> + {:error, "Boost value must be non-negative."} + value -> value end