1
0
Fork 0
forked from OpenNeo/impress

species/zone conditions now render properly, instead of raising parse error from elastic

This commit is contained in:
Emi Matchu 2013-01-21 12:33:26 -06:00
parent 6e09b8bc10
commit 66e0ba28d7
2 changed files with 41 additions and 30 deletions

View file

@ -7,6 +7,15 @@
ANCHORS: ANCHORS:
- &name_locale_partial - &name_locale_partial
"name.<<locale>>^<<boost= 1>>" "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_locales:
*name_locale_partial *name_locale_partial
@ -14,6 +23,24 @@ _name_locales:
_negative_name_locales: _negative_name_locales:
*name_locale_partial *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: item_search:
- query: - query:
bool: bool:
@ -25,21 +52,15 @@ item_search:
is_nc: <<is_nc= ~>> is_nc: <<is_nc= ~>>
- term: - term:
is_pb: <<is_pb= ~>> is_pb: <<is_pb= ~>>
- term: - <<_species_support_ids= ~>>
species_support_id: <<species_support_id= ~>> - <<_occupied_zone_ids= ~>>
- term: - <<_restricted_zone_ids= ~>>
occupied_zone_id: <<occupied_zone_id= ~>>
- term:
restricted_zone_id: <<restricted_zone_id= ~>>
must_not: 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: - multi_match:
query: <<negative_name= ~>> query: <<negative_name= ~>>
fields: <<_negative_name_locales>> fields: <<_negative_name_locales>>
- <<_negative_species_support_ids= ~>>
- <<_negative_occupied_zone_ids= ~>>
- <<_negative_restricted_zone_ids= ~>>
sort: sort:
- name.<<locale>>.untouched - name.<<locale>>.untouched

View file

@ -8,35 +8,25 @@ class Item
end end
def <<(filter) def <<(filter)
if filter.value.respond_to?(:each) if @values[!filter.positive?].include?(filter.value)
filter.value.each do |value| raise Item::Search::Contradiction,
add_value(value, filter.positive?) "positive #{key} and negative #{key} both contain #{filter.value}"
end
else
add_value(filter.value, filter.positive?)
end end
@values[filter.positive?] << filter.value
end end
def to_flex_params def to_flex_params
{ {
key => nil_if_empty(@values[true]), :"_#{key}s" => nil_if_empty(@values[true]),
:"negative_#{key}" => nil_if_empty(@values[false]) :"_negative_#{key}s" => nil_if_empty(@values[false])
} }
end end
private 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) def nil_if_empty(set)
set unless set.empty? set.map { |value| {key => value} } unless set.empty?
end end
end end
end end