From dea3bd913c7693d26c446ee6c553c0fc79f1116c Mon Sep 17 00:00:00 2001 From: Liam Date: Thu, 23 May 2024 15:29:16 -0400 Subject: [PATCH] Respect max_clause_count --- lib/philomena/search/parser.ex | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/philomena/search/parser.ex b/lib/philomena/search/parser.ex index aaba8df7..b2f5e47e 100644 --- a/lib/philomena/search/parser.ex +++ b/lib/philomena/search/parser.ex @@ -29,6 +29,8 @@ defmodule Philomena.Search.Parser do __data__: nil ] + @max_clause_count 512 + def parser(options) do parser = struct(Parser, options) @@ -305,14 +307,16 @@ defmodule Philomena.Search.Parser do # Flattens the child of a disjunction or conjunction to improve performance. defp flatten_disjunction_child(this_child, %{bool: %{should: next_child}} = child) - when child == %{bool: %{should: next_child}} and is_list(next_child), + when child == %{bool: %{should: next_child}} and is_list(next_child) and + length(next_child) <= @max_clause_count, 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}} = child) - when child == %{bool: %{must: next_child}} and is_list(next_child), + when child == %{bool: %{must: next_child}} and is_list(next_child) and + length(next_child) <= @max_clause_count, do: %{bool: %{must: [this_child | next_child]}} defp flatten_conjunction_child(this_child, next_child),