mastico 0.1.0 → 0.1.1

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
- SHA1:
3
- metadata.gz: 205e8a8cf46ddea34bb51b18aac1cb1598b50e72
4
- data.tar.gz: 52aaa582fc56299a0b304b2367cc897375e3787a
2
+ SHA256:
3
+ metadata.gz: 46282da7310c519736cd0947cd37b93cb28324ca7c4bfec8e4d042f4dcfbd112
4
+ data.tar.gz: bb39aaacb4a89cfa83143347a2136246fed4ef40f930abf7a1b5561fe5e7550a
5
5
  SHA512:
6
- metadata.gz: 6b4fa50b5278ad53a9d8215efa07d53a6b5658b8ecd70d95a10687679879e33ceb7524976d3d3114a9e87318df09128db079cb59b5a86756135b937dc6023430
7
- data.tar.gz: b385bb2c52e244029adbcddfdff64af685bce5beb4eccc8d8d4184e88112a82b589cbae4a2f6c90a57bf6afb7072f09f0324e6adf8fa4c280f1937a3d22607b8
6
+ metadata.gz: 8917049d8ab75f18fb6a53446e1ddabba4c5ba9ff595e22dee3ee5869d8e0a1a7a90fcd577584d95f832d6d2642441892e776b06f68d8673a572be6e25db2f8c
7
+ data.tar.gz: 9c92b1644a6f6dbb285682cf1560c125ad5af4cb408d4fd81844707750041b5d265a89f68a6f88db86c517fea6f480003c8f73607ecdf2b22b3f8bc2cbad86b8
@@ -24,6 +24,7 @@ module Mastico
24
24
  @fields = fields
25
25
  @word_weight = word_weight
26
26
  @options = options
27
+ @parts = nil
27
28
  end
28
29
 
29
30
  def perform(scope)
@@ -33,28 +34,32 @@ module Mastico
33
34
  private
34
35
 
35
36
  def parts
36
- clean = query.strip.gsub(/\s+/, ' ').downcase
37
- terms = clean.split(" ")
38
- term_parts = terms.map do |term|
39
- weight = word_weight.call(term)
40
- next nil if weight == 0.0
41
- chewy_term_query(term: term, weight: weight)
42
- end
43
- term_parts = term_parts.compact
44
- case term_parts.size
45
- when 0
46
- nil
47
- when 1
48
- term_parts[0]
49
- else
50
- # We have multiple words in the query -
51
- # all of them **must** match
52
- {bool: {must: term_parts}} # AND query
53
- end
37
+ @parts ||=
38
+ begin
39
+ clean = query.strip.gsub(/\s+/, ' ').downcase
40
+ terms = clean.split(" ")
41
+ term_parts = terms.map do |term|
42
+ weight = word_weight.call(term)
43
+ next nil if weight == 0.0
44
+ chewy_term_query(term: term, weight: weight)
45
+ end
46
+ term_parts = term_parts.compact
47
+ case term_parts.size
48
+ when 0
49
+ nil
50
+ when 1
51
+ term_parts[0]
52
+ else
53
+ # We have multiple words in the query -
54
+ # all of them **must** match
55
+ {bool: {must: term_parts}} # AND query
56
+ end
57
+ end
54
58
  end
55
59
 
56
60
  def chewy_term_query(term:, weight:)
57
61
  parts = []
62
+
58
63
  if term.length >= options[:minimum_term_length]
59
64
  relevant_fields(:term).each do |field, field_boost|
60
65
  parts << chewy_multi_match_term_query(
@@ -64,8 +69,9 @@ module Mastico
64
69
  )
65
70
  end
66
71
  end
72
+
67
73
  if term.length >= options[:minimum_prefix_length]
68
- relevant_fields(:term).each do |field, field_boost|
74
+ relevant_fields(:prefix).each do |field, field_boost|
69
75
  parts << chewy_multi_match_prefix_query(
70
76
  query: term,
71
77
  fields: [field],
@@ -73,8 +79,9 @@ module Mastico
73
79
  )
74
80
  end
75
81
  end
82
+
76
83
  if term.length >= options[:minimum_infix_length]
77
- relevant_fields(:term).each do |field, field_boost|
84
+ relevant_fields(:infix).each do |field, field_boost|
78
85
  parts << chewy_multi_match_infix_query(
79
86
  query: term,
80
87
  fields: [field],
@@ -82,8 +89,9 @@ module Mastico
82
89
  )
83
90
  end
84
91
  end
92
+
85
93
  if term.length >= options[:minimum_fuzzy_length]
86
- relevant_fields(:term).each do |field, field_boost|
94
+ relevant_fields(:fuzzy).each do |field, field_boost|
87
95
  parts << chewy_multi_match_fuzzy_query(
88
96
  query: term,
89
97
  fields: [field],
@@ -91,6 +99,7 @@ module Mastico
91
99
  )
92
100
  end
93
101
  end
102
+
94
103
  parts.compact!
95
104
 
96
105
  if parts.size > 0
@@ -1,3 +1,3 @@
1
1
  module Mastico
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -31,6 +31,7 @@ Gem::Specification.new do |spec|
31
31
  spec.require_paths = ["lib"]
32
32
 
33
33
  spec.add_development_dependency "bundler", "~> 1.14"
34
+ spec.add_development_dependency "pry-byebug", "~> 3.6"
34
35
  spec.add_development_dependency "rake", "~> 10.0"
35
36
  spec.add_development_dependency "rspec", "~> 3.0"
36
37
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mastico
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matteo Manzo
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-01-03 00:00:00.000000000 Z
11
+ date: 2018-03-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.14'
27
+ - !ruby/object:Gem::Dependency
28
+ name: pry-byebug
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.6'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '3.6'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: rake
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -94,7 +108,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
94
108
  version: '0'
95
109
  requirements: []
96
110
  rubyforge_project:
97
- rubygems_version: 2.5.1
111
+ rubygems_version: 2.7.3
98
112
  signing_key:
99
113
  specification_version: 4
100
114
  summary: A chewy helper