rad_core_rails 0.7.2 → 0.8.1
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/.rspec +3 -3
- data/.travis.yml +5 -5
- data/CODE_OF_CONDUCT.md +74 -74
- data/LICENSE.txt +21 -21
- data/lib/rad_core_rails/query_generator.rb +183 -70
- data/lib/rad_core_rails/search_terms.rb +30 -30
- data/lib/rad_core_rails/sortable.rb +14 -14
- data/lib/rad_core_rails/version.rb +1 -1
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 24abb5cab9e032e1dd58b62f1cf23dd6c3770fd1528e0753db9d5a30987bd896
|
4
|
+
data.tar.gz: d2d94cd4bdf1bfc8f5cef2721f0c553d571ccf12dc07af754ee2c09e1a2e32a9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e2aad3c602d90791ce6f073194a09997ce052964cba4def78cc440da7fc031510932b80066de33b75d7479bb6f8617310ac548867fc6b2c5332bd5457798020a
|
7
|
+
data.tar.gz: cfae00d26644fdcaccdf50665675d7e06ec343697ee95179dd9f34909e1712753a629e72e23f94fa77888a7618a6ce26ab377fecadfa1cc0eac3b29901332af9
|
data/.rspec
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
--format documentation
|
2
|
-
--color
|
3
|
-
--require spec_helper
|
1
|
+
--format documentation
|
2
|
+
--color
|
3
|
+
--require spec_helper
|
data/.travis.yml
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
---
|
2
|
-
language: ruby
|
3
|
-
cache: bundler
|
4
|
-
rvm:
|
5
|
-
- 2.4.5
|
1
|
+
---
|
2
|
+
language: ruby
|
3
|
+
cache: bundler
|
4
|
+
rvm:
|
5
|
+
- 2.4.5
|
6
6
|
- 2.7.0
|
data/CODE_OF_CONDUCT.md
CHANGED
@@ -1,74 +1,74 @@
|
|
1
|
-
# Contributor Covenant Code of Conduct
|
2
|
-
|
3
|
-
## Our Pledge
|
4
|
-
|
5
|
-
In the interest of fostering an open and welcoming environment, we as
|
6
|
-
contributors and maintainers pledge to making participation in our project and
|
7
|
-
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
-
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
-
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
-
orientation.
|
11
|
-
|
12
|
-
## Our Standards
|
13
|
-
|
14
|
-
Examples of behavior that contributes to creating a positive environment
|
15
|
-
include:
|
16
|
-
|
17
|
-
* Using welcoming and inclusive language
|
18
|
-
* Being respectful of differing viewpoints and experiences
|
19
|
-
* Gracefully accepting constructive criticism
|
20
|
-
* Focusing on what is best for the community
|
21
|
-
* Showing empathy towards other community members
|
22
|
-
|
23
|
-
Examples of unacceptable behavior by participants include:
|
24
|
-
|
25
|
-
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
-
advances
|
27
|
-
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
-
* Public or private harassment
|
29
|
-
* Publishing others' private information, such as a physical or electronic
|
30
|
-
address, without explicit permission
|
31
|
-
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
-
professional setting
|
33
|
-
|
34
|
-
## Our Responsibilities
|
35
|
-
|
36
|
-
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
-
behavior and are expected to take appropriate and fair corrective action in
|
38
|
-
response to any instances of unacceptable behavior.
|
39
|
-
|
40
|
-
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
-
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
-
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
-
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
-
threatening, offensive, or harmful.
|
45
|
-
|
46
|
-
## Scope
|
47
|
-
|
48
|
-
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
-
when an individual is representing the project or its community. Examples of
|
50
|
-
representing a project or community include using an official project e-mail
|
51
|
-
address, posting via an official social media account, or acting as an appointed
|
52
|
-
representative at an online or offline event. Representation of a project may be
|
53
|
-
further defined and clarified by project maintainers.
|
54
|
-
|
55
|
-
## Enforcement
|
56
|
-
|
57
|
-
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
-
reported by contacting the project team at sancho.ck@gmail.com. All
|
59
|
-
complaints will be reviewed and investigated and will result in a response that
|
60
|
-
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
-
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
-
Further details of specific enforcement policies may be posted separately.
|
63
|
-
|
64
|
-
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
-
faith may face temporary or permanent repercussions as determined by other
|
66
|
-
members of the project's leadership.
|
67
|
-
|
68
|
-
## Attribution
|
69
|
-
|
70
|
-
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
-
available at [https://contributor-covenant.org/version/1/4][version]
|
72
|
-
|
73
|
-
[homepage]: https://contributor-covenant.org
|
74
|
-
[version]: https://contributor-covenant.org/version/1/4/
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at sancho.ck@gmail.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [https://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: https://contributor-covenant.org
|
74
|
+
[version]: https://contributor-covenant.org/version/1/4/
|
data/LICENSE.txt
CHANGED
@@ -1,21 +1,21 @@
|
|
1
|
-
The MIT License (MIT)
|
2
|
-
|
3
|
-
Copyright (c) 2020 Oleksandr Poltavets
|
4
|
-
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
7
|
-
in the Software without restriction, including without limitation the rights
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
10
|
-
furnished to do so, subject to the following conditions:
|
11
|
-
|
12
|
-
The above copyright notice and this permission notice shall be included in
|
13
|
-
all copies or substantial portions of the Software.
|
14
|
-
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
-
THE SOFTWARE.
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2020 Oleksandr Poltavets
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
@@ -24,15 +24,16 @@ module RadCoreRails
|
|
24
24
|
@filter_manifest || {}.with_indifferent_access
|
25
25
|
end
|
26
26
|
|
27
|
-
def create_filters(
|
27
|
+
def create_filters(filters)
|
28
28
|
query = []
|
29
29
|
args = []
|
30
|
-
clause, arguments = generate_search_clause(search)
|
31
|
-
query << clause
|
32
|
-
arguments.each do |arg|
|
33
|
-
|
34
|
-
end
|
35
|
-
filters.map do |
|
30
|
+
# clause, arguments = generate_search_clause(search)
|
31
|
+
# query << clause
|
32
|
+
# arguments.each do |arg|
|
33
|
+
# args << arg
|
34
|
+
# end
|
35
|
+
filters.map do |raw_filter|
|
36
|
+
filter = raw_filter.with_indifferent_access
|
36
37
|
begin
|
37
38
|
clause, arguments = filter_manifest[filter[:key]].call(filter)
|
38
39
|
query << clause
|
@@ -40,98 +41,132 @@ module RadCoreRails
|
|
40
41
|
args << arg
|
41
42
|
end
|
42
43
|
rescue NoMethodError
|
43
|
-
raise NoMethodError
|
44
|
+
raise NoMethodError, "Filter with the name `#{filter[:key]}` doesn't exist."
|
44
45
|
end
|
45
46
|
end
|
46
47
|
[query.reject(&:blank?).join(' AND '), args]
|
47
48
|
end
|
48
49
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
# # search_term_size = search.split(' ').length
|
54
|
-
# and_terms = search.split(' ').select { |term| !term.include?('+') }
|
55
|
-
# or_terms = search.split(' ').select { |term| term.include?('+') }
|
56
|
-
# and_columns = []
|
57
|
-
# or_columns = []
|
58
|
-
# # just_ors = search_term_size == or_term_size
|
59
|
-
# # operand = just_ors ? 'OR' : 'AND'
|
60
|
-
# # search_terms = just_ors == true ? search.split(' ') : search.split(' ').select { |term| !term.include?('+') }
|
61
|
-
# and_terms.each do |term|
|
62
|
-
# columns = []
|
63
|
-
# and_terms.each do |col|
|
64
|
-
# and_columns.push("(LOWER(#{col}) ILIKE ?)")
|
65
|
-
# and_args.push '%' + term.downcase.strip + '%'
|
66
|
-
# end
|
67
|
-
# or_terms.each do |col|
|
68
|
-
# columns.push("(LOWER(#{col}) ILIKE ?)")
|
69
|
-
# or_args.push '%' + term[1, term.length].downcase.strip + '%'
|
70
|
-
# end
|
71
|
-
# clause = if or_columns.empty?
|
72
|
-
# '(' + and_columns.join(' OR ') + ')'
|
73
|
-
# else
|
74
|
-
# '(' + '(' + and_columns.join(' OR ') + ')' + 'AND' + '(' + or_columns.join(' OR ') + ')' + ')'
|
75
|
-
# end
|
76
|
-
# end
|
77
|
-
# [clause, and_args + or_args]
|
78
|
-
# else
|
79
|
-
# ['', []]
|
80
|
-
# end
|
81
|
-
# end
|
82
|
-
|
83
|
-
# @searchable_columns, is an array of column names that you can compare to your terms.
|
84
|
-
#
|
85
|
-
def generate_search_clause(search)
|
50
|
+
def generate_search_clause(filter)
|
51
|
+
search = filter[:values][0]
|
52
|
+
search_clause = ['', []]
|
53
|
+
|
86
54
|
if search.present? && searchable_columns.is_a?(Array)
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
#
|
55
|
+
and_args = [] # SQL from sanitized_and_terms
|
56
|
+
excluded_args = [] # SQL from sanitized_excluded_terms
|
57
|
+
and_clause = [] # table columns SQL for all the AND terms
|
58
|
+
excluded_clause = [] # table columns SQL for all the AND NOT terms
|
59
|
+
or_args = [] # SQL from sanitized_or_terms
|
60
|
+
or_clause = [] # table columns SQL for all the OR terms
|
61
|
+
|
62
|
+
phrases_or = search.scan(/\+"([^"]*)"/) # e.g. +"Phrase for OR"
|
63
|
+
# remove 'or' phrases from search if any
|
64
|
+
phrases_or.each { |phrase| search.gsub!('+"' + phrase.first.to_s + '"', '') } if phrases_or.any?
|
65
|
+
|
66
|
+
phrases_to_exclude = search.scan(/-"([^"]*)"/) # e.g. -"Phrase to exclude"
|
67
|
+
# remove excluded phrases from search if any
|
68
|
+
if phrases_to_exclude.any?
|
69
|
+
phrases_to_exclude.each { |phrase| search.gsub!('-"' + phrase.first.to_s + '"', '') }
|
70
|
+
end
|
71
|
+
|
72
|
+
phrases_and = search.scan(/"([^"]*)"/) # e.g. "Phrase for AND"
|
73
|
+
# remove 'and' phrases from search if any
|
74
|
+
phrases_and.each { |phrase| search.gsub!('"' + phrase.first.to_s + '"', '') } if phrases_and.any?
|
75
|
+
|
76
|
+
# extract 'and' terms, remove casing, and add ILIKE '%' comparisons
|
96
77
|
sanitized_and_terms = search.split(' ')
|
97
|
-
.reject { |term| term.include?('+') }
|
78
|
+
.reject { |term| term.include?('+') || term.include?('-') }
|
98
79
|
.map { |term| '%' + term.downcase.strip + '%' }
|
99
|
-
#
|
80
|
+
# add 'and' phrase terms, remove casing, and add ILIKE '%' comparisons
|
81
|
+
if phrases_and.any?
|
82
|
+
sanitized_and_terms += phrases_and.flatten.map { |phrase| '%' + phrase.downcase.strip + '%' }
|
83
|
+
end
|
84
|
+
|
85
|
+
# extract 'or' terms, remove casing, and add ILIKE '%' comparisons
|
100
86
|
sanitized_or_terms = search.split(' ')
|
101
87
|
.select { |term| term.include?('+') }
|
102
88
|
.map { |term| '%' + term[1, term.length].downcase.strip + '%' }
|
89
|
+
|
90
|
+
# add 'or' phrase terms, remove casing, and add ILIKE '%' comparisons
|
91
|
+
sanitized_or_terms += phrases_or.flatten.map { |phrase| '%' + phrase.downcase.strip + '%' } if phrases_or.any?
|
92
|
+
|
93
|
+
# extract excluded terms, remove casing, and add NOT ILIKE '%' comparisons
|
94
|
+
sanitized_excluded_terms = search.split(' ')
|
95
|
+
.select { |term| term.include?('-') }
|
96
|
+
.map { |term| '%' + term[1, term.length].downcase.strip + '%' }
|
97
|
+
|
98
|
+
# add excluded phrase terms, remove casing, and add NOT ILIKE '%' comparisons
|
99
|
+
if phrases_to_exclude.any?
|
100
|
+
sanitized_excluded_terms += phrases_to_exclude.flatten
|
101
|
+
.map { |phrase| '%' + phrase.downcase.strip + '%' }
|
102
|
+
end
|
103
|
+
|
103
104
|
# loop through sanitized_and_terms to find all possible columns.
|
104
105
|
sanitized_and_terms.each do |sanitized_term|
|
105
106
|
columns = []
|
106
107
|
# all possible columns where this should be searched
|
107
108
|
searchable_columns.each do |col|
|
108
|
-
columns.push("(LOWER(#{col}) ILIKE ?)")
|
109
|
+
columns.push("(COALESCE(LOWER(#{col}), '') ILIKE ?)")
|
109
110
|
and_args.push sanitized_term
|
110
111
|
end
|
111
112
|
and_clause.push '(' + columns.join(' OR ') + ')'
|
112
113
|
end
|
114
|
+
# loop through sanitized_excluded_terms to find all possible columns.
|
115
|
+
sanitized_excluded_terms.each do |sanitized_term|
|
116
|
+
columns = []
|
117
|
+
# all possible columns where this should be searched
|
118
|
+
searchable_columns.each do |col|
|
119
|
+
columns.push("(COALESCE(LOWER(#{col}), '') NOT ILIKE ?)")
|
120
|
+
excluded_args.push sanitized_term
|
121
|
+
end
|
122
|
+
excluded_clause.push '(' + columns.join(' AND ') + ')'
|
123
|
+
end
|
113
124
|
# loop through sanitized_or_terms to find all possible columns.
|
114
125
|
sanitized_or_terms.each do |sanitized_term|
|
115
126
|
columns = []
|
116
127
|
# all possible columns where this should be searched
|
117
128
|
searchable_columns.each do |col|
|
118
|
-
columns.push("(LOWER(#{col}) ILIKE ?)")
|
129
|
+
columns.push("(COALESCE(LOWER(#{col}), '') ILIKE ?)")
|
119
130
|
or_args.push sanitized_term
|
120
131
|
end
|
121
132
|
or_clause.push '(' + columns.join(' OR ') + ')'
|
122
133
|
end
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
134
|
+
|
135
|
+
return ['', []] if or_clause.empty? && and_clause.empty? && excluded_clause.empty?
|
136
|
+
|
137
|
+
return ['(' + and_clause.join(' AND ') + ')', and_args] if or_clause.empty? && excluded_clause.empty?
|
138
|
+
|
139
|
+
return ['(' + or_clause.join(' OR ') + ')', or_args] if and_clause.empty? && excluded_clause.empty?
|
140
|
+
|
141
|
+
return ['(' + excluded_clause.join(' AND ') + ')', excluded_args] if or_clause.empty? && and_clause.empty?
|
142
|
+
|
143
|
+
if or_clause.empty?
|
144
|
+
return ['((' + and_clause.join(' AND ') + ') AND (' + excluded_clause.join(' AND ') + '))',
|
145
|
+
and_args + excluded_args]
|
131
146
|
end
|
132
|
-
|
133
|
-
|
147
|
+
|
148
|
+
if and_clause.empty?
|
149
|
+
return ['((' + or_clause.join(' OR ') + ') AND (' + excluded_clause.join(' AND ') + '))',
|
150
|
+
or_args + excluded_args]
|
151
|
+
end
|
152
|
+
|
153
|
+
if excluded_clause.empty?
|
154
|
+
return ['((' + and_clause.join(' AND ') + ') AND (' + or_clause.join(' OR ') + '))', and_args + or_args]
|
155
|
+
end
|
156
|
+
|
157
|
+
search_clause = [
|
158
|
+
'((' +
|
159
|
+
and_clause.join(' AND ') +
|
160
|
+
') AND (' +
|
161
|
+
or_clause.join(' OR ') +
|
162
|
+
') AND (' +
|
163
|
+
excluded_clause.join(' AND ') +
|
164
|
+
'))',
|
165
|
+
and_args + or_args + excluded_args
|
166
|
+
]
|
134
167
|
end
|
168
|
+
|
169
|
+
search_clause
|
135
170
|
end
|
136
171
|
|
137
172
|
# Generate Boolean clause
|
@@ -156,6 +191,77 @@ module RadCoreRails
|
|
156
191
|
[str, args]
|
157
192
|
end
|
158
193
|
|
194
|
+
def sanitize_vector_string(search)
|
195
|
+
phrases_or = search.scan(/\+"([^"]*)"/) # e.g. +"Phrase for OR"
|
196
|
+
# remove 'or' phrases from search if any
|
197
|
+
phrases_or.each { |phrase| search.gsub!('+"' + phrase.first.to_s + '"', '') } if phrases_or.any?
|
198
|
+
|
199
|
+
phrases_to_exclude = search.scan(/-"([^"]*)"/) # e.g. -"Phrase to exclude"
|
200
|
+
# remove excluded phrases from search if any
|
201
|
+
phrases_to_exclude.each { |phrase| search.gsub!('-"' + phrase.first.to_s + '"', '') } if phrases_to_exclude.any?
|
202
|
+
|
203
|
+
phrases_and = search.scan(/"([^"]*)"/) # e.g. "Phrase for AND"
|
204
|
+
# remove 'and' phrases from search if any
|
205
|
+
phrases_and.each { |phrase| search.gsub!('"' + phrase.first.to_s + '"', '') } if phrases_and.any?
|
206
|
+
|
207
|
+
sanitized_and_terms = search.split(' ')
|
208
|
+
.reject { |term| term.include?('+') || term.include?('-') }
|
209
|
+
.map { |term| term.downcase.strip + ':*' }
|
210
|
+
.reject { |t| t.blank? }
|
211
|
+
|
212
|
+
sanitized_or_terms = search.split(' ')
|
213
|
+
.select { |term| term.include?('+') }
|
214
|
+
.map { |term| term[1, term.length].downcase + ':*' }
|
215
|
+
.reject { |t| t.blank? }
|
216
|
+
|
217
|
+
sanitized_excluded_terms = search.split(' ')
|
218
|
+
.select { |term| term.include?('-') }
|
219
|
+
.map { |term| term[1, term.length].downcase.strip + ':*' }
|
220
|
+
.reject { |t| t.blank? }
|
221
|
+
|
222
|
+
and_clause = sanitized_and_terms.join(' & ')
|
223
|
+
|
224
|
+
or_clause = sanitized_or_terms.join(' | ')
|
225
|
+
|
226
|
+
excluded_clause = sanitized_excluded_terms.map { |t| "!#{t}" }.join(' & ')
|
227
|
+
|
228
|
+
# puts '------'
|
229
|
+
# puts '------'
|
230
|
+
# puts '------'
|
231
|
+
# puts and_clause.inspect
|
232
|
+
# puts or_clause.inspect
|
233
|
+
# puts excluded_clause.inspect
|
234
|
+
# puts '------'
|
235
|
+
# puts '------'
|
236
|
+
|
237
|
+
if and_clause.present? && or_clause.empty? && excluded_clause.empty?
|
238
|
+
and_clause
|
239
|
+
elsif and_clause.empty? && or_clause.present? && excluded_clause.empty?
|
240
|
+
or_clause
|
241
|
+
elsif and_clause.empty? && or_clause.empty? && excluded_clause.present?
|
242
|
+
excluded_clause
|
243
|
+
elsif and_clause.present? && or_clause.present? && excluded_clause.empty?
|
244
|
+
"(#{and_clause}) & (#{or_clause})"
|
245
|
+
elsif and_clause.present? && or_clause.empty? && excluded_clause.present?
|
246
|
+
"(#{and_clause}) & (#{excluded_clause})"
|
247
|
+
elsif and_clause.empty? && or_clause.present? && excluded_clause.present?
|
248
|
+
"(#{or_clause}) & (#{excluded_clause})"
|
249
|
+
elsif and_clause.present? && or_clause.present? && excluded_clause.present?
|
250
|
+
"(#{and_clause}) & (#{or_clause}) & (#{excluded_clause})"
|
251
|
+
else
|
252
|
+
raise StandardError, 'Combination not available.'
|
253
|
+
end
|
254
|
+
end
|
255
|
+
|
256
|
+
def generate_vector_clause(column_name, filter)
|
257
|
+
return ['', []] if filter[:values][0].blank?
|
258
|
+
|
259
|
+
vector_string = sanitize_vector_string(filter[:values][0])
|
260
|
+
|
261
|
+
query = "(#{column_name} @@ to_tsquery('english', ?))"
|
262
|
+
[query, [vector_string]]
|
263
|
+
end
|
264
|
+
|
159
265
|
def generate_zip_codes_clause(column_name, filter)
|
160
266
|
str = "(#{column_name} = ANY(#{zip_code_class.distance_query}))"
|
161
267
|
args = zip_code_class.distance_args(filter)
|
@@ -164,8 +270,13 @@ module RadCoreRails
|
|
164
270
|
end
|
165
271
|
|
166
272
|
def generate_array_clause(column_name, filter)
|
167
|
-
|
168
|
-
|
273
|
+
if filter[:option] == '!='
|
274
|
+
str = "(SELECT NOT(#{column_name}::text[] && ARRAY[?]))"
|
275
|
+
args = [filter[:values]]
|
276
|
+
else
|
277
|
+
str = "(SELECT (#{column_name}::text[] && ARRAY[?]))"
|
278
|
+
args = [filter[:values]]
|
279
|
+
end
|
169
280
|
|
170
281
|
[str, args]
|
171
282
|
end
|
@@ -254,6 +365,7 @@ module RadCoreRails
|
|
254
365
|
|
255
366
|
def handle_filterable(filters_data)
|
256
367
|
return nil if filters_data.empty?
|
368
|
+
|
257
369
|
@zip_code_class = filters_data.delete(:zip_code_class)
|
258
370
|
|
259
371
|
result = {}
|
@@ -270,6 +382,7 @@ module RadCoreRails
|
|
270
382
|
|
271
383
|
def zip_code_class
|
272
384
|
return RadCoreRails::ZipCode unless @zip_code_class
|
385
|
+
|
273
386
|
@zip_code_class.to_s.constantize
|
274
387
|
end
|
275
388
|
end
|
@@ -1,31 +1,31 @@
|
|
1
|
-
module RadCoreRails
|
2
|
-
module SearchTerms
|
3
|
-
extend ActiveSupport::Concern
|
4
|
-
|
5
|
-
class_methods do
|
6
|
-
def _terms(column, search = '')
|
7
|
-
if search.present?
|
8
|
-
if column.is_a?(Array)
|
9
|
-
terms = []
|
10
|
-
search.split(' ').each do |term|
|
11
|
-
columns = []
|
12
|
-
column.each do |col|
|
13
|
-
columns.push("(replace(lower(#{Arel.sql(col)}), ' ', '') ILIKE '%#{Arel.sql(term.downcase)}%')")
|
14
|
-
end
|
15
|
-
terms.push '(' + columns.join(' OR ') + ')'
|
16
|
-
end
|
17
|
-
'(' + terms.join(' AND ') + ')'
|
18
|
-
else
|
19
|
-
terms = []
|
20
|
-
search.split(' ').each do |term|
|
21
|
-
terms.push("(replace(lower(#{Arel.sql(column)}), ' ', '') ILIKE '%#{Arel.sql(term.downcase)}%')")
|
22
|
-
end
|
23
|
-
'(' + terms.join(' AND ') + ')'
|
24
|
-
end
|
25
|
-
else
|
26
|
-
'1 = 1'
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
1
|
+
module RadCoreRails
|
2
|
+
module SearchTerms
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
class_methods do
|
6
|
+
def _terms(column, search = '')
|
7
|
+
if search.present?
|
8
|
+
if column.is_a?(Array)
|
9
|
+
terms = []
|
10
|
+
search.split(' ').each do |term|
|
11
|
+
columns = []
|
12
|
+
column.each do |col|
|
13
|
+
columns.push("(replace(lower(#{Arel.sql(col)}), ' ', '') ILIKE '%#{Arel.sql(term.downcase)}%')")
|
14
|
+
end
|
15
|
+
terms.push '(' + columns.join(' OR ') + ')'
|
16
|
+
end
|
17
|
+
'(' + terms.join(' AND ') + ')'
|
18
|
+
else
|
19
|
+
terms = []
|
20
|
+
search.split(' ').each do |term|
|
21
|
+
terms.push("(replace(lower(#{Arel.sql(column)}), ' ', '') ILIKE '%#{Arel.sql(term.downcase)}%')")
|
22
|
+
end
|
23
|
+
'(' + terms.join(' AND ') + ')'
|
24
|
+
end
|
25
|
+
else
|
26
|
+
'1 = 1'
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
31
|
end
|
@@ -1,14 +1,14 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
module RadCoreRails
|
3
|
-
module Sortable
|
4
|
-
extend ActiveSupport::Concern
|
5
|
-
|
6
|
-
included do
|
7
|
-
scope :sort_order, ->(column, direction) { order(self.sort_column(column, direction)) }
|
8
|
-
|
9
|
-
def self.sort_column(column, direction)
|
10
|
-
"#{Arel.sql(column)} #{sort_direction(direction)}"
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module RadCoreRails
|
3
|
+
module Sortable
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
included do
|
7
|
+
scope :sort_order, ->(column, direction) { order(self.sort_column(column, direction)) }
|
8
|
+
|
9
|
+
def self.sort_column(column, direction)
|
10
|
+
"#{Arel.sql(column)} #{sort_direction(direction)}"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rad_core_rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Oleksandr Poltavets, James Marrs
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-02-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -201,7 +201,7 @@ metadata:
|
|
201
201
|
homepage_uri: https://github.com/jamesmarrs/rad-core-rails
|
202
202
|
source_code_uri: https://rubygems.org/gems/rad_core_rails
|
203
203
|
changelog_uri: https://rubygems.org/gems/rad_core_rails
|
204
|
-
post_install_message:
|
204
|
+
post_install_message:
|
205
205
|
rdoc_options: []
|
206
206
|
require_paths:
|
207
207
|
- lib
|
@@ -217,7 +217,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
217
217
|
version: '0'
|
218
218
|
requirements: []
|
219
219
|
rubygems_version: 3.1.2
|
220
|
-
signing_key:
|
220
|
+
signing_key:
|
221
221
|
specification_version: 4
|
222
222
|
summary: RadCoreRails
|
223
223
|
test_files: []
|