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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e1b996e263fc5f1f6a29cdbc32acb1dcd89c7dbbe70c73dcd71fee38d4801232
4
- data.tar.gz: 7c55dd7db44b97ca4659558be7ad64613f473b7d7f7121991330a7a10e3d1df7
3
+ metadata.gz: dec7afc185ebe9baa4de931681c27b4718d138126111fbeb1467819b958e5883
4
+ data.tar.gz: 21d49c730ea6064c0c6ba1a1993dd24e09273463e082d5a1d57fff9fe2ad17a9
5
5
  SHA512:
6
- metadata.gz: fb649274052909b8d569857ce5df8757da792ca4e50a5a45174dd8d1b368f6004adbe2b91e68713a91ba0f962674161653f2f917ca1b122fb605243a0940ea7c
7
- data.tar.gz: 931537bd72fd62c9d624ba13623a43bfaddbb1c80211dd9139be04264ba2943e98e8287e3898de8374b73fe24e66b80999a07e2995ff83d0dd9e763e1f8042d6
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
@@ -19,3 +19,5 @@ gem 'rubocop'
19
19
  gem 'rubocop-rails'
20
20
  gem 'rubocop-rake'
21
21
  gem 'rubocop-rspec'
22
+
23
+ gem 'ruby-lsp'
data/README.md CHANGED
@@ -89,14 +89,23 @@ class ArticleSource < MySQL::Search::Source
89
89
  end
90
90
  ```
91
91
 
92
- **Available Formatters **
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
- - **Your formatters**. Check the [source code](lib/mysql/search/utils/formatter.rb) for more details.
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
@@ -2,8 +2,8 @@
2
2
 
3
3
  require 'bundler/gem_tasks'
4
4
 
5
- load 'lib/tasks/actualize.rake'
6
- load 'lib/tasks/reindex.rake'
5
+ load 'tasks/mysql/search/actualize.rake'
6
+ load 'tasks/mysql/search/reindex.rake'
7
7
 
8
8
  require 'rspec/core/rake_task'
9
9
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = 'activerecord-mysql-search'
5
- spec.version = '0.1.2'
5
+ spec.version = '0.2.0'
6
6
  spec.authors = ['Daydream Unicorn GmbH & Co. KG']
7
7
  spec.email = ['hello@daydreamunicorn.com']
8
8
 
@@ -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
 
@@ -7,8 +7,8 @@ module MySQL
7
7
  railtie_name :mysql_search
8
8
 
9
9
  rake_tasks do
10
- path = File.expand_path(__dir__)
11
- Dir.glob("#{path}/../../tasks/**/*.rake").each { |f| load f }
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
- TextNormalizer.normalize(value.to_s)
35
+ value
30
36
  end
31
37
 
32
38
  def calendar_week
@@ -1,7 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative 'utils/formatter'
4
- require_relative 'utils/text_normalizer'
5
4
  require_relative 'utils/duration_parser'
6
5
 
7
6
  module MySQL
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.1.2
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/utils/text_normalizer.rb
59
- - lib/tasks/actualize.rake
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