Commit 76e0a2cb364d3e7e8bc0f7405b2f342109fe42df
1 parent
2fba6770
Exists in
master
and in
21 other branches
Added debug option to search method
Showing
3 changed files
with
44 additions
and
28 deletions
Show diff stats
CHANGELOG.md
lib/searchkick/model.rb
@@ -71,30 +71,7 @@ module Searchkick | @@ -71,30 +71,7 @@ module Searchkick | ||
71 | end | 71 | end |
72 | 72 | ||
73 | def searchkick_debug | 73 | def searchkick_debug |
74 | - require "pp" | ||
75 | - | ||
76 | - puts "Model Searchkick Options" | ||
77 | - pp searchkick_options | ||
78 | - puts | ||
79 | - | ||
80 | - puts "Model Sample Search Data" | ||
81 | - begin | ||
82 | - pp first(3).map { |r| {index: searchkick_index.record_data(r).merge(data: searchkick_index.send(:search_data, r))}} | ||
83 | - rescue => e | ||
84 | - puts "#{e.class.name}: #{e.message}" | ||
85 | - end | ||
86 | - puts | ||
87 | - | ||
88 | - puts "Elasticsearch Mapping" | ||
89 | - puts JSON.pretty_generate(searchkick_index.mapping) | ||
90 | - puts | ||
91 | - | ||
92 | - puts "Elasticsearch Settings" | ||
93 | - puts JSON.pretty_generate(searchkick_index.settings) | ||
94 | - puts | ||
95 | - | ||
96 | - puts "Elasticsearch Sample Results" | ||
97 | - puts JSON.pretty_generate(search("*", load: false, limit: 3).response) | 74 | + warn "Use debug option with search method instead" |
98 | 75 | ||
99 | nil # do not return anything, as this is strictly used for manual debugging | 76 | nil # do not return anything, as this is strictly used for manual debugging |
100 | end | 77 | end |
lib/searchkick/query.rb
@@ -112,11 +112,46 @@ module Searchkick | @@ -112,11 +112,46 @@ module Searchkick | ||
112 | padding: @padding, | 112 | padding: @padding, |
113 | load: @load, | 113 | load: @load, |
114 | includes: options[:include] || options[:includes], | 114 | includes: options[:include] || options[:includes], |
115 | - json: !options[:json].nil?, | 115 | + json: !@json.nil?, |
116 | match_suffix: @match_suffix, | 116 | match_suffix: @match_suffix, |
117 | highlighted_fields: @highlighted_fields || [] | 117 | highlighted_fields: @highlighted_fields || [] |
118 | } | 118 | } |
119 | 119 | ||
120 | + if options[:debug] | ||
121 | + require "pp" | ||
122 | + | ||
123 | + puts "Searchkick Version: #{Searchkick::VERSION}" | ||
124 | + puts "Elasticsearch Version: #{Searchkick.server_version}" | ||
125 | + puts | ||
126 | + | ||
127 | + puts "Model Searchkick Options" | ||
128 | + pp searchkick_options | ||
129 | + puts | ||
130 | + | ||
131 | + puts "Search Options" | ||
132 | + pp options | ||
133 | + puts | ||
134 | + | ||
135 | + puts "Model Search Data" | ||
136 | + begin | ||
137 | + pp klass.first(3).map { |r| {index: searchkick_index.record_data(r).merge(data: searchkick_index.send(:search_data, r))}} | ||
138 | + rescue => e | ||
139 | + puts "#{e.class.name}: #{e.message}" | ||
140 | + end | ||
141 | + puts | ||
142 | + | ||
143 | + puts "Elasticsearch Mapping" | ||
144 | + puts JSON.pretty_generate(searchkick_index.mapping) | ||
145 | + puts | ||
146 | + | ||
147 | + puts "Elasticsearch Settings" | ||
148 | + puts JSON.pretty_generate(searchkick_index.settings) | ||
149 | + puts | ||
150 | + | ||
151 | + puts "Elasticsearch Results" | ||
152 | + puts JSON.pretty_generate(response) | ||
153 | + end | ||
154 | + | ||
120 | # set execute for multi search | 155 | # set execute for multi search |
121 | @execute = Searchkick::Results.new(searchkick_klass, response, opts) | 156 | @execute = Searchkick::Results.new(searchkick_klass, response, opts) |
122 | end | 157 | end |
@@ -173,9 +208,9 @@ module Searchkick | @@ -173,9 +208,9 @@ module Searchkick | ||
173 | 208 | ||
174 | all = term == "*" | 209 | all = term == "*" |
175 | 210 | ||
176 | - options[:json] ||= options[:body] | ||
177 | - if options[:json] | ||
178 | - payload = options[:json] | 211 | + @json = options[:json] || options[:body] |
212 | + if @json | ||
213 | + payload = @json | ||
179 | else | 214 | else |
180 | if options[:query] | 215 | if options[:query] |
181 | payload = options[:query] | 216 | payload = options[:query] |