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_facet_constraints(facets_constraints) ⇒ Object
- #with_facets(*facets) ⇒ 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 13 14 15 |
# File 'lib/cloud_search/searcher.rb', line 9 def initialize @response = SearchResponse.new @filters = [] @facets = [] @fields = [] @facets_constraints = {} 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
45 46 47 48 |
# File 'lib/cloud_search/searcher.rb', line 45 def as_boolean_query @boolean = true self end |
#at_page(page) ⇒ Object
78 79 80 81 |
# File 'lib/cloud_search/searcher.rb', line 78 def at_page(page) @page_number = (page && page < 1) ? 1 : page self end |
#boolean_query? ⇒ Boolean
60 61 62 |
# File 'lib/cloud_search/searcher.rb', line 60 def boolean_query? !!@boolean end |
#items_per_page ⇒ Object
74 75 76 |
# File 'lib/cloud_search/searcher.rb', line 74 def items_per_page @response.items_per_page end |
#page_number ⇒ Object
83 84 85 |
# File 'lib/cloud_search/searcher.rb', line 83 def page_number @page_number or 1 end |
#query ⇒ Object
55 56 57 58 |
# File 'lib/cloud_search/searcher.rb', line 55 def query return '' unless @query URI.escape(@query).gsub('&', '%26') end |
#ranked_by(rank_expression) ⇒ Object
50 51 52 53 |
# File 'lib/cloud_search/searcher.rb', line 50 def ranked_by(rank_expression) @rank = rank_expression self end |
#search ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/cloud_search/searcher.rb', line 17 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
87 88 89 90 |
# File 'lib/cloud_search/searcher.rb', line 87 def start return 0 if page_number <= 1 (items_per_page * (page_number - 1)) end |
#url ⇒ Object
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/cloud_search/searcher.rb', line 92 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.any? u.concat("&#{filter_expression}") if @filters.any? u.concat("&facet=#{@facets.join(',')}") if @facets.any? u.concat(@facets_constraints.map do |k,v| values = v.respond_to?(:map) ? v.map{ |i| "'#{i}'" } : ["'#{v}'"] "&facet-#{k}-constraints=#{values.join(',')}" end.join('&')) u.concat("&rank=#{@rank}") if @rank end end |
#with_facet_constraints(facets_constraints) ⇒ Object
40 41 42 43 |
# File 'lib/cloud_search/searcher.rb', line 40 def with_facet_constraints(facets_constraints) @facets_constraints = facets_constraints self end |
#with_facets(*facets) ⇒ Object
35 36 37 38 |
# File 'lib/cloud_search/searcher.rb', line 35 def with_facets(*facets) @facets += facets self end |
#with_fields(*fields) ⇒ Object
64 65 66 67 |
# File 'lib/cloud_search/searcher.rb', line 64 def with_fields(*fields) @fields += fields self end |
#with_filter(filter) ⇒ Object
30 31 32 33 |
# File 'lib/cloud_search/searcher.rb', line 30 def with_filter(filter) @filters << filter self end |
#with_items_per_page(items_per_page) ⇒ Object
69 70 71 72 |
# File 'lib/cloud_search/searcher.rb', line 69 def with_items_per_page(items_per_page) @response.items_per_page = items_per_page self end |
#with_query(query) ⇒ Object
25 26 27 28 |
# File 'lib/cloud_search/searcher.rb', line 25 def with_query(query) @query = query self end |