Hi,
I noticed that the current implementation of faceting is instantiating
active record instances without a real need.
For example, when getting the facets for number of rooms when
searching for sunny houses:
House.facets("sunny", :facets => [:rooms]) # results in { :rooms =>
{ 3 => 66, 2 => 33 }}
(So there are 66 3-room houses and 33 2-room houses)
Unfortunately, per facet "result" there is also an House record
fetched from the DB. For attributes that have a lot of different
values, this get's ugly pretty fast, and totally unneeded.
For my project i've created a quick monkey patch that solves this.
Basically i've used the ids_only search, to make sure not instances
are created when doing a search. Because this gives a different search
result, I've changed the way the facet result hash is composed. I
don't have time to fix the specs yet, I plan to do that later.
Enjoy!,
Ward
### Warning: monkey patch ahead ###############
module ThinkingSphinx
class FacetSearch
def facet_search_options
config = ThinkingSphinx::Configuration.instance
max = config.configuration.searchd.max_matches || 1000
options.merge(
:ids_only => true, #otherwise activerecord instances are
created, we don't need those
:group_function => :attr,
:limit => max,
:max_matches => max,
:page => 1
)
end
def add_from_results(facet, results)
results = results.results
name = ThinkingSphinx::Facet.name_for(facet)
self[name] ||= {}
results[:matches].each do |match|
facet_value = match[:attributes][name.to_s]
facet_count = match[:attributes]["@count"]
self[name][facet_value] ||= 0
self[name][facet_value] += facet_count
end
end
end
end
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Thinking Sphinx" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/thinking-sphinx?hl=en
-~----------~----~----~----~------~----~------~--~---