Skip to content

Commit

Permalink
add option option 'only'.
Browse files Browse the repository at this point in the history
This option works similar to ids_only but for any other fields than id. You can specifiy a string (and receive an array) or an array (and receive a hash).
  • Loading branch information
Hans Hasselberg authored and pat committed Jan 29, 2011
1 parent 53d24d8 commit 4b541ef
Showing 1 changed file with 27 additions and 24 deletions.
51 changes: 27 additions & 24 deletions lib/thinking_sphinx/search.rb
Expand Up @@ -333,13 +333,8 @@ def facets(*args)
options = args.extract_options!
merge_search self, args, options
args << options
<<<<<<< HEAD

ThinkingSphinx::FacetSearch.new *args
=======

ThinkingSphinx::FacetSearch.new(*args)
>>>>>>> 227ce32... enclose some arguments in brackets to avoid ruby ree warnings
end

def client
Expand All @@ -359,16 +354,7 @@ def populate_from_queue(results)
@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
compose_results
end

private
Expand Down Expand Up @@ -400,17 +386,34 @@ def populate
raise ThinkingSphinx::ConnectionError,
'Connection to Sphinx Daemon (searchd) failed.'
end

if options[:ids_only]
replace @results[:matches].collect { |match|

compose_results
end
end

def compose_results
if options[:ids_only] || options[:only]
results = @results[:matches].map do |match|
fuu = if options[:ids_only]
match[:attributes]["sphinx_internal_id"]
}
else
replace instances_from_matches
add_excerpter
add_sphinx_attributes
add_matching_fields if client.rank_mode == :fieldmask
elsif options[:only]
if options[:only].is_a? String
match[:attributes][options[:only]]
elsif options[:only].is_a? Array
{}.tap do |hash|
options[:only].each do |field|
hash[field] = match[:attributes][field]
end
end
end
end
end
replace(results)
else
replace instances_from_matches
add_excerpter
add_sphinx_attributes
add_matching_fields if client.rank_mode == :fieldmask
end
end

Expand Down

0 comments on commit 4b541ef

Please sign in to comment.