globalized search first draft
Confirmed features:
* Output (retrieval, sorting, etc.)
* Name (positive and negative, but new behavior)
* Flags (positive and negative)
Planned features:
* users:owns, user:wants
Known issues:
* Sets are broken
* Don't render properly
* Shouldn't actually be done as joined sets, anyway, since
we actually want (set1_zone1 OR set1_zone2) AND
(set2_zone1 OR set2_zone2), which will require breaking
it into multiple terms queries.
* Name has regressed: ignores phrases, doesn't require *all*
words. While we're breaking sets into multiple queries,
maybe we'll do something similar for name. In fact, we
really kinda have to if we're gonna keep sorting by name,
since "straw hat" returns all hats. Eww.
2013-01-18 21:23:37 -08:00
|
|
|
# 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
|
2013-06-26 23:01:12 -07:00
|
|
|
|
|
|
|
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
|
|
|
|
|
globalized search first draft
Confirmed features:
* Output (retrieval, sorting, etc.)
* Name (positive and negative, but new behavior)
* Flags (positive and negative)
Planned features:
* users:owns, user:wants
Known issues:
* Sets are broken
* Don't render properly
* Shouldn't actually be done as joined sets, anyway, since
we actually want (set1_zone1 OR set1_zone2) AND
(set2_zone1 OR set2_zone2), which will require breaking
it into multiple terms queries.
* Name has regressed: ignores phrases, doesn't require *all*
words. While we're breaking sets into multiple queries,
maybe we'll do something similar for name. In fact, we
really kinda have to if we're gonna keep sorting by name,
since "straw hat" returns all hats. Eww.
2013-01-18 21:23:37 -08:00
|
|
|
def scoped_loaded_collection(options)
|
|
|
|
options[:scopes] ||= {}
|
|
|
|
@loaded_collection ||= begin
|
2013-06-26 21:37:12 -07:00
|
|
|
records_by_class_and_id_str = {}
|
2013-06-26 23:01:12 -07:00
|
|
|
grouped_collection = collection.group_by { |d|
|
|
|
|
d.mapped_class(should_raise=true)
|
|
|
|
}
|
|
|
|
grouped_collection.each do |klass, docs|
|
2013-06-26 21:37:12 -07:00
|
|
|
record_ids = docs.map(&:_id)
|
globalized search first draft
Confirmed features:
* Output (retrieval, sorting, etc.)
* Name (positive and negative, but new behavior)
* Flags (positive and negative)
Planned features:
* users:owns, user:wants
Known issues:
* Sets are broken
* Don't render properly
* Shouldn't actually be done as joined sets, anyway, since
we actually want (set1_zone1 OR set1_zone2) AND
(set2_zone1 OR set2_zone2), which will require breaking
it into multiple terms queries.
* Name has regressed: ignores phrases, doesn't require *all*
words. While we're breaking sets into multiple queries,
maybe we'll do something similar for name. In fact, we
really kinda have to if we're gonna keep sorting by name,
since "straw hat" returns all hats. Eww.
2013-01-18 21:23:37 -08:00
|
|
|
scope = options[:scopes][klass.name] || klass.scoped
|
2013-06-26 21:37:12 -07:00
|
|
|
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
|
globalized search first draft
Confirmed features:
* Output (retrieval, sorting, etc.)
* Name (positive and negative, but new behavior)
* Flags (positive and negative)
Planned features:
* users:owns, user:wants
Known issues:
* Sets are broken
* Don't render properly
* Shouldn't actually be done as joined sets, anyway, since
we actually want (set1_zone1 OR set1_zone2) AND
(set2_zone1 OR set2_zone2), which will require breaking
it into multiple terms queries.
* Name has regressed: ignores phrases, doesn't require *all*
words. While we're breaking sets into multiple queries,
maybe we'll do something similar for name. In fact, we
really kinda have to if we're gonna keep sorting by name,
since "straw hat" returns all hats. Eww.
2013-01-18 21:23:37 -08:00
|
|
|
end
|
|
|
|
end
|
2013-06-26 21:37:12 -07:00
|
|
|
|
|
|
|
# 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
|
globalized search first draft
Confirmed features:
* Output (retrieval, sorting, etc.)
* Name (positive and negative, but new behavior)
* Flags (positive and negative)
Planned features:
* users:owns, user:wants
Known issues:
* Sets are broken
* Don't render properly
* Shouldn't actually be done as joined sets, anyway, since
we actually want (set1_zone1 OR set1_zone2) AND
(set2_zone1 OR set2_zone2), which will require breaking
it into multiple terms queries.
* Name has regressed: ignores phrases, doesn't require *all*
words. While we're breaking sets into multiple queries,
maybe we'll do something similar for name. In fact, we
really kinda have to if we're gonna keep sorting by name,
since "straw hat" returns all hats. Eww.
2013-01-18 21:23:37 -08:00
|
|
|
records.extend Flex::Result::Collection
|
|
|
|
records.setup(self['hits']['total'], variables)
|
|
|
|
records
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|