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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 46359b95123b84264bb61b3ce21c2ecc9375bb5cc45c0df5d36a398bc6762ae8
4
- data.tar.gz: 7c322211d19b5412a143ea5dd2d88fa93b3c018b73aefcca7f41ef5e8d74c03f
3
+ metadata.gz: 6f197c41ecab256de373906accb142c282a94761c87d44c7cde2afffdc9802e9
4
+ data.tar.gz: c8b3fdf49c3ecd7d1b4f38988f26f341e15f88fad5e00b6d3789cb56e633e298
5
5
  SHA512:
6
- metadata.gz: 750cc3e95af36b4d07521b59b6c60547fc6274421861e38cd4afcb7f44df7e3057e2b51b370a1dbcbcb8dcf5012a16f70ad1084ac306531bfd9280d71a186bce
7
- data.tar.gz: 1d83fc2833cc6a6f10f9e02d1a8b9852b3786f42cb3d1cf5a64b06489858af895b92b68be2ec35139b23d56773eddcfc81cd79f2cb1cfe9c0edaa5450544ebbe
6
+ metadata.gz: 435c6f4b0aef9c56cedd4a4e84f6ca3c80ee98a953cc59bd390f3a0c72c01a9bbd10e3c983dedf71f7c35ca2338a93132b781a1d224a70a919a4de3943990628
7
+ data.tar.gz: 987cc75c94e55feaa17a8b252159ca295017b7da4cc28ba43695ecac33178ca7a9d00aa5a37fadb5e022423d071149e05ae9dab5ecbb59c6f63a333ae005b469
data/README.md CHANGED
@@ -1,44 +1,57 @@
1
- ### ChewyQueries
1
+ # ChewyQueries
2
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)
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
- require 'chewy_queries'
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
- ### Search query requires the following
34
+ ```ruby
35
+ def search(class_name, type, condition, value, field)
36
+ # some elastic queries
37
+ end
38
+ ```
25
39
 
26
- #def ChewyQueries.search(class_name, type, condition, value, field)
27
- ------
28
- ------
29
- ------
30
- #end
40
+ Above method includes all possible elastic queries to get the search result.
31
41
 
32
- ## class_name should be your index class name
42
+ ## Each argument explanation
33
43
 
34
- ## type is Fields types i.e:-
44
+ ## 1)type is fields types:
45
+ ```
35
46
  1)text
36
47
  2)number
37
48
  3)date
49
+ ```
38
50
 
39
- ### Condition required for each fields
51
+ ## 2)Condition required for each fields:
40
52
 
41
- # 1)text field
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
- # 2)number field
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
- # 3)date field
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
@@ -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',
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,69 +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
 
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
@@ -1,3 +1,3 @@
1
1
  module ChewyQueries
2
- VERSION = '0.0.1'
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.1
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-07 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: