From c73f11fbfaa918f045522cd79536bb97ead92608 Mon Sep 17 00:00:00 2001 From: Manuel Wegria Date: Mon, 10 Jun 2024 12:26:26 +0200 Subject: [PATCH] Change negate in complex datation strategy for choice set complex datation --- .../search/complex_datation_strategy.rb | 33 ++++++++++++------- 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/app/models/search/complex_datation_strategy.rb b/app/models/search/complex_datation_strategy.rb index 7a0e8dd02..686489a56 100644 --- a/app/models/search/complex_datation_strategy.rb +++ b/app/models/search/complex_datation_strategy.rb @@ -33,18 +33,27 @@ def search(scope, criteria) negate ) - scope = id_scope.or(search_dates(original_scope, start_date_time, end_date_time, field_condition, negate, true)) - - choice.childrens.each do |c| - start_date_time = JSON.parse(c.from_date) - end_date_time = JSON.parse(c.to_date) - scope = scope.or(search_dates(original_scope, start_date_time, end_date_time, field_condition, negate, true)) + if negate + date_scope = scope.where("#{sql_select_table_name}.data->'#{field.uuid}'->>'selected_format' = 'date_time'") + scope = id_scope.or(date_scope) + else + scope = id_scope.or(search_dates(original_scope, start_date_time, end_date_time, field_condition, negate, true)) + + choice.childrens.each do |c| + start_date_time = JSON.parse(c.from_date) + end_date_time = JSON.parse(c.to_date) + scope = scope.or(search_dates(original_scope, start_date_time, end_date_time, field_condition, negate, true)) + end end scope else id_scope = search_data_matching_more_complex_datation_choice(scope, criteria[:default], negate) - date_scope = search_dates(scope, start_date_time, end_date_time, field_condition, negate, true) + if negate + date_scope = scope.where("#{sql_select_table_name}.data->'#{field.uuid}'->>'selected_format' = 'date_time'") + else + date_scope = search_dates(scope, start_date_time, end_date_time, field_condition, negate, true) + end scope = id_scope.or(date_scope) end return scope @@ -116,7 +125,7 @@ def date_for_keywords(item) raw_value(item) end - def date_from_hash(hash, search_data=[]) + def date_from_hash(hash, search_data = []) search_data << hash["from"].each_with_object([]) { |(_, v), array| array << v if v.present? } if hash.key?("from") search_data << hash["to"].each_with_object([]) { |(_, v), array| array << v if v.present? } if hash.key?("to") end @@ -159,7 +168,7 @@ def inexact_search(scope, date_time, field_condition, negate, is_choice) ( ( ((NOT (#{where_date_is_not_set('to')})) AND (NOT (#{where_date_is_not_set('from')}))) AND ((#{date_time_to_interval(date_time, 'from')} #{sql_operator} #{make_interval(date_time)}) OR (#{date_time_to_interval( - date_time, 'to')} #{sql_operator} #{make_interval(date_time)})) ) OR + date_time, 'to')} #{sql_operator} #{make_interval(date_time)})) ) OR ((#{where_date_is_not_set('to')}) AND (#{date_time_to_interval(date_time, 'from')} #{sql_operator} #{make_interval(date_time)})) OR (#{where_date_is_not_set('from')}))" ) @@ -169,7 +178,7 @@ def inexact_search(scope, date_time, field_condition, negate, is_choice) ( ( ((NOT (#{where_choice_date_is_not_set('to_date')})) AND (NOT (#{where_choice_date_is_not_set('from_date')}))) AND ((#{choice_to_interval(date_time, 'from_date')} #{sql_operator} #{make_interval(date_time)}) OR (#{choice_to_interval( - date_time, 'to_date')} #{sql_operator} #{make_interval(date_time)})) ) OR + date_time, 'to_date')} #{sql_operator} #{make_interval(date_time)})) ) OR ((#{where_choice_date_is_not_set('to_date')}) AND (#{choice_to_interval(date_time, 'from_date')} #{sql_operator} #{make_interval(date_time)})) OR (#{where_choice_date_is_not_set('from_date')}))") ) @@ -179,7 +188,7 @@ def inexact_search(scope, date_time, field_condition, negate, is_choice) "#{sql_select_table_name}.data->'#{field.uuid}'->>'selected_format' = 'date_time' AND ( ((NOT (#{where_date_is_not_set('to')})) AND (NOT (#{where_date_is_not_set('from')}))) AND ((#{date_time_to_interval(date_time, 'from')} #{sql_operator} #{make_interval(date_time)}) OR (#{date_time_to_interval( - date_time, 'to')} #{sql_operator} #{make_interval(date_time)})) OR + date_time, 'to')} #{sql_operator} #{make_interval(date_time)})) OR ((#{where_date_is_not_set('from')}) AND (#{date_time_to_interval(date_time, 'to')} #{sql_operator} #{make_interval(date_time)})) OR (#{where_date_is_not_set('to')}))" ) @@ -189,7 +198,7 @@ def inexact_search(scope, date_time, field_condition, negate, is_choice) ( ( ((NOT (#{where_choice_date_is_not_set('from_date')})) AND (NOT (#{where_choice_date_is_not_set('to_date')}))) AND ((#{choice_to_interval(date_time, 'from_date')} #{sql_operator} #{make_interval(date_time)}) OR (#{choice_to_interval( - date_time, 'to_date')} #{sql_operator} #{make_interval(date_time)})) ) OR + date_time, 'to_date')} #{sql_operator} #{make_interval(date_time)})) ) OR ((#{where_choice_date_is_not_set('from_date')}) AND (#{choice_to_interval(date_time, 'to_date')} #{sql_operator} #{make_interval(date_time)})) OR (#{where_choice_date_is_not_set('to_date')}))") )