Permalink
Browse files

add option option 'only'.

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...
1 parent 53d24d8 commit 4b541efd666e4e09e5bf8e0ad5071b76f6de2b90 Hans Hasselberg committed with pat Jan 27, 2011
Showing with 27 additions and 24 deletions.
  1. +27 −24 lib/thinking_sphinx/search.rb
@@ -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
@@ -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
@@ -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

0 comments on commit 4b541ef

Please sign in to comment.