Skip to content

Commit

Permalink
Change negate in complex datation strategy for choice set complex dat…
Browse files Browse the repository at this point in the history
…ation
  • Loading branch information
Manuel Wegria committed Jun 10, 2024
1 parent 1bfd94a commit c73f11f
Showing 1 changed file with 21 additions and 12 deletions.
33 changes: 21 additions & 12 deletions app/models/search/complex_datation_strategy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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')}))"
)
Expand All @@ -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')}))")
)
Expand All @@ -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')}))"
)
Expand All @@ -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')}))")
)
Expand Down

0 comments on commit c73f11f

Please sign in to comment.