like_query 0.3.0 → 0.3.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/README.md +19 -0
- data/lib/like_query/formatter.rb +1 -1
- data/lib/like_query/model_extensions.rb +7 -4
- data/lib/like_query/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: 4acb76ba7e99c858ec318cb2f52d82e3c063d53941775c5b18d34cb084f8d624
|
4
|
+
data.tar.gz: 619ed012558607d25ef0bef7766a96b5ee1ec9923185d6ff7c4dfda0a62ee08c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5846f20fa64023168c9f4468dadb90aa5f73ea131b63eae29e6ad9b06b750d4e5b9d38cd670accdad72be12eb2940a4af11dfac96c865fda0c7cfcc3ccc71aad
|
7
|
+
data.tar.gz: 66c59b0de6ebaa45fe6d237561c88a6e266575dade903dacbd6880df001cc4f172631a26040e9a7322f227f6bee1d787b300d8e9d2e19abb44211dd2d4510e8e
|
data/README.md
CHANGED
@@ -106,6 +106,25 @@ Book.like('Nelson 3.4..8', [:title, :price])
|
|
106
106
|
# => find books where title includes "Nelson" and price (must be number column) is between 3.4 and 8
|
107
107
|
```
|
108
108
|
|
109
|
+
**Column specific search**
|
110
|
+
|
111
|
+
```ruby
|
112
|
+
Book.like('title:history', [:title, :price])
|
113
|
+
# => find books where title includes "history"
|
114
|
+
|
115
|
+
Book.like('author.name:marc', [{author: [:name]}])
|
116
|
+
# => find books where author.name includes "marc"
|
117
|
+
```
|
118
|
+
|
119
|
+
There is a helper for allowing the user translating the column names:
|
120
|
+
|
121
|
+
```ruby
|
122
|
+
LikeQuery::Formatter.translate_columns('one N:two', [['n','name']], case_sensitive: false)
|
123
|
+
# => 'one name:two'
|
124
|
+
# case_sensitive: Default is true
|
125
|
+
```
|
126
|
+
Only upper and lower chars (if case-insensitive), point, underscore, and no German-Umlaute are allowed on the column-key
|
127
|
+
|
109
128
|
**Class LikeQuery::Collect**
|
110
129
|
|
111
130
|
```ruby
|
data/lib/like_query/formatter.rb
CHANGED
@@ -9,7 +9,7 @@ module LikeQuery
|
|
9
9
|
def self.translate_columns(search_string, column_translations, case_sensitive: true)
|
10
10
|
search_string.split(' ').map do |str|
|
11
11
|
|
12
|
-
reg = (case_sensitive ? /^[a-z_]+(?=:)/ : /^[a-zA-Z_]+(?=:)/)
|
12
|
+
reg = (case_sensitive ? /^[a-z_\.]+(?=:)/ : /^[a-zA-Z_\.]+(?=:)/)
|
13
13
|
|
14
14
|
column = if case_sensitive
|
15
15
|
str.match(reg)
|
@@ -55,7 +55,8 @@ module LikeQuery
|
|
55
55
|
|
56
56
|
end
|
57
57
|
|
58
|
-
|
58
|
+
__q = q.compact
|
59
|
+
queries.push("(#{__q.join(' OR ')})") if __q.present?
|
59
60
|
end
|
60
61
|
|
61
62
|
if associations.present?
|
@@ -100,7 +101,7 @@ module LikeQuery
|
|
100
101
|
|
101
102
|
def format_string_element(str)
|
102
103
|
|
103
|
-
column = str.match(/^[a-z_]+(?=:)/)
|
104
|
+
column = str.match(/^[a-z_\.]+(?=:)/)
|
104
105
|
_str = (column ? str.match(/(?<=:)[\s\S]+/) : str).to_s
|
105
106
|
match_number = _str.match(/^(\d+(?:\.\d+)?)$/)
|
106
107
|
match_range = _str.match(/^(\d+(?:\.\d+)?)(\.\.)(\d+(?:\.\d+)?)$/)
|
@@ -121,7 +122,7 @@ module LikeQuery
|
|
121
122
|
{}
|
122
123
|
end
|
123
124
|
res[:string] = _str
|
124
|
-
res[:column] = column.to_s
|
125
|
+
res[:column] = column.to_s if column
|
125
126
|
res
|
126
127
|
end
|
127
128
|
|
@@ -135,7 +136,9 @@ module LikeQuery
|
|
135
136
|
end
|
136
137
|
arel = base_object.arel_table[schema_column]
|
137
138
|
|
138
|
-
|
139
|
+
col = (association ? [association.name, schema_column.to_s].join('.') : schema_column.to_s)
|
140
|
+
|
141
|
+
if !search_string[:column] || col == search_string[:column]
|
139
142
|
if search_string[:float_from] && [:float, :decimal, :big_decimal, :integer, :bigint].include?(type)
|
140
143
|
|
141
144
|
q = arel.between(search_string[:float_from]..search_string[:float_until]).to_sql
|
data/lib/like_query/version.rb
CHANGED