Skip to content

Commit

Permalink
Bulk querying Sphinx for all the facet calls. Not sure how much this …
Browse files Browse the repository at this point in the history
…speeds up facets yet though. Specs need to be updated as well, but features are all green.
  • Loading branch information
pat committed Aug 17, 2010
1 parent 85b8ceb commit a290245
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 4 deletions.
19 changes: 15 additions & 4 deletions lib/thinking_sphinx/facet_search.rb
Expand Up @@ -44,13 +44,24 @@ def set_default_options
end

def populate
facet_names.each do |name|
add_from_results name, ThinkingSphinx.search(
*(args + [facet_search_options(name)])
)
client = config.client

searches.each do |search|
search.append_to client
end

client.run.each_with_index do |results, index|
searches[index].populate_from_queue results
add_from_results facet_names[index], searches[index]
end
end

def searches
@searches ||= facet_names.collect { |name|
ThinkingSphinx.search *(args + [facet_search_options(name)])
}
end

def facet_search_options(facet_name)
options.merge(
:group_function => :attr,
Expand Down
27 changes: 27 additions & 0 deletions lib/thinking_sphinx/search.rb
Expand Up @@ -269,6 +269,29 @@ def search(*args)
self
end

def append_to(client)
prepare client
client.append_query query, indexes, comment
client.reset
end

def populate_from_queue(results)
return if @populated
@populated = true
@results = results

if options[:ids_only]
replace @results[:matches].collect { |match|
match[:attributes]["sphinx_internal_id"]
}
else
replace instances_from_matches
add_excerpter
add_sphinx_attributes
add_matching_fields if client.rank_mode == :fieldmask
end
end

private

def config
Expand Down Expand Up @@ -370,6 +393,10 @@ def log(*args)
def client
client = config.client

prepare client
end

def prepare(client)
index_options = one_class ?
one_class.sphinx_indexes.first.local_options : {}

Expand Down

0 comments on commit a290245

Please sign in to comment.