chewy_queries 0.0.0
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 +7 -0
- data/CHANGELOG.md +3 -0
- data/Gemfile +2 -0
- data/LICENSE +18 -0
- data/README.md +64 -0
- data/chewy_queries.gemspec +19 -0
- data/lib/chewy_queries.rb +69 -0
- data/lib/chewy_queries/version.rb +3 -0
- metadata +51 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 0c6d1885ab06955770811de931724b92c66e7e8d8dd09ae1359aa8b3cef49b2a
|
|
4
|
+
data.tar.gz: 7055330aeaf2319035ef934922cf6707252a01d41088679891df4bcc64f5169e
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 9129b9f8b938cc9ce5fb81f9036845e50a9c0c3d194d2918c3e663cc8922096fc05bc3d404147797c813e475949256d735ff5e21cc429449fcd59efd9eb02dc2
|
|
7
|
+
data.tar.gz: 0f98714662bc5c53e5224ba80b05234272b05ea791d1e2e01548a734b1161040a64029c2392e17a776cb467382622bc6a104883920ccf1fb108d4dbd2fe07124
|
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
Copyright (c) 2020 Lokalise team, Ilya Bodrov
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
4
|
+
a copy of this software and associated documentation files (the
|
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
9
|
+
the following conditions:
|
|
10
|
+
The above copyright notice and this permission notice shall be
|
|
11
|
+
included in all copies or substantial portions of the Software.
|
|
12
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
13
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
14
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
15
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
16
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
17
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
18
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
# ChewyQueries
|
|
2
|
+
|
|
3
|
+
This gem help you to fire the Elastic query directly.This gem is completely depending on chewy gem (Elastic search) you will get more info in (https://github.com/toptal/chewy)
|
|
4
|
+
|
|
5
|
+
## Getting started
|
|
6
|
+
|
|
7
|
+
### Requirements
|
|
8
|
+
Add the gem to your `Gemfile`:
|
|
9
|
+
|
|
10
|
+
gem 'chewy_queries'
|
|
11
|
+
|
|
12
|
+
and run:
|
|
13
|
+
|
|
14
|
+
bundle install
|
|
15
|
+
|
|
16
|
+
or
|
|
17
|
+
|
|
18
|
+
gem install chewy_queries
|
|
19
|
+
|
|
20
|
+
require 'chewy_queries'
|
|
21
|
+
|
|
22
|
+
This gem requires Ruby 2.4+, Rails 5.0+ and Chewy 5.2.0
|
|
23
|
+
|
|
24
|
+
### Search query requires the following
|
|
25
|
+
|
|
26
|
+
## Fields types
|
|
27
|
+
|
|
28
|
+
1)text
|
|
29
|
+
2)number
|
|
30
|
+
3)date
|
|
31
|
+
|
|
32
|
+
### Operators required for each fields
|
|
33
|
+
|
|
34
|
+
## 1)text field
|
|
35
|
+
1)equal
|
|
36
|
+
2)not equal
|
|
37
|
+
3)contains
|
|
38
|
+
4)does not contain
|
|
39
|
+
5)starts with
|
|
40
|
+
6)does not start with
|
|
41
|
+
7)ends with
|
|
42
|
+
8)does not end with
|
|
43
|
+
9)matches exactly
|
|
44
|
+
|
|
45
|
+
## 2)number field
|
|
46
|
+
1)Is equal to
|
|
47
|
+
2)Is not equal to
|
|
48
|
+
3)Is greater than
|
|
49
|
+
4)Is less than
|
|
50
|
+
5)Is provided
|
|
51
|
+
6)Is not provided
|
|
52
|
+
7)Is between
|
|
53
|
+
|
|
54
|
+
## 3)date field
|
|
55
|
+
1)Is before
|
|
56
|
+
2)Is after
|
|
57
|
+
3)Is on or before
|
|
58
|
+
4)Is on or after
|
|
59
|
+
5)equals
|
|
60
|
+
6)does not equal
|
|
61
|
+
7)Is provided
|
|
62
|
+
8)Is not provided
|
|
63
|
+
9)Is between
|
|
64
|
+
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
require File.expand_path('lib/chewy_queries/version', __dir__)
|
|
2
|
+
Gem::Specification.new do |spec|
|
|
3
|
+
spec.name = 'chewy_queries'
|
|
4
|
+
spec.version = ChewyQueries::VERSION
|
|
5
|
+
spec.authors = ['Rakesh']
|
|
6
|
+
spec.email = ['rakesh@example.com']
|
|
7
|
+
spec.summary = 'chewy_queries!'
|
|
8
|
+
spec.description = 'This gem help you to find the query for chewy gem'
|
|
9
|
+
spec.homepage = 'https://github.com/gems/chewy_queries'
|
|
10
|
+
spec.license = 'MIT'
|
|
11
|
+
spec.platform = Gem::Platform::RUBY
|
|
12
|
+
spec.required_ruby_version = '>= 2.4.0'
|
|
13
|
+
spec.files = Dir['README.md', 'LICENSE',
|
|
14
|
+
'CHANGELOG.md', 'lib/**/*.rb',
|
|
15
|
+
'lib/**/*.rake',
|
|
16
|
+
'chewy_queries.gemspec', '.github/*.md',
|
|
17
|
+
'Gemfile', 'Rakefile']
|
|
18
|
+
spec.extra_rdoc_files = ['README.md']
|
|
19
|
+
end
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
class ChewyQueries
|
|
2
|
+
|
|
3
|
+
def self.search(class_name, type, condition, value, field)
|
|
4
|
+
if type == "text"
|
|
5
|
+
if condition == "equal"
|
|
6
|
+
class_name.query(match_phrase: {"#{field}": value})
|
|
7
|
+
elsif condition == "not equal"
|
|
8
|
+
class_name.query.not(match: {"#{field}": value}).and(ContactIndex.query.not(match: {"#{field}": "null"}))
|
|
9
|
+
elsif condition == "contains"
|
|
10
|
+
class_name.query(regexp: {"#{field}": ".*#{value.downcase}.*"}).or(ContactIndex.query(match_phrase: {"#{field}": value}))
|
|
11
|
+
elsif condition == "does not contain"
|
|
12
|
+
class_name.query.not(regexp: {"#{field}": ".*#{value.downcase}.*"}).and(ContactIndex.query.not(match: {"#{field}": "null"}))
|
|
13
|
+
elsif condition == "starts with"
|
|
14
|
+
class_name.query(regexp: {"#{field}": "#{value.downcase}.*"})
|
|
15
|
+
elsif condition == "does not start with"
|
|
16
|
+
class_name.query.not(regexp: {"#{field}": "#{value.downcase}.*"}).and(ContactIndex.query.not(match: {"#{field}": "null"}))
|
|
17
|
+
elsif condition == "ends with"
|
|
18
|
+
class_name.query(regexp: {"#{field}": ".*#{value.downcase}"})
|
|
19
|
+
elsif condition == "does not end with"
|
|
20
|
+
class_name.query.not(regexp: {"#{field}": ".*#{value.downcase}"}).and(ContactIndex.query.not(match: {"#{field}": "null"}))
|
|
21
|
+
elsif condition == "matches exactly"
|
|
22
|
+
class_name.query(match_phrase: {"#{field}": value})
|
|
23
|
+
end
|
|
24
|
+
elsif type == "number"
|
|
25
|
+
if condition == "Is equal to"
|
|
26
|
+
class_name.query(match: {"#{field}": value})
|
|
27
|
+
elsif condition == "Is not equal to"
|
|
28
|
+
class_name.query.not(match: {"#{field}": value})
|
|
29
|
+
elsif condition == "Is greater than"
|
|
30
|
+
class_name.query(range: {"#{field}": {gt: value}})
|
|
31
|
+
elsif condition == "Is less than"
|
|
32
|
+
class_name.query(range: {"#{field}": {lt: value}}).and(ContactIndex.query.not(match: {"#{field}": 0}))
|
|
33
|
+
elsif condition == "Is provided"
|
|
34
|
+
class_name.query.not(match: {"#{field}": 0})
|
|
35
|
+
elsif condition == "Is not provided"
|
|
36
|
+
class_name.query(match: {"#{field}": 0})
|
|
37
|
+
elsif condition == "Is between"
|
|
38
|
+
class_name.query(range: {"#{field}": {gt: value.first, lt: value.last}})
|
|
39
|
+
end
|
|
40
|
+
elsif type == "date"
|
|
41
|
+
if value.class != Array
|
|
42
|
+
value1 = value.split("T").first
|
|
43
|
+
end
|
|
44
|
+
if condition == "Is before"
|
|
45
|
+
class_name.query(range: {"#{field}": {lt: value1}})
|
|
46
|
+
elsif condition == "Is after"
|
|
47
|
+
class_name.query(range: {"#{field}": {gt: value1}})
|
|
48
|
+
elsif condition == "Is on or before"
|
|
49
|
+
class_name.query(range: {"#{field}": {lte: value1}})
|
|
50
|
+
elsif condition == "Is on or after"
|
|
51
|
+
class_name.query(range: {"#{field}": {gte: value1}})
|
|
52
|
+
elsif condition == "equals"
|
|
53
|
+
class_name.query(match: {"#{field}": value1})
|
|
54
|
+
elsif condition == "does not equal"
|
|
55
|
+
class_name.query.not(match: {"#{field}": value1})
|
|
56
|
+
elsif condition == "Is provided"
|
|
57
|
+
class_name.query.not(match: {"#{field}": 0})
|
|
58
|
+
elsif condition == "Is not provided"
|
|
59
|
+
class_name.query(match: {"#{field}": 0})
|
|
60
|
+
elsif condition == "Is between"
|
|
61
|
+
value1 = value.first.split("T").first
|
|
62
|
+
value2 = value.last.split("T").first
|
|
63
|
+
class_name.query(range: {"#{field}": {gt: value1, lt: value2}})
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: chewy_queries
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Rakesh
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2021-07-07 00:00:00.000000000 Z
|
|
12
|
+
dependencies: []
|
|
13
|
+
description: This gem help you to find the query for chewy gem
|
|
14
|
+
email:
|
|
15
|
+
- rakesh@example.com
|
|
16
|
+
executables: []
|
|
17
|
+
extensions: []
|
|
18
|
+
extra_rdoc_files:
|
|
19
|
+
- README.md
|
|
20
|
+
files:
|
|
21
|
+
- CHANGELOG.md
|
|
22
|
+
- Gemfile
|
|
23
|
+
- LICENSE
|
|
24
|
+
- README.md
|
|
25
|
+
- chewy_queries.gemspec
|
|
26
|
+
- lib/chewy_queries.rb
|
|
27
|
+
- lib/chewy_queries/version.rb
|
|
28
|
+
homepage: https://github.com/gems/chewy_queries
|
|
29
|
+
licenses:
|
|
30
|
+
- MIT
|
|
31
|
+
metadata: {}
|
|
32
|
+
post_install_message:
|
|
33
|
+
rdoc_options: []
|
|
34
|
+
require_paths:
|
|
35
|
+
- lib
|
|
36
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - ">="
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: 2.4.0
|
|
41
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
42
|
+
requirements:
|
|
43
|
+
- - ">="
|
|
44
|
+
- !ruby/object:Gem::Version
|
|
45
|
+
version: '0'
|
|
46
|
+
requirements: []
|
|
47
|
+
rubygems_version: 3.1.4
|
|
48
|
+
signing_key:
|
|
49
|
+
specification_version: 4
|
|
50
|
+
summary: chewy_queries!
|
|
51
|
+
test_files: []
|