activerecord-mysql-search 0.2.1 → 0.2.3
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 +5 -0
- data/README.md +19 -1
- data/activerecord-mysql-search.gemspec +1 -1
- data/lib/mysql/search/extensions/arel_against.rb +13 -3
- data/lib/mysql/search/queries/boolean_full_text_search_query.rb +21 -0
- data/lib/mysql/search/searchable.rb +4 -0
- data/lib/mysql/search.rb +1 -0
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 19cb0101f1cfe861ccdf0defa71c17f4608e17e99e7428f5e5ad00aa2a646be5
|
|
4
|
+
data.tar.gz: 758c80b143460cc517d826af5fd701d19adbe46dddbec49aa1e245cf48f37201
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 5c0d1de1bdcf4d17b6b30826fcd7f38eb6f81410fe8d27794379e71d7b67cadb7d5c78f465ecc143bc0b7a23dbea022edefb44f90cf558e61791180b336aaf1d
|
|
7
|
+
data.tar.gz: 8c70d839e870efe25a3525baa34053e0b951bdb32b12ebc8c0e84fbc8ab52ca9a8658d68a4a4c9ddc6fcbff0a533b096745ed0ea9fd6aade945c30090d4cca5c
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
## [Unreleased]
|
|
2
2
|
|
|
3
|
+
## [0.2.3] - 2026-09-11
|
|
4
|
+
|
|
5
|
+
- Adds the `boolean_full_text_search` scope for MySQL boolean full-text queries
|
|
6
|
+
- Adds integration coverage for required (`+`) and excluded (`-`) search terms
|
|
7
|
+
|
|
3
8
|
## [0.2.1] - 2026-07-15
|
|
4
9
|
|
|
5
10
|
- Adds automatic loading of source classes on Rails startup via new `autoload_sources` configuration option (default: true)
|
data/README.md
CHANGED
|
@@ -121,6 +121,24 @@ This command populates the `search_indices` table with existing data from your m
|
|
|
121
121
|
results = Article.full_text_search("Ruby on Rails")
|
|
122
122
|
```
|
|
123
123
|
|
|
124
|
+
`full_text_search` uses MySQL's natural-language full-text search. Use
|
|
125
|
+
`boolean_full_text_search` when you need operators such as `+` for required
|
|
126
|
+
terms, `-` for excluded terms, or quotes and wildcards supported by MySQL's
|
|
127
|
+
boolean full-text syntax:
|
|
128
|
+
|
|
129
|
+
```ruby
|
|
130
|
+
results = Article.boolean_full_text_search("+Ruby +Rails -legacy")
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
Both scopes support searching one or more search-index columns:
|
|
134
|
+
|
|
135
|
+
```ruby
|
|
136
|
+
results = Product.boolean_full_text_search(
|
|
137
|
+
"+Ruby +Rails",
|
|
138
|
+
search_column: %i[content seller_extra]
|
|
139
|
+
)
|
|
140
|
+
```
|
|
141
|
+
|
|
124
142
|
**That’s it!** Users now get fast, scalable, and relevant search—no complex SQL, external services, or maintenance headaches.
|
|
125
143
|
|
|
126
144
|
## Advanced Scenarios: Multi-Column Search for Roles and Contexts
|
|
@@ -247,7 +265,7 @@ end
|
|
|
247
265
|
|
|
248
266
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
|
249
267
|
|
|
250
|
-
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update
|
|
268
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update `spec.version` in `activerecord-mysql-search.gemspec`, commit the change, and then run `bundle exec rake release`. This creates a git tag for the version, pushes the commit and tag, and pushes the `.gem` file to [rubygems.org](https://rubygems.org).
|
|
251
269
|
|
|
252
270
|
## Contributing
|
|
253
271
|
|
|
@@ -8,7 +8,9 @@ module Arel
|
|
|
8
8
|
class MySQL
|
|
9
9
|
def visit_Arel_Nodes_Against(node, collector) # rubocop:disable Naming/MethodName
|
|
10
10
|
visit(node.left, collector) << ' AGAINST ('
|
|
11
|
-
visit(node.right, collector)
|
|
11
|
+
visit(node.right, collector)
|
|
12
|
+
collector << ' IN BOOLEAN MODE' if node.boolean_mode?
|
|
13
|
+
collector << ')'
|
|
12
14
|
end
|
|
13
15
|
end
|
|
14
16
|
end
|
|
@@ -16,13 +18,21 @@ module Arel
|
|
|
16
18
|
module Nodes
|
|
17
19
|
# Represents the `AGAINST` clause used in MySQL full-text search queries.
|
|
18
20
|
class Against < Arel::Nodes::Matches
|
|
21
|
+
def initialize(left, right, boolean_mode: false)
|
|
22
|
+
super(left, right)
|
|
23
|
+
@boolean_mode = boolean_mode
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def boolean_mode?
|
|
27
|
+
@boolean_mode
|
|
28
|
+
end
|
|
19
29
|
end
|
|
20
30
|
end
|
|
21
31
|
|
|
22
32
|
# Adds a method to the `Arel::Nodes::Node` class to allow for full-text search queries.
|
|
23
33
|
module Predications
|
|
24
|
-
def against(other)
|
|
25
|
-
Arel::Nodes::Against.new(self, quoted_node(other))
|
|
34
|
+
def against(other, boolean_mode: false)
|
|
35
|
+
Arel::Nodes::Against.new(self, quoted_node(other), boolean_mode: boolean_mode)
|
|
26
36
|
end
|
|
27
37
|
end
|
|
28
38
|
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative 'full_text_search_query'
|
|
4
|
+
|
|
5
|
+
module MySQL
|
|
6
|
+
module Search
|
|
7
|
+
module Queries
|
|
8
|
+
# BooleanFullTextSearchQuery builds MySQL boolean full-text search queries.
|
|
9
|
+
class BooleanFullTextSearchQuery < FullTextSearchQuery
|
|
10
|
+
private
|
|
11
|
+
|
|
12
|
+
def search_expression(search_term, search_column)
|
|
13
|
+
search_indices = ::MySQL::Search.search_index_class_name.constantize.arel_table
|
|
14
|
+
search_columns = Array.wrap(search_column).map { |col| search_indices[col] }
|
|
15
|
+
|
|
16
|
+
Arel::Nodes::NamedFunction.new('MATCH', search_columns).against(search_term, boolean_mode: true)
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -18,6 +18,10 @@ module MySQL
|
|
|
18
18
|
scope :full_text_search, lambda { |search_term, search_column: :content|
|
|
19
19
|
::MySQL::Search::Queries::FullTextSearchQuery.new(self).call(search_term, search_column: search_column)
|
|
20
20
|
}
|
|
21
|
+
|
|
22
|
+
scope :boolean_full_text_search, lambda { |search_term, search_column: :content|
|
|
23
|
+
::MySQL::Search::Queries::BooleanFullTextSearchQuery.new(self).call(search_term, search_column: search_column)
|
|
24
|
+
}
|
|
21
25
|
end
|
|
22
26
|
end
|
|
23
27
|
end
|
data/lib/mysql/search.rb
CHANGED
|
@@ -7,6 +7,7 @@ require_relative 'search/searchable'
|
|
|
7
7
|
require_relative 'search/source'
|
|
8
8
|
require_relative 'search/queries/updated_sources_query'
|
|
9
9
|
require_relative 'search/queries/full_text_search_query'
|
|
10
|
+
require_relative 'search/queries/boolean_full_text_search_query'
|
|
10
11
|
require_relative 'search/updater'
|
|
11
12
|
require_relative 'search/utils'
|
|
12
13
|
|
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.2.
|
|
4
|
+
version: 0.2.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Daydream Unicorn GmbH & Co. KG
|
|
@@ -48,6 +48,7 @@ files:
|
|
|
48
48
|
- lib/mysql/search/jobs.rb
|
|
49
49
|
- lib/mysql/search/jobs/scheduled_updater_job.rb
|
|
50
50
|
- lib/mysql/search/jobs/updater_job.rb
|
|
51
|
+
- lib/mysql/search/queries/boolean_full_text_search_query.rb
|
|
51
52
|
- lib/mysql/search/queries/full_text_search_query.rb
|
|
52
53
|
- lib/mysql/search/queries/updated_sources_query.rb
|
|
53
54
|
- lib/mysql/search/railtie.rb
|