chewy_queries 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +6 -6
- data/chewy_queries.gemspec +1 -1
- data/lib/chewy_queries.rb +18 -0
- data/lib/chewy_queries/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: add0b2391e69e66947d7323c8f296e53275d4b5d6a179ad2fbc800115908493f
|
|
4
|
+
data.tar.gz: ae14f4c97ab71d2ea790992dc8b9396271f9b0278ee236456b85df4f09f306de
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 548ed26e5bc14e219371e15d74e405346965bb486f4604b49ef2da9af98cd1a7eb0f5fc0952da1c982efec5367be657cceeb24a8c876f4248e52b5af099395d2
|
|
7
|
+
data.tar.gz: c0ab9fa4fd9f8933c8731be3386af093423d97a9c8739d19ea3cc4a99d1b2f6dd3373cc2eec95d7902dd40200d15426ad7f29761f4bd146094aeb7bcc5cc79cb
|
data/README.md
CHANGED
|
@@ -21,13 +21,13 @@ require 'chewy_queries'
|
|
|
21
21
|
|
|
22
22
|
This gem requires Ruby 2.4+, Rails 5.0+ and Chewy 5.2.0
|
|
23
23
|
|
|
24
|
-
|
|
24
|
+
## Search query requires the following
|
|
25
25
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
26
|
+
## def ChewyQueries.search(class_name, type, condition, value, field)
|
|
27
|
+
# some elastic queries
|
|
28
|
+
## end
|
|
29
|
+
|
|
30
|
+
Above method includes all possible query to get the search result.
|
|
31
31
|
|
|
32
32
|
## class_name should be your index class name
|
|
33
33
|
|
data/chewy_queries.gemspec
CHANGED
|
@@ -11,7 +11,7 @@ Gem::Specification.new do |spec|
|
|
|
11
11
|
spec.platform = Gem::Platform::RUBY
|
|
12
12
|
spec.required_ruby_version = '>= 2.4.0'
|
|
13
13
|
spec.files = Dir['README.md', 'LICENSE',
|
|
14
|
-
'CHANGELOG.md', 'lib/**/*.rb',
|
|
14
|
+
'CHANGELOG.md', 'lib/**/*.rb','lib/chewy_queries.rb',
|
|
15
15
|
'lib/**/*.rake',
|
|
16
16
|
'chewy_queries.gemspec', '.github/*.md',
|
|
17
17
|
'Gemfile', 'Rakefile']
|
data/lib/chewy_queries.rb
CHANGED
|
@@ -65,5 +65,23 @@ class ChewyQueries
|
|
|
65
65
|
end
|
|
66
66
|
end
|
|
67
67
|
|
|
68
|
+
def self.exact_match_search(class_name, field, value)
|
|
69
|
+
class_name.query(match_phrase: {"#{field}": value}).to_a
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
def self.partial_search(class_name, field, value)
|
|
73
|
+
class_name.query(regexp: {"#{field}": ".*#{value.downcase}.*"}).to_a
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
def self.multiple_field_search(class_name, multiple_field_array, value)
|
|
77
|
+
exact_search = []
|
|
78
|
+
partial_search = []
|
|
79
|
+
multiple_field_array.each do |field|
|
|
80
|
+
exact_search << class_name.query(match_phrase: {"#{field}": value}).to_a
|
|
81
|
+
partial_search << class_name.query(regexp: {"#{field}": ".*#{value.downcase}.*"}).to_a
|
|
82
|
+
end
|
|
83
|
+
search = exact_search + partial_search
|
|
84
|
+
return search.uniq
|
|
85
|
+
end
|
|
68
86
|
|
|
69
87
|
end
|