Class: Sunspot::Query::Highlighting

Inherits:
Object
  • Object
show all
Defined in:
sunspot/lib/sunspot/query/highlighting.rb

Overview

A query component that builds parameters for requesting highlights

Instance Method Summary (collapse)

Constructor Details

- (Highlighting) initialize(fields = [], options = {})

:nodoc:



7
8
9
10
# File 'sunspot/lib/sunspot/query/highlighting.rb', line 7

def initialize(fields=[], options={})
  @fields  = fields
  @options = options
end

Instance Method Details

- (Object) to_params

Return Solr highlighting params



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'sunspot/lib/sunspot/query/highlighting.rb', line 15

def to_params
  params = {
    :hl => 'on',
    :hl.simple.pre" => '@@@hl@@@',
    :hl.simple.post" => '@@@endhl@@@'
  }
  unless @fields.empty?
    params[:hl.fl"] = @fields.map { |field| field.indexed_name }
  end
  if max_snippets = @options[:max_snippets]
    params.merge!(make_params('snippets', max_snippets))
  end
  if fragment_size = @options[:fragment_size]
    params.merge!(make_params('fragsize', fragment_size))
  end
  if @options[:merge_contiguous_fragments]
    params.merge!(make_params('mergeContiguous', 'true'))
  end
  if @options[:phrase_highlighter]
    params.merge!(make_params('usePhraseHighlighter', 'true'))
    if @options[:require_field_match]
      params.merge!(make_params('requireFieldMatch', 'true'))
    end
  end
  if formatter = @options[:formatter]
    params.merge!(make_params('formatter', formatter))
  end
  if fragmenter = @options[:fragmenter]
    params.merge!(make_params('fragmenter', fragmenter))
  end

  params
end