diff -Naur vendor/plugins/orig_acts_as_solr/trunk/lib/parser_methods.rb vendor/plugins/acts_as_solr/lib/parser_methods.rb --- vendor/plugins/orig_acts_as_solr/trunk/lib/parser_methods.rb 2007-09-09 00:48:33.000000000 +0530 +++ vendor/plugins/acts_as_solr/lib/parser_methods.rb 2007-09-09 00:04:00.000000000 +0530 @@ -6,7 +6,7 @@ # Method used by mostly all the ClassMethods when doing a search def parse_query(query=nil, options={}, models=nil) - valid_options = [:offset, :limit, :facets, :models, :results_format, :order, :scores, :operator] + valid_options = [:offset, :limit, :facets, :models, :results_format, :order, :scores, :operator, :highlight] query_options = {} return if query.nil? raise "Invalid parameters: #{(options.keys - valid_options).join(',')}" unless (options.keys - valid_options).empty? @@ -41,6 +41,16 @@ order = options[:order].split(/\s*,\s*/).collect{|e| e.gsub(/\s+/,'_t ') }.join(',') if options[:order] query_options[:query] = replace_types([query])[0] # TODO adjust replace_types to work with String or Array + if options[:highlight] + query_options[:highlighting] = {} + query_options[:highlighting][:field_list] = [] + query_options[:highlighting][:field_list] << options[:highlight][:fields].collect {|k| "#{k}_t"} if options[:highlight][:fields] + query_options[:highlighting][:require_field_match] = options[:highlight][:require_field_match] if options[:highlight][:require_field_match] + query_options[:highlighting][:max_snippets] = options[:highlight][:max_snippets] if options[:highlight][:max_snippets] + query_options[:highlighting][:prefix] = options[:highlight][:prefix] if options[:highlight][:prefix] + query_options[:highlighting][:suffix] = options[:highlight][:suffix] if options[:highlight][:suffix] + end + if options[:order] # TODO: set the sort parameter instead of the old ;order. style. query_options[:query] << ';' << replace_types([order], false)[0] @@ -70,9 +80,16 @@ conditions = [ "#{self.table_name}.#{primary_key} in (?)", ids ] result = configuration[:format] == :objects ? reorder(self.find(:all, :conditions => conditions), ids) : ids add_scores(result, solr_data) if configuration[:format] == :objects && options[:scores] - + highlighted = {} + solr_data.highlighting.map do |x,y| + e={} + y1=y.map{|x1,y1| e[x1.gsub(/_[^_]*/,"")]=y1} unless y.nil? + highlighted[x.gsub(/[^:]*:/,"").to_i]=e + end unless solr_data.highlighting.nil? + results.update(:facets => solr_data.data['facet_counts']) if options[:facets] results.update({:docs => result, :total => solr_data.total, :max_score => solr_data.max_score}) + results.update({:highlights=>highlighted}) SearchResults.new(results) end @@ -122,4 +139,4 @@ end end -end \ No newline at end of file +end diff -Naur vendor/plugins/orig_acts_as_solr/trunk/lib/search_results.rb vendor/plugins/acts_as_solr/lib/search_results.rb --- vendor/plugins/orig_acts_as_solr/trunk/lib/search_results.rb 2007-09-09 00:48:33.000000000 +0530 +++ vendor/plugins/acts_as_solr/lib/search_results.rb 2007-09-08 23:56:47.000000000 +0530 @@ -54,6 +54,10 @@ @solr_data[:max_score] end + # Returns the highlighted fields which one has asked for.. + def highlights + @solr_data[:highlights] + end alias docs results alias records results alias num_found total @@ -61,4 +65,4 @@ alias highest_score max_score end -end \ No newline at end of file +end diff -Naur vendor/plugins/orig_acts_as_solr/trunk/lib/solr/response/standard.rb vendor/plugins/acts_as_solr/lib/solr/response/standard.rb --- vendor/plugins/orig_acts_as_solr/trunk/lib/solr/response/standard.rb 2007-09-09 00:48:33.000000000 +0530 +++ vendor/plugins/acts_as_solr/lib/solr/response/standard.rb 2007-09-08 23:33:44.000000000 +0530 @@ -49,6 +49,10 @@ def highlighted(id, field) @data['highlighting'][id.to_s][field.to_s] rescue nil end + + def highlighting + @data['highlighting'] + end # supports enumeration of hits # TODO revisit - should this iterate through *all* hits by re-requesting more?