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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 990c8bb612f6b79f93019924a8c6aea863254df480f0329439bb5ce8ff953226
4
- data.tar.gz: 68974713009f8dc894192431dd2d6226d72a1938245b3ae31cb5d731c30c1eeb
3
+ metadata.gz: 6f197c41ecab256de373906accb142c282a94761c87d44c7cde2afffdc9802e9
4
+ data.tar.gz: c8b3fdf49c3ecd7d1b4f38988f26f341e15f88fad5e00b6d3789cb56e633e298
5
5
  SHA512:
6
- metadata.gz: b18a547340987f3d104856a45667be62f90bfaaba8b5481c4512dd974bbdf8f9d53988a69160dc8b65e087764626cd3eb2a374aab430e941e7628b4e3952341e
7
- data.tar.gz: 9cfc21c59c8625368e3df7fe9a25ac389be2a15c9929a18cc8a4df24fb684c082e3c5ecf6d80869d29cd2839cf4edcf61669af6c64e16c6753abe76663a618bb
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 ChewyQueries.search(class_name, type, condition, value, field)
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
  ```
@@ -1,19 +1,20 @@
1
- require File.expand_path('lib/chewy_queries/version', __dir__)
1
+ require_relative 'lib/chewy_queries/version'
2
+
2
3
  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
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
- 'CHANGELOG.md', 'lib/**/*.rb','lib/chewy_queries.rb',
15
- 'lib/**/*.rake',
16
- 'chewy_queries.gemspec', '.github/*.md',
17
- 'Gemfile', 'Rakefile']
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
- class ChewyQueries
1
+ module ChewyQueries
2
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(class_name.query.not(match: {"#{field}": "null"}))
9
- elsif condition == "contains"
10
- class_name.query(regexp: {"#{field}": ".*#{value.downcase}.*"}).or(class_name.query(match_phrase: {"#{field}": value}))
11
- elsif condition == "does not contain"
12
- class_name.query.not(regexp: {"#{field}": ".*#{value.downcase}.*"}).and(class_name.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(class_name.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(class_name.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}})
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
- def self.exact_match_search(class_name, field, value)
69
- class_name.query(match_phrase: {"#{field}": value})
70
- end
70
+ def exact_match_search(class_name, field, value)
71
+ class_name.query(match_phrase: {"#{field}": value})
72
+ end
71
73
 
72
- def self.partial_search(class_name, field, value)
73
- class_name.query(regexp: {"#{field}": ".*#{value.downcase}.*"})
74
- end
74
+ def partial_search(class_name, field, value)
75
+ class_name.query(regexp: {"#{field}": ".*#{value.downcase}.*"})
76
+ end
75
77
 
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})
81
- partial_search << class_name.query(regexp: {"#{field}": ".*#{value.downcase}.*"})
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
@@ -1,3 +1,3 @@
1
1
  module ChewyQueries
2
- VERSION = '0.0.4'
2
+ VERSION = '0.0.5'
3
3
  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
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-07-08 00:00:00.000000000 Z
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: