activerecord-mysql-search 0.1.2 → 0.2.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/CHANGELOG.md +18 -0
- data/Gemfile +2 -0
- data/README.md +11 -2
- data/Rakefile +2 -2
- data/activerecord-mysql-search.gemspec +1 -1
- data/lib/mysql/search/queries/full_text_search_query.rb +0 -1
- data/lib/mysql/search/railtie.rb +2 -2
- data/lib/mysql/search/utils/formatter.rb +8 -2
- data/lib/mysql/search/utils.rb +0 -1
- data/lib/mysql/search.rb +4 -0
- metadata +3 -4
- data/lib/mysql/search/utils/text_normalizer.rb +0 -16
- /data/lib/tasks/{actualize.rake → mysql/search/actualize.rake} +0 -0
- /data/lib/tasks/{reindex.rake → mysql/search/reindex.rake} +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dec7afc185ebe9baa4de931681c27b4718d138126111fbeb1467819b958e5883
|
4
|
+
data.tar.gz: 21d49c730ea6064c0c6ba1a1993dd24e09273463e082d5a1d57fff9fe2ad17a9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 706aa3813e15aa8814ab3f2c908de266db1ab65d09a7b96f00bc6234cabcc6579dd8413db97bcd6b4754c6375e1464156dcc5c930345cc193eaa532ee4794f03
|
7
|
+
data.tar.gz: 0ce9414a415f48805420657fbc14c9e7b7f7111d2e4641dd6b127601c5100915ffaba100fea62023c9a0735d044d9362e436761e39f5c98e6632fdf3d324528b
|
data/CHANGELOG.md
CHANGED
@@ -3,3 +3,21 @@
|
|
3
3
|
## [0.1.0] - 2025-07-22
|
4
4
|
|
5
5
|
- Initial release
|
6
|
+
|
7
|
+
## [0.1.1] - 2025-08-05
|
8
|
+
|
9
|
+
- Fixes load paths to rake tasks
|
10
|
+
|
11
|
+
## [0.1.2] - 2025-08-12
|
12
|
+
|
13
|
+
- Removes code of conduct
|
14
|
+
|
15
|
+
## [0.1.3] - 2025-08-06
|
16
|
+
|
17
|
+
- Move rake tasks to the proper place + explicit tasks load
|
18
|
+
|
19
|
+
## [0.2.0] - 2025-09-25
|
20
|
+
|
21
|
+
- Removes text normalization from default `:text` formatter
|
22
|
+
- Search term passed as argument to the scope `.full_text_search` is not pre-normalized anymore
|
23
|
+
- Adds `register_format` method to register custom formatters
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -89,14 +89,23 @@ class ArticleSource < MySQL::Search::Source
|
|
89
89
|
end
|
90
90
|
```
|
91
91
|
|
92
|
-
|
92
|
+
#### Available Formatters
|
93
93
|
|
94
94
|
- **`:text`** - Extracts text content from the field
|
95
95
|
- **`:date`** - Formats dates using the configured date format (e.g., "12.01.2025", format is configurable)
|
96
96
|
- **`:calendar_week`** - Extracts calendar week information (e.g., "week 42", format is configurable)
|
97
97
|
- **`Proc`** - Custom extraction logic with access to the attribute value
|
98
98
|
- **Nested Associations** - Supports nested associations
|
99
|
-
|
99
|
+
|
100
|
+
#### Registering new formatters
|
101
|
+
|
102
|
+
You can register new formatters using the `register_format` method:
|
103
|
+
|
104
|
+
```ruby
|
105
|
+
MySQL::Search.configure do |config|
|
106
|
+
config.register_format(:upcase) { |value| value.to_s.upcase }
|
107
|
+
end
|
108
|
+
```
|
100
109
|
|
101
110
|
### Step 6: Index Existing Data
|
102
111
|
|
data/Rakefile
CHANGED
@@ -59,7 +59,6 @@ module MySQL
|
|
59
59
|
private
|
60
60
|
|
61
61
|
def search_expression(search_term, search_column)
|
62
|
-
search_term = ::MySQL::Search::Utils::TextNormalizer.normalize(search_term)
|
63
62
|
search_indices = ::MySQL::Search.search_index_class_name.constantize.arel_table
|
64
63
|
search_columns = Array.wrap(search_column).map { |col| search_indices[col] }
|
65
64
|
|
data/lib/mysql/search/railtie.rb
CHANGED
@@ -7,8 +7,8 @@ module MySQL
|
|
7
7
|
railtie_name :mysql_search
|
8
8
|
|
9
9
|
rake_tasks do
|
10
|
-
|
11
|
-
|
10
|
+
load 'tasks/mysql/search/actualize.rake'
|
11
|
+
load 'tasks/mysql/search/reindex.rake'
|
12
12
|
end
|
13
13
|
|
14
14
|
generators do
|
@@ -7,6 +7,12 @@ module MySQL
|
|
7
7
|
class Formatter
|
8
8
|
attr_reader :value, :formatter
|
9
9
|
|
10
|
+
def self.register(name, &block)
|
11
|
+
define_method(name) do
|
12
|
+
block.call(value)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
10
16
|
def initialize(value, formatter)
|
11
17
|
if formatter.instance_of?(Proc)
|
12
18
|
@value = formatter.call(value)
|
@@ -20,13 +26,13 @@ module MySQL
|
|
20
26
|
end
|
21
27
|
|
22
28
|
def format
|
23
|
-
formatter ? send(formatter) : value
|
29
|
+
(formatter ? send(formatter) : value).to_s.strip
|
24
30
|
end
|
25
31
|
|
26
32
|
private
|
27
33
|
|
28
34
|
def text
|
29
|
-
|
35
|
+
value
|
30
36
|
end
|
31
37
|
|
32
38
|
def calendar_week
|
data/lib/mysql/search/utils.rb
CHANGED
data/lib/mysql/search.rb
CHANGED
@@ -27,6 +27,10 @@ module MySQL
|
|
27
27
|
mattr_accessor :calendar_week_format, default: 'week %V'
|
28
28
|
mattr_accessor :date_format, default: '%d.%m.%Y'
|
29
29
|
|
30
|
+
def register_format(name, &)
|
31
|
+
Utils::Formatter.register(name, &)
|
32
|
+
end
|
33
|
+
|
30
34
|
def search_index_class
|
31
35
|
@search_index_class ||= search_index_class_name.constantize
|
32
36
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activerecord-mysql-search
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daydream Unicorn GmbH & Co. KG
|
@@ -55,9 +55,8 @@ files:
|
|
55
55
|
- lib/mysql/search/utils.rb
|
56
56
|
- lib/mysql/search/utils/duration_parser.rb
|
57
57
|
- lib/mysql/search/utils/formatter.rb
|
58
|
-
- lib/mysql/search/
|
59
|
-
- lib/tasks/
|
60
|
-
- lib/tasks/reindex.rake
|
58
|
+
- lib/tasks/mysql/search/actualize.rake
|
59
|
+
- lib/tasks/mysql/search/reindex.rake
|
61
60
|
homepage: https://github.com/ddunicorn/activerecord-mysql-search.rubygem/blob/main/README.md
|
62
61
|
licenses:
|
63
62
|
- MIT
|
@@ -1,16 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module MySQL
|
4
|
-
module Search
|
5
|
-
module Utils
|
6
|
-
# Normalizes text by removing non-alphanumeric characters, except for spaces and hyphens.
|
7
|
-
class TextNormalizer
|
8
|
-
REGEXP = /[[:alnum:][:blank:]+\-*~<>()"@\.]/
|
9
|
-
|
10
|
-
def self.normalize(value)
|
11
|
-
value.to_s.scan(REGEXP).join.squish
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
File without changes
|
File without changes
|