forked from OpenNeo/impress
update item search to original name-matching behavior
We originally had a regression on name-matching, where, among other issues, `straw hat` returned items containing both "straw" and "hat", which isn't really helpful behavior since we're sorting alphabetically. Now, `straw hat` behaves as expected. Additionally, "phrases like these" behave as expected, too.
This commit is contained in:
parent
04f29c8611
commit
cded361f73
2 changed files with 29 additions and 22 deletions
|
@ -5,8 +5,6 @@
|
|||
# ANCHORS litheral key: it will not be used as template
|
||||
# you can store here fragments of queries to reuse in the templates below
|
||||
ANCHORS:
|
||||
- &name_locale_partial
|
||||
"name.<<locale>>^<<boost= 1>>"
|
||||
- &species_support_id_partial
|
||||
term:
|
||||
species_support_id: <<species_support_id>>
|
||||
|
@ -17,11 +15,17 @@ ANCHORS:
|
|||
terms:
|
||||
restricted_zone_id: <<restricted_zone_id>>
|
||||
|
||||
_name_locales:
|
||||
*name_locale_partial
|
||||
_names:
|
||||
multi_match:
|
||||
query: <<name>>
|
||||
fields: <<fields>>
|
||||
type: phrase
|
||||
|
||||
_negative_name_locales:
|
||||
*name_locale_partial
|
||||
_negative_names:
|
||||
multi_match:
|
||||
query: <<name>>
|
||||
fields: <<fields>>
|
||||
type: phrase
|
||||
|
||||
_species_support_ids:
|
||||
*species_support_id_partial
|
||||
|
@ -45,20 +49,16 @@ item_search:
|
|||
- query:
|
||||
bool:
|
||||
must:
|
||||
- multi_match:
|
||||
query: <<name= ~>>
|
||||
fields: <<_name_locales>>
|
||||
- term:
|
||||
is_nc: <<is_nc= ~>>
|
||||
- term:
|
||||
is_pb: <<is_pb= ~>>
|
||||
- <<_names= ~>>
|
||||
- <<_species_support_ids= ~>>
|
||||
- <<_occupied_zone_ids= ~>>
|
||||
- <<_restricted_zone_ids= ~>>
|
||||
must_not:
|
||||
- multi_match:
|
||||
query: <<negative_name= ~>>
|
||||
fields: <<_negative_name_locales>>
|
||||
- <<_negative_names= ~>>
|
||||
- <<_negative_species_support_ids= ~>>
|
||||
- <<_negative_occupied_zone_ids= ~>>
|
||||
- <<_negative_restricted_zone_ids= ~>>
|
||||
|
|
|
@ -7,7 +7,7 @@ class Item
|
|||
:species_support_id => Fields::SetField,
|
||||
:occupied_zone_id => Fields::SetField,
|
||||
:restricted_zone_id => Fields::SetField,
|
||||
:name => Fields::TextField
|
||||
:name => Fields::SetField
|
||||
}
|
||||
|
||||
def initialize(filters, user)
|
||||
|
@ -42,23 +42,30 @@ class Item
|
|||
I18n.locales_with_neopets_language_code
|
||||
final_flex_params[:locale] = locales.first
|
||||
|
||||
if final_flex_params[:name] || final_flex_params[:negative_name]
|
||||
# Extend the names/negative_names queries with the corresponding
|
||||
# localalized field names.
|
||||
if final_flex_params[:_names] || final_flex_params[:_negative_names]
|
||||
locale_entries = locales.map do |locale|
|
||||
boost = (locale == I18n.locale) ? 4 : 1
|
||||
{:locale => locale, :boost => boost}
|
||||
"name.#{locale}^#{boost}"
|
||||
end
|
||||
|
||||
if final_flex_params[:name]
|
||||
final_flex_params[:_name_locales] = locale_entries
|
||||
end
|
||||
|
||||
if final_flex_params[:negative_name]
|
||||
final_flex_params[:_negative_name_locales] = locale_entries
|
||||
# We *could* have set _name_locales once as a partial, but Flex won't
|
||||
# let us call partials from inside other partials. Whatever. Assign
|
||||
# it to each name entry instead. I also feel bad doing this
|
||||
# afterwards, since it's kinda the field's job to return proper flex
|
||||
# params, but that's a refactor for another day.
|
||||
[:_names, :_negative_names].each do |key|
|
||||
if final_flex_params[key]
|
||||
final_flex_params[key].each do |name_query|
|
||||
name_query[:fields] = locale_entries
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
result = FlexSearch.item_search(final_flex_params)
|
||||
result.scoped_loaded_collection(:scopes => {'Item' => Item.with_translations})
|
||||
result.loaded_collection
|
||||
end
|
||||
|
||||
# Load the text query labels from I18n, so that when we see, say,
|
||||
|
|
Loading…
Reference in a new issue