chewy_queries 0.0.1 → 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 +60 -21
- data/chewy_queries.gemspec +15 -14
- data/lib/chewy_queries.rb +84 -63
- 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,44 +1,57 @@
|
|
|
1
|
-
|
|
1
|
+
# ChewyQueries
|
|
2
2
|
|
|
3
|
-
This gem
|
|
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 use this gem for firing the queries to get result.
|
|
4
5
|
|
|
5
6
|
## Getting started
|
|
6
7
|
|
|
7
8
|
### Requirements
|
|
9
|
+
|
|
10
|
+
This gem requires Ruby 2.4+, Rails 5.0+ and Chewy 5.2.0
|
|
11
|
+
|
|
12
|
+
### Installation
|
|
13
|
+
|
|
8
14
|
Add the gem to your `Gemfile`:
|
|
9
15
|
|
|
16
|
+
```ruby
|
|
10
17
|
gem 'chewy_queries'
|
|
18
|
+
```
|
|
11
19
|
|
|
12
20
|
and run:
|
|
13
21
|
|
|
22
|
+
```
|
|
14
23
|
bundle install
|
|
15
|
-
|
|
24
|
+
```
|
|
16
25
|
or
|
|
17
26
|
|
|
27
|
+
```
|
|
18
28
|
gem install chewy_queries
|
|
29
|
+
```
|
|
19
30
|
|
|
20
|
-
|
|
31
|
+
## Search query requires the following
|
|
21
32
|
|
|
22
|
-
This gem requires Ruby 2.4+, Rails 5.0+ and Chewy 5.2.0
|
|
23
33
|
|
|
24
|
-
|
|
34
|
+
```ruby
|
|
35
|
+
def search(class_name, type, condition, value, field)
|
|
36
|
+
# some elastic queries
|
|
37
|
+
end
|
|
38
|
+
```
|
|
25
39
|
|
|
26
|
-
|
|
27
|
-
------
|
|
28
|
-
------
|
|
29
|
-
------
|
|
30
|
-
#end
|
|
40
|
+
Above method includes all possible elastic queries to get the search result.
|
|
31
41
|
|
|
32
|
-
##
|
|
42
|
+
## Each argument explanation
|
|
33
43
|
|
|
34
|
-
## type is
|
|
44
|
+
## 1)type is fields types:
|
|
45
|
+
```
|
|
35
46
|
1)text
|
|
36
47
|
2)number
|
|
37
48
|
3)date
|
|
49
|
+
```
|
|
38
50
|
|
|
39
|
-
|
|
51
|
+
## 2)Condition required for each fields:
|
|
40
52
|
|
|
41
|
-
|
|
53
|
+
### a)text field
|
|
54
|
+
```
|
|
42
55
|
1)equal
|
|
43
56
|
2)not equal
|
|
44
57
|
3)contains
|
|
@@ -48,8 +61,9 @@ This gem requires Ruby 2.4+, Rails 5.0+ and Chewy 5.2.0
|
|
|
48
61
|
7)ends with
|
|
49
62
|
8)does not end with
|
|
50
63
|
9)matches exactly
|
|
51
|
-
|
|
52
|
-
|
|
64
|
+
```
|
|
65
|
+
### b)number field
|
|
66
|
+
```
|
|
53
67
|
1)Is equal to
|
|
54
68
|
2)Is not equal to
|
|
55
69
|
3)Is greater than
|
|
@@ -57,8 +71,9 @@ This gem requires Ruby 2.4+, Rails 5.0+ and Chewy 5.2.0
|
|
|
57
71
|
5)Is provided
|
|
58
72
|
6)Is not provided
|
|
59
73
|
7)Is between
|
|
60
|
-
|
|
61
|
-
|
|
74
|
+
```
|
|
75
|
+
### c)date field
|
|
76
|
+
```
|
|
62
77
|
1)Is before
|
|
63
78
|
2)Is after
|
|
64
79
|
3)Is on or before
|
|
@@ -68,6 +83,30 @@ This gem requires Ruby 2.4+, Rails 5.0+ and Chewy 5.2.0
|
|
|
68
83
|
7)Is provided
|
|
69
84
|
8)Is not provided
|
|
70
85
|
9)Is between
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
## 3)value should be your search value
|
|
89
|
+
|
|
90
|
+
## 4)field should be your search filed
|
|
91
|
+
|
|
92
|
+
## Example
|
|
93
|
+
|
|
94
|
+
```ruby
|
|
95
|
+
#for search
|
|
96
|
+
ChewyQueries::GetQuery.search(ContactIndex, "number", "Is equal to", 23, "age").limit(Contact.count)
|
|
97
|
+
|
|
98
|
+
#Note:limit is to get morethan 10 result
|
|
99
|
+
|
|
100
|
+
#for exact_match_search
|
|
101
|
+
ChewyQueries::GetQuery.exact_match_search(ContactIndex,"email","rakesh@example.com")
|
|
102
|
+
|
|
103
|
+
#for multiple_field_search
|
|
104
|
+
ChewyQueries::GetQuery.multiple_field_search(ContactIndex,["first_name","last_name","full_name"],"rakesh")
|
|
105
|
+
|
|
106
|
+
#for partial_search
|
|
107
|
+
ChewyQueries::GetQuery.partial_search(ContactIndex,"first_name","rak")
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
```
|
|
111
|
+
|
|
71
112
|
|
|
72
|
-
## value should be your search value
|
|
73
|
-
## field should be your search filed
|
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,69 +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
|
|
|
70
|
+
def exact_match_search(class_name, field, value)
|
|
71
|
+
class_name.query(match_phrase: {"#{field}": value})
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def partial_search(class_name, field, value)
|
|
75
|
+
class_name.query(regexp: {"#{field}": ".*#{value.downcase}.*"})
|
|
76
|
+
end
|
|
77
|
+
|
|
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
|
|
87
|
+
end
|
|
68
88
|
|
|
89
|
+
end
|
|
69
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:
|