Class: Median::Primo::SearchRequest

Inherits:
Object
  • Object
show all
Defined in:
lib/median/primo/search_request.rb

Constant Summary collapse

PRECISION_OPTIONS =
{contains: 'contains', exact: 'exact', begins_with: 'begins_with'}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ SearchRequest

Returns a new instance of SearchRequest.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/median/primo/search_request.rb', line 5

def initialize(options)
  # set search term
  self.search_term = options[:search_term]
  # set the index field
  self.index_field = options[:index_field]
  # set the precision
  self.precision   = options[:precision]
  # page and page size
  self.page        = options[:page]
  self.page_size   = options[:page_size]
  # set facets
  self.facets      = options[:facets]
  # doc id in case we do a fullview search for a single record
  self.doc_id      = options[:doc_id]
  # search locations
  self.locations   = options[:locations]
end

Instance Attribute Details

#index_fieldObject



31
32
33
# File 'lib/median/primo/search_request.rb', line 31

def index_field
  @index_field || 'any'
end

#locationsObject



78
79
80
# File 'lib/median/primo/search_request.rb', line 78

def locations
  @locations || []
end

#search_termObject



25
26
27
# File 'lib/median/primo/search_request.rb', line 25

def search_term
  @search_term || doc_id
end

Instance Method Details

#doc_idObject



72
73
74
# File 'lib/median/primo/search_request.rb', line 72

def doc_id
  @doc_id
end

#doc_id=(value) ⇒ Object

doc id



68
69
70
# File 'lib/median/primo/search_request.rb', line 68

def doc_id=(value)
  @doc_id = value
end

#facetsObject



96
97
98
# File 'lib/median/primo/search_request.rb', line 96

def facets
  @facets || []
end

#facets=(value) ⇒ Object

Facets



83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/median/primo/search_request.rb', line 83

def facets=(value)
  @facets = []
  value.each do |facet_name, facet_values|
    facet_values.each do |facet_value|
      # create the facet struct
      facet       = OpenStruct.new
      facet.name  = facet_name
      facet.value = facet_value
      @facets << facet
    end if facet_name and facet_values and facet_values.is_a?(Array)
  end if value and value.is_a?(Hash)
end

#include_facet?(name) ⇒ Boolean

Returns:

  • (Boolean)


100
101
102
103
104
105
# File 'lib/median/primo/search_request.rb', line 100

def include_facet?(name)
  facets.each do |f|
    return true if f.name.downcase == name.downcase
  end if name.present?
  false
end

#pageObject



49
50
51
# File 'lib/median/primo/search_request.rb', line 49

def page
  @page || 1
end

#page=(value) ⇒ Object

page



45
46
47
# File 'lib/median/primo/search_request.rb', line 45

def page=(value)
  @page = value.to_i if value.to_i > 0
end

#page_sizeObject



58
59
60
# File 'lib/median/primo/search_request.rb', line 58

def page_size
  @page_size || 25
end

#page_size=(value) ⇒ Object

page size



54
55
56
# File 'lib/median/primo/search_request.rb', line 54

def page_size=(value)
  @page_size = value.to_i if value.to_i > 0
end

#precisionObject



40
41
42
# File 'lib/median/primo/search_request.rb', line 40

def precision
  @precision || PRECISION_OPTIONS[:contains]
end

#precision=(value) ⇒ Object

precision



36
37
38
# File 'lib/median/primo/search_request.rb', line 36

def precision=(value)
  @precision = PRECISION_OPTIONS[value.to_sym] if value.present?
end

#start_indexObject

start index



63
64
65
# File 'lib/median/primo/search_request.rb', line 63

def start_index
  ((page - 1) * page_size) + 1
end

#to_xmlObject

utils



109
110
111
# File 'lib/median/primo/search_request.rb', line 109

def to_xml
  @doc_id.present? ? fullview_request_xml : search_request_xml
end