forked from OpenNeo/impress
basic fits functionality in search
This commit is contained in:
parent
acbec2ad5e
commit
0fe31ee79a
4 changed files with 44 additions and 2 deletions
|
@ -29,6 +29,9 @@ ANCHORS:
|
|||
user_id: <<user_id>>
|
||||
- term:
|
||||
owned: <<user_closet_hanger_ownership>>
|
||||
- &body_id_partial
|
||||
term:
|
||||
body_id: <<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.<<locale>>.untouched
|
||||
|
|
|
@ -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 => {}
|
||||
}
|
||||
|
||||
|
|
|
@ -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+))/
|
||||
|
|
|
@ -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:
|
||||
|
|
Loading…
Reference in a new issue