Method: Sunspot::DSL::Query#fulltext
- Defined in:
- lib/sunspot/dsl/query.rb
#fulltext(keywords, options = {}, &block) ⇒ Object Also known as: keywords
Specify a phrase that should be searched as fulltext. Only text
fields are searched - see DSL::Fields.text
Keyword search is executed using Solr’s dismax handler, which strikes a good balance between powerful and foolproof. In particular, well-matched quotation marks can be used to group phrases, and the + and - modifiers work as expected. All other special Solr boolean syntax is escaped, and mismatched quotes are ignored entirely.
This method can optionally take a block, which is evaluated by the Fulltext DSL class, and exposes several powerful dismax features.
Parameters
- keywords<String>
-
phrase to perform fulltext search on
Options
- :fields<Array>
-
List of fields that should be searched for keywords. Defaults to all fields configured for the types under search.
- :highlight<Boolean,Array>
-
If true, perform keyword highlighting on all searched fields. If an array of field names, perform highlighting on the specified fields. This can also be called from within the fulltext block.
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/sunspot/dsl/query.rb', line 38 def fulltext(keywords, = {}, &block) if keywords && !(keywords.to_s =~ /^\s*$/) fulltext_query = @query.set_fulltext(keywords) if field_names = .delete(:fields) Array(field_names).each do |field_name| @setup.text_fields(field_name).each do |field| fulltext_query.add_fulltext_field(field, field.default_boost) end end end if highlight_field_names = .delete(:highlight) if highlight_field_names == true fulltext_query.set_highlight else highlight_fields = [] Array(highlight_field_names).each do |field_name| highlight_fields.concat(@setup.text_fields(field_name)) end fulltext_query.set_highlight(highlight_fields) end end if block && fulltext_query fulltext_dsl = Fulltext.new(fulltext_query, @setup) Util.instance_eval_or_call( fulltext_dsl, &block ) end if !field_names && (!fulltext_dsl || !fulltext_dsl.fields_added?) @setup.all_text_fields.each do |field| unless fulltext_query.has_fulltext_field?(field) fulltext_query.add_fulltext_field(field, field.default_boost) end end end end end |