Class: CloudSearch::Searcher
- Inherits:
-
Object
- Object
- CloudSearch::Searcher
- Includes:
- ConfigurationChecking
- Defined in:
- lib/eden_cloud_search/searcher.rb
Instance Attribute Summary collapse
-
#weights ⇒ Object
readonly
Returns the value of attribute weights.
Instance Method Summary collapse
- #at_page(page) ⇒ Object
-
#initialize ⇒ Searcher
constructor
A new instance of Searcher.
- #items_per_page ⇒ Object
- #page_number ⇒ Object
- #params ⇒ Object
- #ranked_by(rank_expression) ⇒ Object
- #search ⇒ Object
- #start ⇒ Object
- #with_boolean_query(queries) ⇒ Object
- #with_facets(*facets) ⇒ Object
- #with_fields(*fields) ⇒ Object
- #with_filters(filters) ⇒ 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 16 |
# File 'lib/eden_cloud_search/searcher.rb', line 9 def initialize @response = SearchResponse.new @query = '' @boolean_queries = {} @filters = {} @facets = [] @fields = [] end |
Instance Attribute Details
#weights ⇒ Object (readonly)
Returns the value of attribute weights.
7 8 9 |
# File 'lib/eden_cloud_search/searcher.rb', line 7 def weights @weights end |
Instance Method Details
#at_page(page) ⇒ Object
65 66 67 68 |
# File 'lib/eden_cloud_search/searcher.rb', line 65 def at_page(page) @page_number = (page && page < 1) ? 1 : page self end |
#items_per_page ⇒ Object
89 90 91 |
# File 'lib/eden_cloud_search/searcher.rb', line 89 def items_per_page @response.items_per_page end |
#page_number ⇒ Object
93 94 95 |
# File 'lib/eden_cloud_search/searcher.rb', line 93 def page_number @page_number or 1 end |
#params ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/eden_cloud_search/searcher.rb', line 70 def params check_configuration_parameters raise InsufficientParametersException.new('At least query or boolean_query must be defined.') if (@query.empty? && @boolean_queries.empty?) params = { 'q' => query, 'bq' => boolean_query, 'size' => items_per_page, 'start' => start, 'return-fields' => URI.escape(@fields.join(",")), 'facet' => @facets.join(','), 'rank' => @rank } params.merge! @filters params.delete_if { |_,v| v.nil? || v.to_s.empty? } params end |
#ranked_by(rank_expression) ⇒ Object
50 51 52 53 |
# File 'lib/eden_cloud_search/searcher.rb', line 50 def ranked_by(rank_expression) @rank = rank_expression self end |
#search ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/eden_cloud_search/searcher.rb', line 18 def search cloud_search_response = RestClient.get "#{CloudSearch.config.search_url}/search", :params => params @response.http_code = cloud_search_response.code @response.body = cloud_search_response.body @response end |
#start ⇒ Object
97 98 99 100 |
# File 'lib/eden_cloud_search/searcher.rb', line 97 def start return 0 if page_number <= 1 (items_per_page * (page_number - 1)) end |
#with_boolean_query(queries) ⇒ Object
31 32 33 34 35 36 37 38 |
# File 'lib/eden_cloud_search/searcher.rb', line 31 def with_boolean_query(queries) queries.each do |k, v| queries[k] = [v] unless v.respond_to? :map end @boolean_queries.merge!(queries) self end |
#with_facets(*facets) ⇒ Object
45 46 47 48 |
# File 'lib/eden_cloud_search/searcher.rb', line 45 def with_facets(*facets) @facets += facets self end |
#with_fields(*fields) ⇒ Object
55 56 57 58 |
# File 'lib/eden_cloud_search/searcher.rb', line 55 def with_fields(*fields) @fields += fields self end |
#with_filters(filters) ⇒ Object
40 41 42 43 |
# File 'lib/eden_cloud_search/searcher.rb', line 40 def with_filters(filters) @filters = filters self end |
#with_items_per_page(items_per_page) ⇒ Object
60 61 62 63 |
# File 'lib/eden_cloud_search/searcher.rb', line 60 def with_items_per_page(items_per_page) @response.items_per_page = items_per_page self end |
#with_query(query) ⇒ Object
26 27 28 29 |
# File 'lib/eden_cloud_search/searcher.rb', line 26 def with_query(query) @query = query || '' self end |