searchkick_bharthur 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 818186270af7ec5267bc549fc676bf129dadbb80
4
- data.tar.gz: 102234acb915dc57f54cc654361ae760bed16092
3
+ metadata.gz: 16721346103dccfb79902897450a5856cac9af7b
4
+ data.tar.gz: 598d665eb6f3d2edd077ad6a7f83a7bfa4bcca61
5
5
  SHA512:
6
- metadata.gz: 4a5cca2aa2830fa4112f2fa702b36930f0fc7fe3b060a9c3802033f0d5a4193eb8fb1de073440345c8d8dacfd76262cd6c5eacf5cefbb15b3904e0947fd20de0
7
- data.tar.gz: 273108babbce1dd1f6e0696d09d3f9364c8dd749b8b6a94e7dc6ef0692708779386e968ba0a25a6094ae964650c174387bfbeeb1ee6d88ecf011f7d24dc9711f
6
+ metadata.gz: dca0bd25cf59c44df5be98dbbc00aae7eeba2d8f2270c3dada915ee4d6cba908d99b6fa3f5de08245d233142af01f6cb02556bc4e3072041b34466ccd63eee83
7
+ data.tar.gz: ad9c33db97dc860a42de4f1a2af75f3aa55bcd55e4315c106e8fcd6673fe3062dabdc4e60725fdd754c4e38ddc2e32937deed0665431ec9f50800af5bbee84ec
@@ -47,13 +47,13 @@ module Searchkick
47
47
 
48
48
  def params
49
49
  index =
50
- if options[:index_name]
51
- Array(options[:index_name]).map { |v| v.respond_to?(:searchkick_index) ? v.searchkick_index.name : v }.join(",")
52
- elsif searchkick_index
53
- searchkick_index.name
54
- else
55
- "_all"
56
- end
50
+ if options[:index_name]
51
+ Array(options[:index_name]).map { |v| v.respond_to?(:searchkick_index) ? v.searchkick_index.name : v }.join(",")
52
+ elsif searchkick_index
53
+ searchkick_index.name
54
+ else
55
+ "_all"
56
+ end
57
57
 
58
58
  params = {
59
59
  index: index,
@@ -122,11 +122,11 @@ module Searchkick
122
122
  if status_code == 404
123
123
  raise MissingIndexError, "Index missing - run #{reindex_command}"
124
124
  elsif status_code == 500 && (
125
- e.message.include?("IllegalArgumentException[minimumSimilarity >= 1]") ||
126
- e.message.include?("No query registered for [multi_match]") ||
127
- e.message.include?("[match] query does not support [cutoff_frequency]]") ||
128
- e.message.include?("No query registered for [function_score]]")
129
- )
125
+ e.message.include?("IllegalArgumentException[minimumSimilarity >= 1]") ||
126
+ e.message.include?("No query registered for [multi_match]") ||
127
+ e.message.include?("[match] query does not support [cutoff_frequency]]") ||
128
+ e.message.include?("No query registered for [function_score]]")
129
+ )
130
130
 
131
131
  raise UnsupportedVersionError, "This version of Searchkick requires Elasticsearch 1.0 or greater"
132
132
  elsif status_code == 400
@@ -200,13 +200,13 @@ module Searchkick
200
200
  queries = []
201
201
 
202
202
  misspellings =
203
- if options.key?(:misspellings)
204
- options[:misspellings]
205
- elsif options.key?(:mispellings)
206
- options[:mispellings] # why not?
207
- else
208
- true
209
- end
203
+ if options.key?(:misspellings)
204
+ options[:misspellings]
205
+ elsif options.key?(:mispellings)
206
+ options[:mispellings] # why not?
207
+ else
208
+ true
209
+ end
210
210
 
211
211
  if misspellings.is_a?(Hash) && misspellings[:below] && !@misspellings_below
212
212
  @misspellings_below = misspellings[:below].to_i
@@ -216,13 +216,13 @@ module Searchkick
216
216
  if misspellings != false
217
217
  edit_distance = (misspellings.is_a?(Hash) && (misspellings[:edit_distance] || misspellings[:distance])) || 1
218
218
  transpositions =
219
- if misspellings.is_a?(Hash) && misspellings.key?(:transpositions)
220
- {fuzzy_transpositions: misspellings[:transpositions]}
221
- elsif below14?
222
- {}
223
- else
224
- {fuzzy_transpositions: true}
225
- end
219
+ if misspellings.is_a?(Hash) && misspellings.key?(:transpositions)
220
+ {fuzzy_transpositions: misspellings[:transpositions]}
221
+ elsif below14?
222
+ {}
223
+ else
224
+ {fuzzy_transpositions: true}
225
+ end
226
226
  prefix_length = (misspellings.is_a?(Hash) && misspellings[:prefix_length]) || 0
227
227
  default_max_expansions = @misspellings_below ? 20 : 3
228
228
  max_expansions = (misspellings.is_a?(Hash) && misspellings[:max_expansions]) || default_max_expansions
@@ -238,12 +238,12 @@ module Searchkick
238
238
  }
239
239
 
240
240
  match_type =
241
- if field.end_with?(".phrase")
242
- field = field.sub(/\.phrase\z/, ".analyzed")
243
- :match_phrase
244
- else
245
- :match
246
- end
241
+ if field.end_with?(".phrase")
242
+ field = field.sub(/\.phrase\z/, ".analyzed")
243
+ :match_phrase
244
+ else
245
+ :match
246
+ end
247
247
 
248
248
  shared_options[:operator] = operator if match_type == :match || below50?
249
249
 
@@ -278,11 +278,11 @@ module Searchkick
278
278
  if conversions_field && options[:conversions] != false
279
279
  # wrap payload in a bool query
280
280
  script_score =
281
- if below12?
282
- {script_score: {script: "doc['count'].value"}}
283
- else
284
- {field_value_factor: {field: "#{conversions_field}.count"}}
285
- end
281
+ if below12?
282
+ {script_score: {script: "doc['count'].value"}}
283
+ else
284
+ {field_value_factor: {field: "#{conversions_field}.count"}}
285
+ end
286
286
 
287
287
  payload = {
288
288
  bool: {
@@ -397,25 +397,25 @@ module Searchkick
397
397
  boost_fields = {}
398
398
  fields = options[:fields] || searchkick_options[:searchable]
399
399
  fields =
400
- if fields
401
- if options[:autocomplete]
402
- fields.map { |f| "#{f}.autocomplete" }
403
- else
404
- fields.map do |value|
405
- k, v = value.is_a?(Hash) ? value.to_a.first : [value, options[:match] || searchkick_options[:match] || :word]
406
- k2, boost = k.to_s.split("^", 2)
407
- field = "#{k2}.#{v == :word ? 'analyzed' : v}"
408
- boost_fields[field] = boost.to_f if boost
409
- field
410
- end
411
- end
400
+ if fields
401
+ if options[:autocomplete]
402
+ fields.map { |f| "#{f}.autocomplete" }
412
403
  else
413
- if options[:autocomplete]
414
- (searchkick_options[:autocomplete] || []).map { |f| "#{f}.autocomplete" }
415
- else
416
- ["_all"]
404
+ fields.map do |value|
405
+ k, v = value.is_a?(Hash) ? value.to_a.first : [value, options[:match] || searchkick_options[:match] || :word]
406
+ k2, boost = k.to_s.split("^", 2)
407
+ field = "#{k2}.#{v == :word ? 'analyzed' : v}"
408
+ boost_fields[field] = boost.to_f if boost
409
+ field
417
410
  end
418
411
  end
412
+ else
413
+ if options[:autocomplete]
414
+ (searchkick_options[:autocomplete] || []).map { |f| "#{f}.autocomplete" }
415
+ else
416
+ ["_all"]
417
+ end
418
+ end
419
419
  [boost_fields, fields]
420
420
  end
421
421
 
@@ -525,7 +525,7 @@ module Searchkick
525
525
  payload[:aggs] = {}
526
526
 
527
527
  if aggs.is_a?(Hash) && aggs[:body]
528
- payload[:aggs] = aggs[:body]
528
+ payload[:aggs] = aggs[:body]
529
529
  else
530
530
  aggs = Hash[aggs.map { |f| [f, {}] }] if aggs.is_a?(Array) # convert to more advanced syntax
531
531
 
@@ -629,36 +629,47 @@ module Searchkick
629
629
  end
630
630
 
631
631
  def set_filters(payload, filters)
632
- if options[:facets] || options[:aggs]
633
- if below20?
634
- payload[:filter] = {
635
- and: filters
636
- }
637
- else
638
- payload[:post_filter] = {
639
- bool: {
640
- filter: filters
632
+ if options[:custom]
633
+ payload[:query] = {
634
+ filtered: {
635
+ query: payload[:query],
636
+ filter: {
637
+ and: filters
641
638
  }
642
639
  }
643
- end
640
+ }
644
641
  else
645
- # more efficient query if no facets
646
- if below20?
647
- payload[:query] = {
648
- filtered: {
649
- query: payload[:query],
650
- filter: {
651
- and: filters
642
+ if options[:facets] || options[:aggs]
643
+ if below20?
644
+ payload[:filter] = {
645
+ and: filters
646
+ }
647
+ else
648
+ payload[:post_filter] = {
649
+ bool: {
650
+ filter: filters
652
651
  }
653
652
  }
654
- }
653
+ end
655
654
  else
656
- payload[:query] = {
657
- bool: {
658
- must: payload[:query],
659
- filter: filters
655
+ # more efficient query if no facets
656
+ if below20?
657
+ payload[:query] = {
658
+ filtered: {
659
+ query: payload[:query],
660
+ filter: {
661
+ and: filters
662
+ }
663
+ }
660
664
  }
661
- }
665
+ else
666
+ payload[:query] = {
667
+ bool: {
668
+ must: payload[:query],
669
+ filter: filters
670
+ }
671
+ }
672
+ end
662
673
  end
663
674
  end
664
675
  end
@@ -728,18 +739,18 @@ module Searchkick
728
739
  filters << term_filters(field, op_value)
729
740
  else
730
741
  range_query =
731
- case op
732
- when :gt
733
- {from: op_value, include_lower: false}
734
- when :gte
735
- {from: op_value, include_lower: true}
736
- when :lt
737
- {to: op_value, include_upper: false}
738
- when :lte
739
- {to: op_value, include_upper: true}
740
- else
741
- raise "Unknown where operator: #{op.inspect}"
742
- end
742
+ case op
743
+ when :gt
744
+ {from: op_value, include_lower: false}
745
+ when :gte
746
+ {from: op_value, include_lower: true}
747
+ when :lt
748
+ {to: op_value, include_upper: false}
749
+ when :lte
750
+ {to: op_value, include_upper: true}
751
+ else
752
+ raise "Unknown where operator: #{op.inspect}"
753
+ end
743
754
  # issue 132
744
755
  if (existing = filters.find { |f| f[:range] && f[:range][field] })
745
756
  existing[:range][field].merge!(range_query)
@@ -801,12 +812,12 @@ module Searchkick
801
812
  log = value.key?(:log) ? value[:log] : options[:log]
802
813
  value[:factor] ||= 1
803
814
  script_score =
804
- if below12?
805
- script = log ? "log(doc['#{field}'].value + 2.718281828)" : "doc['#{field}'].value"
806
- {script_score: {script: "#{value[:factor].to_f} * #{script}"}}
807
- else
808
- {field_value_factor: {field: field, factor: value[:factor].to_f, modifier: log ? "ln2p" : nil}}
809
- end
815
+ if below12?
816
+ script = log ? "log(doc['#{field}'].value + 2.718281828)" : "doc['#{field}'].value"
817
+ {script_score: {script: "#{value[:factor].to_f} * #{script}"}}
818
+ else
819
+ {field_value_factor: {field: field, factor: value[:factor].to_f, modifier: log ? "ln2p" : nil}}
820
+ end
810
821
 
811
822
  {
812
823
  filter: {
@@ -1,3 +1,3 @@
1
1
  module Searchkick
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: searchkick_bharthur
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Kane
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-07-17 00:00:00.000000000 Z
12
+ date: 2016-07-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activemodel