Remove flex from the app (breaks search!)
We'll need to replace the item search query stuff with direct MySQL queries, but that's not ready yet bc the app still isn't booting, so we're committing this in a known broken state for now!
This commit is contained in:
parent
1ed973f319
commit
b35c773be3
14 changed files with 1 additions and 346 deletions
5
Gemfile
5
Gemfile
|
@ -52,11 +52,6 @@ gem "http_accept_language", :git => "https://github.com/iain/http_accept_languag
|
||||||
|
|
||||||
gem 'globalize', '~> 4.0.3'
|
gem 'globalize', '~> 4.0.3'
|
||||||
|
|
||||||
# My flex branch fixes a minor pagination bug. Once it's merged into the
|
|
||||||
# original gem, we can switch back.
|
|
||||||
gem "flex", :require => "flex/rails", :git => "https://github.com/matchu/flex.git"
|
|
||||||
gem "patron", "~> 0.4.18"
|
|
||||||
|
|
||||||
gem "rest-client", "~> 1.6.7"
|
gem "rest-client", "~> 1.6.7"
|
||||||
|
|
||||||
gem 'rails-i18n', '~> 4.0', '>= 4.0.9'
|
gem 'rails-i18n', '~> 4.0', '>= 4.0.9'
|
||||||
|
|
18
Gemfile.lock
18
Gemfile.lock
|
@ -4,15 +4,6 @@ GIT
|
||||||
specs:
|
specs:
|
||||||
http_accept_language (2.1.1)
|
http_accept_language (2.1.1)
|
||||||
|
|
||||||
GIT
|
|
||||||
remote: https://github.com/matchu/flex.git
|
|
||||||
revision: 6d7e3fd6e2845ae978545be67b912323888d1ebb
|
|
||||||
specs:
|
|
||||||
flex (0.4.1)
|
|
||||||
multi_json (~> 1.3.4)
|
|
||||||
progressbar (~> 0.11.0)
|
|
||||||
prompter (~> 0.1.5)
|
|
||||||
|
|
||||||
GIT
|
GIT
|
||||||
remote: https://github.com/matchu/neopets.git
|
remote: https://github.com/matchu/neopets.git
|
||||||
revision: 5d13a720b616ba57fbbd54541f3e5daf02b3fedc
|
revision: 5d13a720b616ba57fbbd54541f3e5daf02b3fedc
|
||||||
|
@ -98,7 +89,6 @@ GEM
|
||||||
dotenv-deployment (0.0.2)
|
dotenv-deployment (0.0.2)
|
||||||
dotenv-rails (2.0.1)
|
dotenv-rails (2.0.1)
|
||||||
dotenv (= 2.0.1)
|
dotenv (= 2.0.1)
|
||||||
dye (0.1.4)
|
|
||||||
erubis (2.7.0)
|
erubis (2.7.0)
|
||||||
excon (0.45.4)
|
excon (0.45.4)
|
||||||
execjs (2.5.2)
|
execjs (2.5.2)
|
||||||
|
@ -157,11 +147,6 @@ GEM
|
||||||
orm_adapter (0.5.0)
|
orm_adapter (0.5.0)
|
||||||
parallel (1.13.0)
|
parallel (1.13.0)
|
||||||
passenger_monit (0.1.1)
|
passenger_monit (0.1.1)
|
||||||
patron (0.4.20)
|
|
||||||
progressbar (0.11.0)
|
|
||||||
prompter (0.1.6)
|
|
||||||
dye (>= 0.1.1)
|
|
||||||
yard (>= 0.6.3)
|
|
||||||
rack (1.5.5)
|
rack (1.5.5)
|
||||||
rack-attack (2.2.1)
|
rack-attack (2.2.1)
|
||||||
rack
|
rack
|
||||||
|
@ -272,7 +257,6 @@ GEM
|
||||||
activesupport (>= 2.3.4)
|
activesupport (>= 2.3.4)
|
||||||
chronic (~> 0.6.3)
|
chronic (~> 0.6.3)
|
||||||
will_paginate (3.0.7)
|
will_paginate (3.0.7)
|
||||||
yard (0.9.34)
|
|
||||||
|
|
||||||
PLATFORMS
|
PLATFORMS
|
||||||
ruby
|
ruby
|
||||||
|
@ -289,7 +273,6 @@ DEPENDENCIES
|
||||||
dotenv-deployment
|
dotenv-deployment
|
||||||
dotenv-rails
|
dotenv-rails
|
||||||
factory_girl_rails (~> 1.0)
|
factory_girl_rails (~> 1.0)
|
||||||
flex!
|
|
||||||
fog (~> 1.8.0)
|
fog (~> 1.8.0)
|
||||||
globalize (~> 4.0.3)
|
globalize (~> 4.0.3)
|
||||||
haml (~> 4.0.0)
|
haml (~> 4.0.0)
|
||||||
|
@ -304,7 +287,6 @@ DEPENDENCIES
|
||||||
openneo-auth-signatory (~> 0.1.0)
|
openneo-auth-signatory (~> 0.1.0)
|
||||||
parallel (~> 1.13.0)
|
parallel (~> 1.13.0)
|
||||||
passenger_monit (~> 0.1.1)
|
passenger_monit (~> 0.1.1)
|
||||||
patron (~> 0.4.18)
|
|
||||||
rack-attack (~> 2.2.0)
|
rack-attack (~> 2.2.0)
|
||||||
rails (= 4.0.13)
|
rails (= 4.0.13)
|
||||||
rails-i18n (~> 4.0, >= 4.0.9)
|
rails-i18n (~> 4.0, >= 4.0.9)
|
||||||
|
|
|
@ -1,18 +0,0 @@
|
||||||
# inspect the methods loaded in this module and their usage
|
|
||||||
# in the rails console by just typing:
|
|
||||||
# >> puts FlexSearch.flex.info
|
|
||||||
# you can eventually restrict the info to a single method by pasing its name:
|
|
||||||
# >> puts FlexSearch.flex.info :search
|
|
||||||
# see the detailed doc for this feature at https://github.com/ddnexus/flex/wiki/Selfdoc
|
|
||||||
|
|
||||||
module FlexSearch
|
|
||||||
|
|
||||||
extend self
|
|
||||||
|
|
||||||
include Flex::Loader
|
|
||||||
flex.load_search_source
|
|
||||||
|
|
||||||
# you may need to add more method here, usually wrapper methods
|
|
||||||
# that use one of the autogenerated methods from the loaded templates
|
|
||||||
|
|
||||||
end
|
|
|
@ -1,100 +0,0 @@
|
||||||
# Add here your search queries
|
|
||||||
# see the detailed Source documentation at https://github.com/ddnexus/flex/wiki/Sources
|
|
||||||
|
|
||||||
|
|
||||||
# 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_partial
|
|
||||||
multi_match:
|
|
||||||
query: <<name>>
|
|
||||||
fields: <<fields>>
|
|
||||||
type: phrase
|
|
||||||
- &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>>
|
|
||||||
- &user_closet_hangers_ownership_partial
|
|
||||||
has_child:
|
|
||||||
type: closet_hanger
|
|
||||||
query:
|
|
||||||
bool:
|
|
||||||
must:
|
|
||||||
- term:
|
|
||||||
user_id: <<user_id>>
|
|
||||||
- term:
|
|
||||||
owned: <<user_closet_hanger_ownership>>
|
|
||||||
- &body_id_partial
|
|
||||||
constant_score:
|
|
||||||
filter:
|
|
||||||
or:
|
|
||||||
query:
|
|
||||||
- term:
|
|
||||||
body_id: <<body_id>>
|
|
||||||
- term:
|
|
||||||
body_id: 0
|
|
||||||
|
|
||||||
_names:
|
|
||||||
*name_partial
|
|
||||||
|
|
||||||
_negative_names:
|
|
||||||
*name_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
|
|
||||||
|
|
||||||
_user_closet_hanger_ownerships:
|
|
||||||
*user_closet_hangers_ownership_partial
|
|
||||||
|
|
||||||
_negative_user_closet_hanger_ownerships:
|
|
||||||
*user_closet_hangers_ownership_partial
|
|
||||||
|
|
||||||
_fits_pet_types:
|
|
||||||
*body_id_partial
|
|
||||||
|
|
||||||
_negative_fits_pet_types:
|
|
||||||
*body_id_partial
|
|
||||||
|
|
||||||
item_search:
|
|
||||||
- query:
|
|
||||||
bool:
|
|
||||||
must:
|
|
||||||
- term:
|
|
||||||
is_nc: <<is_nc= ~>>
|
|
||||||
- term:
|
|
||||||
is_pb: <<is_pb= ~>>
|
|
||||||
- <<_names= ~>>
|
|
||||||
- <<_species_support_ids= ~>>
|
|
||||||
- <<_occupied_zone_ids= ~>>
|
|
||||||
- <<_restricted_zone_ids= ~>>
|
|
||||||
- <<_user_closet_hanger_ownerships= ~>>
|
|
||||||
- <<_fits_pet_types= ~>>
|
|
||||||
must_not:
|
|
||||||
- <<_negative_names= ~>>
|
|
||||||
- <<_negative_species_support_ids= ~>>
|
|
||||||
- <<_negative_occupied_zone_ids= ~>>
|
|
||||||
- <<_negative_restricted_zone_ids= ~>>
|
|
||||||
- <<_negative_user_closet_hanger_ownerships= ~>>
|
|
||||||
- <<_negative_fits_pet_types= ~>>
|
|
||||||
sort:
|
|
||||||
- name.<<locale>>.untouched
|
|
|
@ -1,45 +0,0 @@
|
||||||
# see the detailed Extenders documentation at https://github.com/ddnexus/flex/wiki/Extenders
|
|
||||||
|
|
||||||
module FlexSearchExtender
|
|
||||||
|
|
||||||
# set this method to restrict this extender to certain types of results
|
|
||||||
# see the other Flex extenders for reference (https://github.com/ddnexus/flex/tree/master/lib/flex/result)
|
|
||||||
def self.should_extend?(response)
|
|
||||||
true
|
|
||||||
end
|
|
||||||
|
|
||||||
def proxied_collection
|
|
||||||
Item.build_proxies(collection.map(&:_id)).tap do |proxies|
|
|
||||||
proxies.extend Flex::Result::Collection
|
|
||||||
proxies.setup(self['hits']['total'], variables)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def scoped_loaded_collection(options)
|
|
||||||
options[:scopes] ||= {}
|
|
||||||
@loaded_collection ||= begin
|
|
||||||
records_by_class_and_id_str = {}
|
|
||||||
grouped_collection = collection.group_by { |d|
|
|
||||||
d.mapped_class(should_raise=true)
|
|
||||||
}
|
|
||||||
grouped_collection.each do |klass, docs|
|
|
||||||
record_ids = docs.map(&:_id)
|
|
||||||
scope = options[:scopes][klass.name] || klass.scoped
|
|
||||||
records = scope.find(record_ids)
|
|
||||||
records.each do |record|
|
|
||||||
records_by_class_and_id_str[record.class] ||= {}
|
|
||||||
records_by_class_and_id_str[record.class][record.id.to_s] = record
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
# Reorder records to preserve order from search results
|
|
||||||
records = collection.map do |d|
|
|
||||||
records_by_class_and_id_str[d.mapped_class][d._id]
|
|
||||||
end
|
|
||||||
records.extend Flex::Result::Collection
|
|
||||||
records.setup(self['hits']['total'], variables)
|
|
||||||
records
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
|
|
@ -1,6 +1,4 @@
|
||||||
class ClosetHanger < ActiveRecord::Base
|
class ClosetHanger < ActiveRecord::Base
|
||||||
include Flex::Model
|
|
||||||
|
|
||||||
belongs_to :item
|
belongs_to :item
|
||||||
belongs_to :list, :class_name => 'ClosetList'
|
belongs_to :list, :class_name => 'ClosetList'
|
||||||
belongs_to :user
|
belongs_to :user
|
||||||
|
@ -40,29 +38,6 @@ class ClosetHanger < ActiveRecord::Base
|
||||||
|
|
||||||
before_validation :merge_quantities, :set_owned_by_list
|
before_validation :merge_quantities, :set_owned_by_list
|
||||||
|
|
||||||
if Flex::Configuration.hangers_enabled
|
|
||||||
flex.parent :item, 'item' => 'closet_hanger'
|
|
||||||
flex.sync self, callbacks: [:save] # we handle destroy more carefully
|
|
||||||
end
|
|
||||||
|
|
||||||
after_destroy do
|
|
||||||
begin
|
|
||||||
flex.remove
|
|
||||||
rescue Flex::HttpError
|
|
||||||
# This usually means that the record was already dropped from
|
|
||||||
# the search engine. Weird, but okay; if the search engine is
|
|
||||||
# erroneously in the correct state, let it be.
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def flex_source
|
|
||||||
{
|
|
||||||
:user_id => user_id,
|
|
||||||
:item_id => item_id,
|
|
||||||
:owned => owned?
|
|
||||||
}.to_json
|
|
||||||
end
|
|
||||||
|
|
||||||
def possibly_null_closet_list
|
def possibly_null_closet_list
|
||||||
list || user.null_closet_list(owned)
|
list || user.null_closet_list(owned)
|
||||||
end
|
end
|
||||||
|
@ -147,6 +122,7 @@ class ClosetHanger < ActiveRecord::Base
|
||||||
# Find a hanger that conflicts: for the same item, in the same user's
|
# Find a hanger that conflicts: for the same item, in the same user's
|
||||||
# closet, same owned status, same list. It also must not be the current
|
# closet, same owned status, same list. It also must not be the current
|
||||||
# hanger. Select enough for our logic and to update flex_source.
|
# hanger. Select enough for our logic and to update flex_source.
|
||||||
|
# TODO: We deleted flex, does this reduce what data we need here?
|
||||||
conflicting_hanger = self.class.select([:id, :quantity, :user_id, :item_id,
|
conflicting_hanger = self.class.select([:id, :quantity, :user_id, :item_id,
|
||||||
:owned]).
|
:owned]).
|
||||||
where(:user_id => user_id, :item_id => item_id, :owned => owned,
|
where(:user_id => user_id, :item_id => item_id, :owned => owned,
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
class Item < ActiveRecord::Base
|
class Item < ActiveRecord::Base
|
||||||
include Flex::Model
|
|
||||||
include PrettyParam
|
include PrettyParam
|
||||||
|
|
||||||
set_inheritance_column 'inheritance_type' # PHP Impress used "type" to describe category
|
set_inheritance_column 'inheritance_type' # PHP Impress used "type" to describe category
|
||||||
|
@ -41,29 +40,6 @@ class Item < ActiveRecord::Base
|
||||||
|
|
||||||
scope :with_closet_hangers, joins(:closet_hangers)
|
scope :with_closet_hangers, joins(:closet_hangers)
|
||||||
|
|
||||||
# Syncing is now handled in background tasks, created in the ItemObserver.
|
|
||||||
flex.sync self, callbacks: []
|
|
||||||
|
|
||||||
def flex_source
|
|
||||||
indexed_attributes = {
|
|
||||||
:is_nc => self.nc?,
|
|
||||||
:is_pb => self.pb?,
|
|
||||||
: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 => {}
|
|
||||||
}
|
|
||||||
|
|
||||||
I18n.usable_locales_with_neopets_language_code.each do |locale|
|
|
||||||
I18n.with_locale(locale) do
|
|
||||||
indexed_attributes[:name][locale] = self.name
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
indexed_attributes.to_json
|
|
||||||
end
|
|
||||||
|
|
||||||
def closeted?
|
def closeted?
|
||||||
@owned || @wanted
|
@owned || @wanted
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,60 +0,0 @@
|
||||||
# ANCHORS litheral key: it will not be used as template
|
|
||||||
# you can store here fragments of structures to reuse below
|
|
||||||
ANCHORS:
|
|
||||||
-
|
|
||||||
|
|
||||||
# This is a dynamic index name The settings and mapping below will work with any index.
|
|
||||||
# The default index name generated by Flex is usually <application_name>_<environment>,
|
|
||||||
# but you may have changed it in the initializers/flex.rb or you can hardcode it if you prefer.
|
|
||||||
<%= Flex::Configuration.variables[:index] %>:
|
|
||||||
|
|
||||||
settings:
|
|
||||||
number_of_shards: 5
|
|
||||||
number_of_replicas: 1
|
|
||||||
|
|
||||||
analysis:
|
|
||||||
analyzer:
|
|
||||||
item_name_index:
|
|
||||||
type: custom
|
|
||||||
tokenizer: item_name
|
|
||||||
filter:
|
|
||||||
- lowercase
|
|
||||||
- asciifolding
|
|
||||||
|
|
||||||
item_name_search:
|
|
||||||
type: custom
|
|
||||||
tokenizer: keyword
|
|
||||||
filter:
|
|
||||||
- lowercase
|
|
||||||
- asciifolding
|
|
||||||
|
|
||||||
tokenizer:
|
|
||||||
item_name:
|
|
||||||
type: ngram
|
|
||||||
min_gram: 3
|
|
||||||
max_gram: 16
|
|
||||||
|
|
||||||
# add your custom mappings here
|
|
||||||
mappings:
|
|
||||||
item:
|
|
||||||
properties:
|
|
||||||
# Name is an object of locale fields, which are in turn multi_fields.
|
|
||||||
# First, an analyzed string for searching. Second, an untouched
|
|
||||||
# string for sorting. Elasticsearch requires that both be expliticly
|
|
||||||
# named in the mapping, but will handle the copy implicitly.
|
|
||||||
name:
|
|
||||||
type: object
|
|
||||||
properties:
|
|
||||||
<% I18n.usable_locales_with_neopets_language_code.each do |locale| %>
|
|
||||||
<%= locale %>:
|
|
||||||
type: multi_field
|
|
||||||
fields:
|
|
||||||
<%= locale %>:
|
|
||||||
type: string
|
|
||||||
index: analyzed
|
|
||||||
index_analyzer: item_name_index
|
|
||||||
search_analyzer: item_name_search
|
|
||||||
untouched:
|
|
||||||
type: string
|
|
||||||
index: not_analyzed
|
|
||||||
<% end %>
|
|
|
@ -1,51 +0,0 @@
|
||||||
# see the detailed Configuration documentation at https://github.com/ddnexus/flex/wiki/Configuration
|
|
||||||
|
|
||||||
Flex::Configuration.configure do |config|
|
|
||||||
|
|
||||||
# If queries like "user:owns" are too much for the server to handle (not
|
|
||||||
# enough RAM?), set to false to stop indexing closet hangers and disable
|
|
||||||
# item queries that reference them.
|
|
||||||
config.hangers_enabled = true
|
|
||||||
|
|
||||||
# you MUST add your indexed model names here
|
|
||||||
config.flex_models = %w[ Item ]
|
|
||||||
config.flex_models << 'ClosetHanger' if config.hangers_enabled
|
|
||||||
|
|
||||||
|
|
||||||
# Add the your result extenders here
|
|
||||||
config.result_extenders |= [ FlexSearchExtender ]
|
|
||||||
|
|
||||||
# Add the default variables here
|
|
||||||
# see also the details Variables documentation at https://github.com/ddnexus/flex/wiki/Variables
|
|
||||||
# config.variables.add :index => 'my_index',
|
|
||||||
# :type => 'project',
|
|
||||||
# :anything => 'anything
|
|
||||||
|
|
||||||
# The custom url of your ElasticSearch server
|
|
||||||
# config.base_uri = 'http://localhost:9200'
|
|
||||||
|
|
||||||
# Set it to true to log the debug infos (true by default in development mode)
|
|
||||||
# config.debug = false
|
|
||||||
|
|
||||||
# Debug info are actually valid curl commands
|
|
||||||
# config.debug_to_curl = false
|
|
||||||
|
|
||||||
# The custom logger you want Flex to use. Default Rails.logger
|
|
||||||
# config.logger = Logger.new(STDERR)
|
|
||||||
|
|
||||||
# Custom config file path
|
|
||||||
# config.config_file = '/custom/path/to/flex.yml',
|
|
||||||
|
|
||||||
# Custom flex dir path
|
|
||||||
# config.flex_dir = '/custom/path/to/flex',
|
|
||||||
|
|
||||||
# The custom http_client you may want to implement
|
|
||||||
# config.http_client = 'Your::Client'
|
|
||||||
|
|
||||||
# The options passed to the http_client. They are client specific.
|
|
||||||
# config.http_client_options = {:timeout => 5}
|
|
||||||
|
|
||||||
# Experimental: checks the response and return a boolean (should raise?)
|
|
||||||
# config.raise_proc = proc{|response| response.status >= 400}
|
|
||||||
|
|
||||||
end
|
|
BIN
vendor/cache/dye-0.1.4.gem
vendored
BIN
vendor/cache/dye-0.1.4.gem
vendored
Binary file not shown.
BIN
vendor/cache/patron-0.4.20.gem
vendored
BIN
vendor/cache/patron-0.4.20.gem
vendored
Binary file not shown.
BIN
vendor/cache/progressbar-0.11.0.gem
vendored
BIN
vendor/cache/progressbar-0.11.0.gem
vendored
Binary file not shown.
BIN
vendor/cache/prompter-0.1.6.gem
vendored
BIN
vendor/cache/prompter-0.1.6.gem
vendored
Binary file not shown.
BIN
vendor/cache/yard-0.9.34.gem
vendored
BIN
vendor/cache/yard-0.9.34.gem
vendored
Binary file not shown.
Loading…
Reference in a new issue