chewy_queries 0.0.2 → 0.0.3
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 +38 -18
- data/lib/chewy_queries.rb +4 -4
- data/lib/chewy_queries/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 8a44148fe1c365c4907380ecba044b436611e67b62ffc55a86275a52097bf1f8
|
|
4
|
+
data.tar.gz: 3f78b696b02be625c741a6a695a2837d691bdbd3aac9f9f584c902fa9db680d8
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b07b58608223b4aec4bf6af95202308baaf1539c68fc294a915e64b9c565b57fbccee639a8f3e14bd9394bf710faa0e7e2745269c050a35e853d6cd5a3f150bf
|
|
7
|
+
data.tar.gz: 3f02574c67a4e79eaaaac29c3b18d36b3cd00318a36cf1224fe05487aaac92d3820e514e5c64b55ee6b677aee29bafaca09fae899e91375a4da113c4684f899b
|
data/README.md
CHANGED
|
@@ -1,44 +1,52 @@
|
|
|
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 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
|
|
19
|
-
|
|
20
|
-
require 'chewy_queries'
|
|
21
|
-
|
|
22
|
-
This gem requires Ruby 2.4+, Rails 5.0+ and Chewy 5.2.0
|
|
29
|
+
```
|
|
23
30
|
|
|
24
31
|
## Search query requires the following
|
|
25
32
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
33
|
+
```ruby
|
|
34
|
+
def ChewyQueries.search(class_name, type, condition, value, field)
|
|
35
|
+
# some elastic queries
|
|
36
|
+
end
|
|
37
|
+
```
|
|
29
38
|
|
|
30
|
-
Above method includes all possible
|
|
31
|
-
|
|
32
|
-
## class_name should be your index class name
|
|
39
|
+
Above method includes all possible elastic queries to get the search result.
|
|
33
40
|
|
|
41
|
+
## method explaination
|
|
34
42
|
## type is Fields types i.e:-
|
|
35
43
|
1)text
|
|
36
44
|
2)number
|
|
37
45
|
3)date
|
|
38
46
|
|
|
39
|
-
|
|
47
|
+
## Condition required for each fields
|
|
40
48
|
|
|
41
|
-
|
|
49
|
+
### 1)text field
|
|
42
50
|
1)equal
|
|
43
51
|
2)not equal
|
|
44
52
|
3)contains
|
|
@@ -49,7 +57,7 @@ Above method includes all possible query to get the search result.
|
|
|
49
57
|
8)does not end with
|
|
50
58
|
9)matches exactly
|
|
51
59
|
|
|
52
|
-
|
|
60
|
+
### 2)number field
|
|
53
61
|
1)Is equal to
|
|
54
62
|
2)Is not equal to
|
|
55
63
|
3)Is greater than
|
|
@@ -58,7 +66,7 @@ Above method includes all possible query to get the search result.
|
|
|
58
66
|
6)Is not provided
|
|
59
67
|
7)Is between
|
|
60
68
|
|
|
61
|
-
|
|
69
|
+
### 3)date field
|
|
62
70
|
1)Is before
|
|
63
71
|
2)Is after
|
|
64
72
|
3)Is on or before
|
|
@@ -70,4 +78,16 @@ Above method includes all possible query to get the search result.
|
|
|
70
78
|
9)Is between
|
|
71
79
|
|
|
72
80
|
## value should be your search value
|
|
73
|
-
## field should be your search filed
|
|
81
|
+
## field should be your search filed
|
|
82
|
+
|
|
83
|
+
## Note:This gem will give maximum 10 result if you want more than 10 you can use limit(limit(1000)) after calling methods.
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
## Example
|
|
87
|
+
|
|
88
|
+
```ruby
|
|
89
|
+
ChewyQueries.search(ContactIndex, "number", "Is equal to", 23, "age").limit(Contact.count)
|
|
90
|
+
#limit is get more than 10 result
|
|
91
|
+
|
|
92
|
+
```
|
|
93
|
+
|
data/lib/chewy_queries.rb
CHANGED
|
@@ -66,19 +66,19 @@ class ChewyQueries
|
|
|
66
66
|
end
|
|
67
67
|
|
|
68
68
|
def self.exact_match_search(class_name, field, value)
|
|
69
|
-
class_name.query(match_phrase: {"#{field}": value})
|
|
69
|
+
class_name.query(match_phrase: {"#{field}": value})
|
|
70
70
|
end
|
|
71
71
|
|
|
72
72
|
def self.partial_search(class_name, field, value)
|
|
73
|
-
class_name.query(regexp: {"#{field}": ".*#{value.downcase}.*"})
|
|
73
|
+
class_name.query(regexp: {"#{field}": ".*#{value.downcase}.*"})
|
|
74
74
|
end
|
|
75
75
|
|
|
76
76
|
def self.multiple_field_search(class_name, multiple_field_array, value)
|
|
77
77
|
exact_search = []
|
|
78
78
|
partial_search = []
|
|
79
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}.*"})
|
|
80
|
+
exact_search << class_name.query(match_phrase: {"#{field}": value})
|
|
81
|
+
partial_search << class_name.query(regexp: {"#{field}": ".*#{value.downcase}.*"})
|
|
82
82
|
end
|
|
83
83
|
search = exact_search + partial_search
|
|
84
84
|
return search.uniq
|