Class: Median::Primo::SearchRequest
- Inherits:
-
Object
- Object
- Median::Primo::SearchRequest
- 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
- #doc_id ⇒ Object
-
#doc_id=(value) ⇒ Object
doc id.
- #facets ⇒ Object
-
#facets=(value) ⇒ Object
Facets.
- #include_facet?(name) ⇒ Boolean
-
#initialize(options) ⇒ SearchRequest
constructor
A new instance of SearchRequest.
- #page ⇒ Object
-
#page=(value) ⇒ Object
page.
- #page_size ⇒ Object
-
#page_size=(value) ⇒ Object
page size.
- #precision ⇒ Object
-
#precision=(value) ⇒ Object
precision.
-
#start_index ⇒ Object
start index.
-
#to_xml ⇒ Object
utils.
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() # set search term self.search_term = [:search_term] # set the index field self.index_field = [:index_field] # set the precision self.precision = [:precision] # page and page size self.page = [:page] self.page_size = [:page_size] # set facets self.facets = [:facets] # doc id in case we do a fullview search for a single record self.doc_id = [:doc_id] # search locations self.locations = [:locations] end |
Instance Attribute Details
#index_field ⇒ Object
31 32 33 |
# File 'lib/median/primo/search_request.rb', line 31 def index_field @index_field || 'any' end |
#locations ⇒ Object
78 79 80 |
# File 'lib/median/primo/search_request.rb', line 78 def locations @locations || [] end |
#search_term ⇒ Object
25 26 27 |
# File 'lib/median/primo/search_request.rb', line 25 def search_term @search_term || doc_id end |
Instance Method Details
#doc_id ⇒ Object
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 |
#facets ⇒ Object
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
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 |
#page ⇒ Object
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_size ⇒ Object
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 |
#precision ⇒ Object
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_index ⇒ Object
start index
63 64 65 |
# File 'lib/median/primo/search_request.rb', line 63 def start_index ((page - 1) * page_size) + 1 end |
#to_xml ⇒ Object
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 |