diff --git a/app/flex/flex_search.yml b/app/flex/flex_search.yml index 15168564..f8755e6e 100644 --- a/app/flex/flex_search.yml +++ b/app/flex/flex_search.yml @@ -29,6 +29,9 @@ ANCHORS: user_id: <> - term: owned: <> + - &body_id_partial + term: + body_id: <> _names: *name_partial @@ -60,6 +63,12 @@ _user_closet_hanger_ownerships: _negative_user_closet_hanger_ownerships: *user_closet_hangers_ownership_partial +_body_ids: + *body_id_partial + +_negative_body_ids: + *body_id_partial + item_search: - query: bool: @@ -73,11 +82,13 @@ item_search: - <<_occupied_zone_ids= ~>> - <<_restricted_zone_ids= ~>> - <<_user_closet_hanger_ownerships= ~>> + - <<_body_ids= ~>> must_not: - <<_negative_names= ~>> - <<_negative_species_support_ids= ~>> - <<_negative_occupied_zone_ids= ~>> - <<_negative_restricted_zone_ids= ~>> - <<_negative_user_closet_hanger_ownerships= ~>> + - <<_negative_body_ids= ~>> sort: - name.<>.untouched diff --git a/app/models/item.rb b/app/models/item.rb index fe0d602f..68a4e1f7 100644 --- a/app/models/item.rb +++ b/app/models/item.rb @@ -51,6 +51,7 @@ class Item < ActiveRecord::Base :species_support_id => self.supported_species_ids, :occupied_zone_id => self.occupied_zone_ids, :restricted_zone_id => self.restricted_zone_ids, + :body_id => self.modeled_body_ids, :name => {} } diff --git a/app/models/item/search/query.rb b/app/models/item/search/query.rb index b2ca1ef4..21255997 100644 --- a/app/models/item/search/query.rb +++ b/app/models/item/search/query.rb @@ -11,7 +11,8 @@ class Item :occupied_zone_id => Fields::SetField, :restricted_zone_id => Fields::SetField, :name => Fields::SetField, - :user_closet_hanger_ownership => Fields::SetField + :user_closet_hanger_ownership => Fields::SetField, + :body_id => Fields::SetField } FIELD_KEYS = FIELD_CLASSES.keys @@ -93,6 +94,15 @@ class Item end end end + + [:_body_ids, :_negative_body_ids].each do |key| + if final_flex_params[key] + final_flex_params[key].each do |entry| + # These are pet types at first. Yikes, dem hax. + entry[:body_id] = entry[:body_id].body_id + end + end + end result = FlexSearch.item_search(final_flex_params) @@ -159,6 +169,19 @@ class Item Item::Search.error 'not_found.ownership', :keyword => keyword end end + }, + :pet_type => lambda { |keyword| + name1, name2 = keyword.split('-') + [[name1, name2], [name2, name1]].each do |species_name, color_name| + species = Species.find_by_name(species_name) + next if species.nil? + color = Color.find_by_name(color_name) + next if color.nil? + pet_type = PetType.find_by_species_id_and_color_id(species, color) + return pet_type if pet_type.present? + end + Item::Search.error 'not_found.pet_type', + name1: name1.humanize, name2: name2.humanize } } @@ -172,6 +195,9 @@ class Item ownership: lambda { |owned| owned_key = owned ? 'owns' : 'wants' I18n.translate("items.search.labels.user_#{owned_key}") + }, + pet_type: lambda { |pet_type| + "#{pet_type.color.name}-#{pet_type.species.name}" } } @@ -179,7 +205,8 @@ class Item :species_support_id => :species, :occupied_zone_id => :zone, :restricted_zone_id => :zone, - :user_closet_hanger_ownership => :ownership + :user_closet_hanger_ownership => :ownership, + :body_id => :pet_type } TEXT_FILTER_EXPR = /([+-]?)(?:(\p{Word}+):)?(?:"([^"]+)"|(\S+))/ diff --git a/config/locales/en.yml b/config/locales/en.yml index 3f8c63b1..3fc2136c 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -363,6 +363,8 @@ en: ownership: I don't know what user:%{keyword} means. Did you mean user:owns or user:wants? + pet_type: We have no record of the %{name1} %{name2}. + It is spelled correctly? not_logged_in: The "user" filters are only available if you're logged in. flag_keywords: @@ -377,6 +379,7 @@ en: user_closet_hanger_ownership: user user_owns: owns user_wants: wants + body_id: fits neopets_pages: create: