From 627dfbefdba41839a572086db08b83e9e2dad8b6 Mon Sep 17 00:00:00 2001 From: "byte[]" Date: Sun, 15 Dec 2019 11:19:34 -0500 Subject: [PATCH] be stricter about boolean optimization --- lib/search/parser.ex | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/search/parser.ex b/lib/search/parser.ex index 4601e8e3..96b6cc76 100644 --- a/lib/search/parser.ex +++ b/lib/search/parser.ex @@ -274,19 +274,25 @@ defmodule Search.Parser do end # Flattens the child of a disjunction or conjunction to improve performance. - defp flatten_disjunction_child(this_child, %{bool: %{should: next_child}}), + defp flatten_disjunction_child(this_child, %{bool: %{should: next_child}} = child) + when child == %{bool: %{should: next_child}} and is_list(next_child), do: %{bool: %{should: [this_child | next_child]}} + defp flatten_disjunction_child(this_child, next_child), do: %{bool: %{should: [this_child, next_child]}} - defp flatten_conjunction_child(this_child, %{bool: %{must: next_child}}), + defp flatten_conjunction_child(this_child, %{bool: %{must: next_child}} = child) + when child == %{bool: %{must: next_child}} and is_list(next_child), do: %{bool: %{must: [this_child | next_child]}} + defp flatten_conjunction_child(this_child, next_child), do: %{bool: %{must: [this_child, next_child]}} # Flattens the child of a negation to eliminate double negation. - defp flatten_negation_child(%{bool: %{must_not: next_child}}), + defp flatten_negation_child(%{bool: %{must_not: next_child}} = child) + when child == %{bool: %{must_not: next_child}} and is_map(next_child), do: next_child + defp flatten_negation_child(next_child), do: %{bool: %{must_not: next_child}} -end \ No newline at end of file +end