Class: CloudSearch::Searcher
- Inherits:
-
Object
- Object
- CloudSearch::Searcher
- Includes:
- ConfigurationChecking
- Defined in:
- lib/cloud_search/searcher.rb
Instance Attribute Summary collapse
-
#weights ⇒ Object
readonly
Returns the value of attribute weights.
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
- #ranked_by(rank_expression) ⇒ 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.
9 10 11 12 |
# File 'lib/cloud_search/searcher.rb', line 9 def initialize @response = SearchResponse.new @filters = [] end |
Instance Attribute Details
#weights ⇒ Object (readonly)
Returns the value of attribute weights.
7 8 9 |
# File 'lib/cloud_search/searcher.rb', line 7 def weights @weights end |
Instance Method Details
#as_boolean_query ⇒ Object
32 33 34 35 |
# File 'lib/cloud_search/searcher.rb', line 32 def as_boolean_query @boolean = true self end |
#at_page(page) ⇒ Object
65 66 67 68 |
# File 'lib/cloud_search/searcher.rb', line 65 def at_page(page) @page_number = (page && page < 1) ? 1 : page self end |
#boolean_query? ⇒ Boolean
47 48 49 |
# File 'lib/cloud_search/searcher.rb', line 47 def boolean_query? !!@boolean end |
#items_per_page ⇒ Object
61 62 63 |
# File 'lib/cloud_search/searcher.rb', line 61 def items_per_page @response.items_per_page end |
#page_number ⇒ Object
70 71 72 |
# File 'lib/cloud_search/searcher.rb', line 70 def page_number @page_number or 1 end |
#query ⇒ Object
42 43 44 45 |
# File 'lib/cloud_search/searcher.rb', line 42 def query return '' unless @query URI.escape(@query).gsub('&', '%26') end |
#ranked_by(rank_expression) ⇒ Object
37 38 39 40 |
# File 'lib/cloud_search/searcher.rb', line 37 def ranked_by(rank_expression) @rank = rank_expression self end |
#search ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/cloud_search/searcher.rb', line 14 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
74 75 76 77 |
# File 'lib/cloud_search/searcher.rb', line 74 def start return 0 if page_number <= 1 (items_per_page * (page_number - 1)) end |
#url ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/cloud_search/searcher.rb', line 79 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? u.concat("&#{weighted_fields_expression}") if @weights and !@weights.empty? u.concat("&rank=#{@rank}") if @rank end end |
#with_fields(*fields) ⇒ Object
51 52 53 54 |
# File 'lib/cloud_search/searcher.rb', line 51 def with_fields(*fields) @fields = fields self end |
#with_filter(filter) ⇒ Object
27 28 29 30 |
# File 'lib/cloud_search/searcher.rb', line 27 def with_filter(filter) @filters << filter self end |
#with_items_per_page(items_per_page) ⇒ Object
56 57 58 59 |
# File 'lib/cloud_search/searcher.rb', line 56 def with_items_per_page(items_per_page) @response.items_per_page = items_per_page self end |
#with_query(query) ⇒ Object
22 23 24 25 |
# File 'lib/cloud_search/searcher.rb', line 22 def with_query(query) @query = query self end |