Class: CloudSearch::Searcher
- Inherits:
-
Object
- Object
- CloudSearch::Searcher
- Includes:
- ConfigurationChecking
- Defined in:
- lib/cloud_search/searcher.rb
Instance Method Summary collapse
- #as_boolean_query ⇒ Object
- #at_page(page) ⇒ Object
- #boolean_query? ⇒ Boolean
-
#initialize ⇒ Searcher
constructor
A new instance of Searcher.
- #items_per_page ⇒ Object
- #page_number ⇒ Object
- #query ⇒ Object
- #search ⇒ Object
- #start ⇒ Object
- #url ⇒ Object
- #with_fields(*fields) ⇒ Object
- #with_filter(filter) ⇒ Object
- #with_items_per_page(items_per_page) ⇒ Object
- #with_query(query) ⇒ Object
Constructor Details
#initialize ⇒ Searcher
Returns a new instance of Searcher.
7 8 9 10 |
# File 'lib/cloud_search/searcher.rb', line 7 def initialize @response = SearchResponse.new @filters = [] end |
Instance Method Details
#as_boolean_query ⇒ Object
30 31 32 33 |
# File 'lib/cloud_search/searcher.rb', line 30 def as_boolean_query @boolean = true self end |
#at_page(page) ⇒ Object
58 59 60 61 |
# File 'lib/cloud_search/searcher.rb', line 58 def at_page(page) @page_number = (page && page < 1) ? 1 : page self end |
#boolean_query? ⇒ Boolean
40 41 42 |
# File 'lib/cloud_search/searcher.rb', line 40 def boolean_query? !!@boolean end |
#items_per_page ⇒ Object
54 55 56 |
# File 'lib/cloud_search/searcher.rb', line 54 def items_per_page @response.items_per_page end |
#page_number ⇒ Object
63 64 65 |
# File 'lib/cloud_search/searcher.rb', line 63 def page_number @page_number or 1 end |
#query ⇒ Object
35 36 37 38 |
# File 'lib/cloud_search/searcher.rb', line 35 def query return '' unless @query URI.escape(@query).gsub('&', '%26') end |
#search ⇒ Object
12 13 14 15 16 17 18 |
# File 'lib/cloud_search/searcher.rb', line 12 def search cloud_search_response = RestClient.get url @response.http_code = cloud_search_response.code @response.body = cloud_search_response.body @response end |
#start ⇒ Object
67 68 69 70 |
# File 'lib/cloud_search/searcher.rb', line 67 def start return 0 if page_number <= 1 (items_per_page * (page_number - 1)) + 1 end |
#url ⇒ Object
72 73 74 75 76 77 78 79 80 |
# File 'lib/cloud_search/searcher.rb', line 72 def url check_configuration_parameters "#{CloudSearch.config.search_url}/search".tap do |u| u.concat("?#{query_parameter}=#{query}&size=#{items_per_page}&start=#{start}") u.concat("&return-fields=#{URI.escape(@fields.join(","))}") if @fields && @fields.any? u.concat("&#{filter_expression}") if @filters.any? end end |
#with_fields(*fields) ⇒ Object
44 45 46 47 |
# File 'lib/cloud_search/searcher.rb', line 44 def with_fields(*fields) @fields = fields self end |
#with_filter(filter) ⇒ Object
25 26 27 28 |
# File 'lib/cloud_search/searcher.rb', line 25 def with_filter(filter) @filters << filter self end |
#with_items_per_page(items_per_page) ⇒ Object
49 50 51 52 |
# File 'lib/cloud_search/searcher.rb', line 49 def with_items_per_page(items_per_page) @response.items_per_page = items_per_page self end |
#with_query(query) ⇒ Object
20 21 22 23 |
# File 'lib/cloud_search/searcher.rb', line 20 def with_query(query) @query = query self end |