forked from OpenNeo/impress
species/zone conditions now render properly, instead of raising parse error from elastic
This commit is contained in:
parent
6e09b8bc10
commit
66e0ba28d7
2 changed files with 41 additions and 30 deletions
|
@ -7,6 +7,15 @@
|
|||
ANCHORS:
|
||||
- &name_locale_partial
|
||||
"name.<<locale>>^<<boost= 1>>"
|
||||
- &species_support_id_partial
|
||||
term:
|
||||
species_support_id: <<species_support_id>>
|
||||
- &occupied_zone_id_partial
|
||||
terms:
|
||||
occupied_zone_id: <<occupied_zone_id>>
|
||||
- &restricted_zone_id_partial
|
||||
terms:
|
||||
restricted_zone_id: <<restricted_zone_id>>
|
||||
|
||||
_name_locales:
|
||||
*name_locale_partial
|
||||
|
@ -14,6 +23,24 @@ _name_locales:
|
|||
_negative_name_locales:
|
||||
*name_locale_partial
|
||||
|
||||
_species_support_ids:
|
||||
*species_support_id_partial
|
||||
|
||||
_negative_species_support_ids:
|
||||
*species_support_id_partial
|
||||
|
||||
_occupied_zone_ids:
|
||||
*occupied_zone_id_partial
|
||||
|
||||
_negative_occupied_zone_ids:
|
||||
*occupied_zone_id_partial
|
||||
|
||||
_restricted_zone_ids:
|
||||
*restricted_zone_id_partial
|
||||
|
||||
_negative_restricted_zone_ids:
|
||||
*restricted_zone_id_partial
|
||||
|
||||
item_search:
|
||||
- query:
|
||||
bool:
|
||||
|
@ -25,21 +52,15 @@ item_search:
|
|||
is_nc: <<is_nc= ~>>
|
||||
- term:
|
||||
is_pb: <<is_pb= ~>>
|
||||
- term:
|
||||
species_support_id: <<species_support_id= ~>>
|
||||
- term:
|
||||
occupied_zone_id: <<occupied_zone_id= ~>>
|
||||
- term:
|
||||
restricted_zone_id: <<restricted_zone_id= ~>>
|
||||
- <<_species_support_ids= ~>>
|
||||
- <<_occupied_zone_ids= ~>>
|
||||
- <<_restricted_zone_ids= ~>>
|
||||
must_not:
|
||||
- term:
|
||||
species_support_id: <<negative_species_support_id= ~>>
|
||||
- term:
|
||||
occupied_zone_id: <<negative_occupied_zone_id= ~>>
|
||||
- term:
|
||||
restricted_zone_id: <<negative_restricted_zone_id= ~>>
|
||||
- multi_match:
|
||||
query: <<negative_name= ~>>
|
||||
fields: <<_negative_name_locales>>
|
||||
- <<_negative_species_support_ids= ~>>
|
||||
- <<_negative_occupied_zone_ids= ~>>
|
||||
- <<_negative_restricted_zone_ids= ~>>
|
||||
sort:
|
||||
- name.<<locale>>.untouched
|
||||
|
|
|
@ -8,35 +8,25 @@ class Item
|
|||
end
|
||||
|
||||
def <<(filter)
|
||||
if filter.value.respond_to?(:each)
|
||||
filter.value.each do |value|
|
||||
add_value(value, filter.positive?)
|
||||
end
|
||||
else
|
||||
add_value(filter.value, filter.positive?)
|
||||
if @values[!filter.positive?].include?(filter.value)
|
||||
raise Item::Search::Contradiction,
|
||||
"positive #{key} and negative #{key} both contain #{filter.value}"
|
||||
end
|
||||
|
||||
@values[filter.positive?] << filter.value
|
||||
end
|
||||
|
||||
def to_flex_params
|
||||
{
|
||||
key => nil_if_empty(@values[true]),
|
||||
:"negative_#{key}" => nil_if_empty(@values[false])
|
||||
:"_#{key}s" => nil_if_empty(@values[true]),
|
||||
:"_negative_#{key}s" => nil_if_empty(@values[false])
|
||||
}
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def add_value(value, is_positive)
|
||||
if @values[!is_positive].include?(value)
|
||||
raise Item::Search::Contradiction,
|
||||
"positive #{key} and negative #{key} both contain #{value}"
|
||||
end
|
||||
|
||||
@values[is_positive] << value
|
||||
end
|
||||
|
||||
def nil_if_empty(set)
|
||||
set unless set.empty?
|
||||
set.map { |value| {key => value} } unless set.empty?
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue