lib/sunspot/query/fulltext_base_query.rb in benjaminkrause-sunspot-0.9.7 vs lib/sunspot/query/fulltext_base_query.rb in benjaminkrause-sunspot-0.9.8

- old
+ new

@@ -2,17 +2,15 @@ module Query class FulltextBaseQuery < BaseQuery #:nodoc: def initialize(keywords, options, types, setup) super(types, setup) @keywords = keywords + if highlight_options = options.delete(:highlight) - if highlight_options == true - set_highlight - else - set_highlight(highlight_options) - end + set_highlight(highlight_options == true ? [] : highlight_options) end + if fulltext_fields = options.delete(:fields) Array(fulltext_fields).each do |field| add_fulltext_field(field) end end @@ -56,14 +54,20 @@ def create_boost_query(factor) @boost_query ||= BoostQuery.new(factor, @setup) end - def set_highlight(options = {}) - @highlight = Highlighting.new(options) + def set_highlight(field_names=[], options={}) + @highlight = Highlighting.new(text_fields(field_names), options) end private + + def text_fields(field_names) + field_names.inject([]) do |fields, name| + fields.concat(@setup.text_fields(name)) + end + end # # Returns the names of text fields that should be queried in a keyword # search. If specific fields are requested, use those; otherwise use the # union of all fields configured for the types under search.