chewy_queries 0.0.4 → 0.0.5
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 +15 -14
- data/lib/chewy_queries.rb +81 -78
- data/lib/chewy_queries/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 6f197c41ecab256de373906accb142c282a94761c87d44c7cde2afffdc9802e9
|
|
4
|
+
data.tar.gz: c8b3fdf49c3ecd7d1b4f38988f26f341e15f88fad5e00b6d3789cb56e633e298
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 435c6f4b0aef9c56cedd4a4e84f6ca3c80ee98a953cc59bd390f3a0c72c01a9bbd10e3c983dedf71f7c35ca2338a93132b781a1d224a70a919a4de3943990628
|
|
7
|
+
data.tar.gz: 987cc75c94e55feaa17a8b252159ca295017b7da4cc28ba43695ecac33178ca7a9d00aa5a37fadb5e022423d071149e05ae9dab5ecbb59c6f63a333ae005b469
|
data/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# ChewyQueries
|
|
2
2
|
|
|
3
3
|
This gem is completely depending on Chewy gem (Elastic search) you will get more info in [Chewy-gem](https://github.com/toptal/chewy).
|
|
4
|
-
First develop the index by using Chewy gem, then you can this gem for firing the queries to get result.
|
|
4
|
+
First develop the index by using Chewy gem, then you can use this gem for firing the queries to get result.
|
|
5
5
|
|
|
6
6
|
## Getting started
|
|
7
7
|
|
|
@@ -32,7 +32,7 @@ gem install chewy_queries
|
|
|
32
32
|
|
|
33
33
|
|
|
34
34
|
```ruby
|
|
35
|
-
def
|
|
35
|
+
def search(class_name, type, condition, value, field)
|
|
36
36
|
# some elastic queries
|
|
37
37
|
end
|
|
38
38
|
```
|
|
@@ -93,18 +93,18 @@ Above method includes all possible elastic queries to get the search result.
|
|
|
93
93
|
|
|
94
94
|
```ruby
|
|
95
95
|
#for search
|
|
96
|
-
ChewyQueries.search(ContactIndex, "number", "Is equal to", 23, "age").limit(Contact.count)
|
|
96
|
+
ChewyQueries::GetQuery.search(ContactIndex, "number", "Is equal to", 23, "age").limit(Contact.count)
|
|
97
97
|
|
|
98
98
|
#Note:limit is to get morethan 10 result
|
|
99
99
|
|
|
100
100
|
#for exact_match_search
|
|
101
|
-
ChewyQueries.exact_match_search(ContactIndex,"email","rakesh@example.com")
|
|
101
|
+
ChewyQueries::GetQuery.exact_match_search(ContactIndex,"email","rakesh@example.com")
|
|
102
102
|
|
|
103
103
|
#for multiple_field_search
|
|
104
|
-
ChewyQueries.multiple_field_search(ContactIndex,["first_name","last_name","full_name"],"rakesh")
|
|
104
|
+
ChewyQueries::GetQuery.multiple_field_search(ContactIndex,["first_name","last_name","full_name"],"rakesh")
|
|
105
105
|
|
|
106
106
|
#for partial_search
|
|
107
|
-
ChewyQueries.partial_search(ContactIndex,"first_name","rak")
|
|
107
|
+
ChewyQueries::GetQuery.partial_search(ContactIndex,"first_name","rak")
|
|
108
108
|
|
|
109
109
|
|
|
110
110
|
```
|
data/chewy_queries.gemspec
CHANGED
|
@@ -1,19 +1,20 @@
|
|
|
1
|
-
|
|
1
|
+
require_relative 'lib/chewy_queries/version'
|
|
2
|
+
|
|
2
3
|
Gem::Specification.new do |spec|
|
|
3
|
-
spec.name
|
|
4
|
-
spec.version
|
|
5
|
-
spec.authors
|
|
6
|
-
spec.email
|
|
7
|
-
spec.summary
|
|
8
|
-
spec.description
|
|
9
|
-
spec.homepage
|
|
10
|
-
spec.license
|
|
11
|
-
spec.platform
|
|
4
|
+
spec.name = 'chewy_queries'
|
|
5
|
+
spec.version = ChewyQueries::VERSION
|
|
6
|
+
spec.authors = ['Rakesh']
|
|
7
|
+
spec.email = ['rakesh@example.com']
|
|
8
|
+
spec.summary = 'chewy_queries!'
|
|
9
|
+
spec.description = 'This gem help you to find the query for chewy gem'
|
|
10
|
+
spec.homepage = 'https://github.com/gems/chewy_queries'
|
|
11
|
+
spec.license = 'MIT'
|
|
12
|
+
spec.platform = Gem::Platform::RUBY
|
|
12
13
|
spec.required_ruby_version = '>= 2.4.0'
|
|
13
14
|
spec.files = Dir['README.md', 'LICENSE',
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
'CHANGELOG.md', 'lib/**/*.rb', 'lib/chewy_queries.rb',
|
|
16
|
+
'lib/**/*.rake',
|
|
17
|
+
'chewy_queries.gemspec', '.github/*.md',
|
|
18
|
+
'Gemfile', 'Rakefile']
|
|
18
19
|
spec.extra_rdoc_files = ['README.md']
|
|
19
20
|
end
|
data/lib/chewy_queries.rb
CHANGED
|
@@ -1,87 +1,90 @@
|
|
|
1
|
-
|
|
1
|
+
module ChewyQueries
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
3
|
+
class GetQuery
|
|
4
|
+
|
|
5
|
+
def search(class_name, type, condition, value, field)
|
|
6
|
+
if type == "text"
|
|
7
|
+
if condition == "equal"
|
|
8
|
+
class_name.query(match_phrase: {"#{field}": value})
|
|
9
|
+
elsif condition == "not equal"
|
|
10
|
+
class_name.query.not(match: {"#{field}": value}).and(class_name.query.not(match: {"#{field}": "null"}))
|
|
11
|
+
elsif condition == "contains"
|
|
12
|
+
class_name.query(regexp: {"#{field}": ".*#{value.downcase}.*"}).or(class_name.query(match_phrase: {"#{field}": value}))
|
|
13
|
+
elsif condition == "does not contain"
|
|
14
|
+
class_name.query.not(regexp: {"#{field}": ".*#{value.downcase}.*"}).and(class_name.query.not(match: {"#{field}": "null"}))
|
|
15
|
+
elsif condition == "starts with"
|
|
16
|
+
class_name.query(regexp: {"#{field}": "#{value.downcase}.*"})
|
|
17
|
+
elsif condition == "does not start with"
|
|
18
|
+
class_name.query.not(regexp: {"#{field}": "#{value.downcase}.*"}).and(class_name.query.not(match: {"#{field}": "null"}))
|
|
19
|
+
elsif condition == "ends with"
|
|
20
|
+
class_name.query(regexp: {"#{field}": ".*#{value.downcase}"})
|
|
21
|
+
elsif condition == "does not end with"
|
|
22
|
+
class_name.query.not(regexp: {"#{field}": ".*#{value.downcase}"}).and(ContactIndex.query.not(match: {"#{field}": "null"}))
|
|
23
|
+
elsif condition == "matches exactly"
|
|
24
|
+
class_name.query(match_phrase: {"#{field}": value})
|
|
25
|
+
end
|
|
26
|
+
elsif type == "number"
|
|
27
|
+
if condition == "Is equal to"
|
|
28
|
+
class_name.query(match: {"#{field}": value})
|
|
29
|
+
elsif condition == "Is not equal to"
|
|
30
|
+
class_name.query.not(match: {"#{field}": value})
|
|
31
|
+
elsif condition == "Is greater than"
|
|
32
|
+
class_name.query(range: {"#{field}": {gt: value}})
|
|
33
|
+
elsif condition == "Is less than"
|
|
34
|
+
class_name.query(range: {"#{field}": {lt: value}}).and(class_name.query.not(match: {"#{field}": 0}))
|
|
35
|
+
elsif condition == "Is provided"
|
|
36
|
+
class_name.query.not(match: {"#{field}": 0})
|
|
37
|
+
elsif condition == "Is not provided"
|
|
38
|
+
class_name.query(match: {"#{field}": 0})
|
|
39
|
+
elsif condition == "Is between"
|
|
40
|
+
class_name.query(range: {"#{field}": {gt: value.first, lt: value.last}})
|
|
41
|
+
end
|
|
42
|
+
elsif type == "date"
|
|
43
|
+
if value.class != Array
|
|
44
|
+
value1 = value.split("T").first
|
|
45
|
+
end
|
|
46
|
+
if condition == "Is before"
|
|
47
|
+
class_name.query(range: {"#{field}": {lt: value1}})
|
|
48
|
+
elsif condition == "Is after"
|
|
49
|
+
class_name.query(range: {"#{field}": {gt: value1}})
|
|
50
|
+
elsif condition == "Is on or before"
|
|
51
|
+
class_name.query(range: {"#{field}": {lte: value1}})
|
|
52
|
+
elsif condition == "Is on or after"
|
|
53
|
+
class_name.query(range: {"#{field}": {gte: value1}})
|
|
54
|
+
elsif condition == "equals"
|
|
55
|
+
class_name.query(match: {"#{field}": value1})
|
|
56
|
+
elsif condition == "does not equal"
|
|
57
|
+
class_name.query.not(match: {"#{field}": value1})
|
|
58
|
+
elsif condition == "Is provided"
|
|
59
|
+
class_name.query.not(match: {"#{field}": 0})
|
|
60
|
+
elsif condition == "Is not provided"
|
|
61
|
+
class_name.query(match: {"#{field}": 0})
|
|
62
|
+
elsif condition == "Is between"
|
|
63
|
+
value1 = value.first.split("T").first
|
|
64
|
+
value2 = value.last.split("T").first
|
|
65
|
+
class_name.query(range: {"#{field}": {gt: value1, lt: value2}})
|
|
66
|
+
end
|
|
64
67
|
end
|
|
65
68
|
end
|
|
66
|
-
end
|
|
67
69
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
70
|
+
def exact_match_search(class_name, field, value)
|
|
71
|
+
class_name.query(match_phrase: {"#{field}": value})
|
|
72
|
+
end
|
|
71
73
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
74
|
+
def partial_search(class_name, field, value)
|
|
75
|
+
class_name.query(regexp: {"#{field}": ".*#{value.downcase}.*"})
|
|
76
|
+
end
|
|
75
77
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
78
|
+
def multiple_field_search(class_name, multiple_field_array, value)
|
|
79
|
+
exact_search = []
|
|
80
|
+
partial_search = []
|
|
81
|
+
multiple_field_array.each do |field|
|
|
82
|
+
exact_search << class_name.query(match_phrase: {"#{field}": value})
|
|
83
|
+
partial_search << class_name.query(regexp: {"#{field}": ".*#{value.downcase}.*"})
|
|
84
|
+
end
|
|
85
|
+
search = exact_search + partial_search
|
|
86
|
+
return search.uniq
|
|
82
87
|
end
|
|
83
|
-
search = exact_search + partial_search
|
|
84
|
-
return search.uniq
|
|
85
|
-
end
|
|
86
88
|
|
|
89
|
+
end
|
|
87
90
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: chewy_queries
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.5
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Rakesh
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2021-
|
|
11
|
+
date: 2021-08-20 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
|
13
13
|
description: This gem help you to find the query for chewy gem
|
|
14
14
|
email:
|