eluvia-base 3.37.1 → 3.38.0
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/lib/eluvia/active_record/filtering.rb +16 -6
- data/lib/eluvia/active_record/filters_model.rb +13 -4
- data/lib/eluvia/base/config.rb +7 -0
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 5504d4c333c7a6ec87a0752207016b6ba9e9b4b6627a1de04afde70b755a907e
|
|
4
|
+
data.tar.gz: 0d666609cd85101862b53301e4a31f08f99719b02164ddb2c43aff83edb4a698
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 1da58aaaef1574dc606baa60d941ac243554808301a5a94d4ccea92b21c65375895a3e66c8b749dc181d22c8d5da50955e0c34840d1818a0001a5ba4821f3f74
|
|
7
|
+
data.tar.gz: 9ca68b4c7e319abbb95228e0639c1d13c0158571491fd3e355363e5cf1237abac9cf5e83513f5dc70da3a86ed9b4768bd83c47ccc6f23bbc4a6c42ac42b752fe
|
|
@@ -365,19 +365,29 @@ module Eluvia
|
|
|
365
365
|
return scope if search_term.blank?
|
|
366
366
|
return scope if filters_model_class.nil?
|
|
367
367
|
|
|
368
|
-
|
|
369
|
-
return scope if
|
|
368
|
+
search_attrs = filters_model_class.search_attrs
|
|
369
|
+
return scope if search_attrs.empty?
|
|
370
370
|
|
|
371
371
|
search_term.split.each do |word|
|
|
372
|
-
sql_parts =
|
|
373
|
-
col =
|
|
374
|
-
"lower(
|
|
372
|
+
sql_parts = search_attrs.map do |attr_name|
|
|
373
|
+
col = attr_name.is_a?(Symbol) ? "#{self.table_name}.#{attr_name}" : attr_name.to_s
|
|
374
|
+
"lower(#{normalize_search_expression(col)}) LIKE ('%' || lower(#{normalize_search_expression('?')}) || '%')"
|
|
375
375
|
end
|
|
376
|
-
scope = scope.where(sql_parts.join(' OR '), *([word] *
|
|
376
|
+
scope = scope.where(sql_parts.join(' OR '), *([word] * search_attrs.size))
|
|
377
377
|
end
|
|
378
378
|
scope
|
|
379
379
|
end
|
|
380
380
|
|
|
381
|
+
# Wraps a search expression in `trim` and, when enabled via config, `unaccent`.
|
|
382
|
+
# `unaccent` requires the PostgreSQL `unaccent` extension to be enabled in the database.
|
|
383
|
+
def normalize_search_expression(expr)
|
|
384
|
+
if Eluvia::Base::Config.search_use_unaccent
|
|
385
|
+
"unaccent(trim(#{expr}))"
|
|
386
|
+
else
|
|
387
|
+
"trim(#{expr})"
|
|
388
|
+
end
|
|
389
|
+
end
|
|
390
|
+
|
|
381
391
|
def apply_filters_for_filter_attrs(scope, params, parent: nil, current_user: nil)
|
|
382
392
|
return scope unless is_filters_model?(filters_model_class)
|
|
383
393
|
filters_model_class.filter_attrs.each do |attr_spec|
|
|
@@ -12,11 +12,20 @@ module Eluvia
|
|
|
12
12
|
|
|
13
13
|
class_methods do
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
# Declares (with arguments) or returns (without arguments) the attributes searched by the
|
|
16
|
+
# generic `search` param. Each attribute is compared with a case-insensitive substring match,
|
|
17
|
+
# OR-combined across all of them.
|
|
18
|
+
#
|
|
19
|
+
# @example
|
|
20
|
+
# class User::Filters
|
|
21
|
+
# include Eluvia::ActiveRecord::FiltersModel
|
|
22
|
+
# search_attrs :first_name, :last_name, :email
|
|
23
|
+
# end
|
|
24
|
+
def search_attrs(*attr_names)
|
|
25
|
+
if attr_names.empty?
|
|
26
|
+
@_search_attrs ||= []
|
|
18
27
|
else
|
|
19
|
-
@
|
|
28
|
+
@_search_attrs = attr_names.flatten
|
|
20
29
|
end
|
|
21
30
|
end
|
|
22
31
|
|
data/lib/eluvia/base/config.rb
CHANGED
|
@@ -33,6 +33,13 @@ module Eluvia
|
|
|
33
33
|
mattr_accessor :uuid_seed
|
|
34
34
|
@@uuid_seed = '12345678-1234-1234-1234-1234567890ab'
|
|
35
35
|
|
|
36
|
+
# Whether the generic `search` param should wrap compared columns in the PostgreSQL `unaccent`
|
|
37
|
+
# function, making the search insensitive to diacritics. Requires the `unaccent` extension to be
|
|
38
|
+
# enabled in the database (`enable_extension 'unaccent'`). When false, search is only
|
|
39
|
+
# case-insensitive. (default: true)
|
|
40
|
+
mattr_accessor :search_use_unaccent
|
|
41
|
+
@@search_use_unaccent = true
|
|
42
|
+
|
|
36
43
|
end
|
|
37
44
|
end
|
|
38
45
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: eluvia-base
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 3.
|
|
4
|
+
version: 3.38.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Matěj Outlý
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-
|
|
11
|
+
date: 2026-09-14 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rest-client
|