pg_search_multiple_highlight 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 513c09da1edb45a90f08b99b0363e309e3ccd7c825ee45171057cd123d16f4ea
4
- data.tar.gz: 1ee17e8f55e968b068f42207aa4f95f18161f37471e90a7fe1b365c7292d7fa3
3
+ metadata.gz: 1102e138d69bc59b4fbcb29b470530af8ffb8111e9bc2035cb80bea3c4909333
4
+ data.tar.gz: d6b092296fc0ecdae01cbb5308dce5a77915643d4d75ca0a385311873564b922
5
5
  SHA512:
6
- metadata.gz: e6189fefdcd3b89c358ccde3d7fe4eb14ea7b681dcaa961923bb92fb7b5ee0b4d4c40210e8b6d30ee4f402b8344dc0d7fc3613a8916886712249b0312f212804
7
- data.tar.gz: 18978a57b1370ded738dc5ca49c6f35da12cb2a17475bf64ce07ebf71ad745df9f06d72371ebd6eb697136b54fc23d57ed3badfcb48635778eb4f9741dc5a140
6
+ metadata.gz: 936c9289a3ee0752e306a5c63c7ee4bf4e10fe7c9153d6314175a7724f6c17fb56cd14cfe4c22e0d89ab8b84146536b6188bf78ae35aa422d380f8aff8cb832b
7
+ data.tar.gz: f63fb8d7697b3dc76be7a1db7561681cb2dcf4a7dd7fcbf90acb3478488cf84d8bfdeeca4382c3b18a73e4b62c8fb9e0cb9564d1e4711f0160f8f46181a44797
data/CHANGELOG.md CHANGED
@@ -1,5 +1,7 @@
1
1
  ## [Released]
2
2
 
3
+ ## [0.3.0] - 2024-01-28
4
+ - Fix N+1 issue in highlighting results
3
5
  ## [0.2.0] - 2023-08-17
4
6
  - Improve integration with scope options
5
7
  ## [0.1.0] - 2023-08-08
data/Gemfile.lock CHANGED
@@ -1,18 +1,18 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- pg_search_multiple_highlight (0.2.0)
4
+ pg_search_multiple_highlight (0.3.0)
5
5
  pg_search (~> 2.3)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
- activemodel (7.0.6)
11
- activesupport (= 7.0.6)
12
- activerecord (7.0.6)
13
- activemodel (= 7.0.6)
14
- activesupport (= 7.0.6)
15
- activesupport (7.0.6)
10
+ activemodel (7.0.7.1)
11
+ activesupport (= 7.0.7.1)
12
+ activerecord (7.0.7.1)
13
+ activemodel (= 7.0.7.1)
14
+ activesupport (= 7.0.7.1)
15
+ activesupport (7.0.7.1)
16
16
  concurrent-ruby (~> 1.0, >= 1.0.2)
17
17
  i18n (>= 1.6, < 2)
18
18
  minitest (>= 5.1)
@@ -24,7 +24,7 @@ GEM
24
24
  bundler (>= 1.2.0, < 3)
25
25
  thor (~> 1.0)
26
26
  byebug (11.1.3)
27
- concurrent-ruby (1.2.2)
27
+ concurrent-ruby (1.2.3)
28
28
  database_cleaner (2.0.2)
29
29
  database_cleaner-active_record (>= 2, < 3)
30
30
  database_cleaner-active_record (2.1.0)
@@ -39,7 +39,7 @@ GEM
39
39
  json (2.6.3)
40
40
  language_server-protocol (3.17.0.3)
41
41
  lint_roller (1.1.0)
42
- minitest (5.19.0)
42
+ minitest (5.21.2)
43
43
  parallel (1.23.0)
44
44
  parser (3.2.2.3)
45
45
  ast (~> 2.4.1)
@@ -27,24 +27,11 @@ module PgSearch
27
27
  end
28
28
 
29
29
  def highlight_multiple_fields(text, query)
30
- tsquery = ActiveRecord::Base.connection.quote(query)
30
+ split_words = query.split(/\s+/).map { |word| Regexp.escape(word) }
31
31
 
32
- dictionary = @options[:dictionary] || "simple"
32
+ regex = Regexp.new("\\b(#{split_words.join("|")})\\b", Regexp::IGNORECASE)
33
33
 
34
- raw_options = @options[:multiple_highlight]
35
-
36
- scope_options = raw_options.map { |key, value| "#{key}=#{value}" }.join(", ")
37
-
38
- sanitized_sql = ActiveRecord::Base.send(
39
- :sanitize_sql_array, [
40
- "SELECT ts_headline(
41
- ?, to_tsquery('#{dictionary}', ?),
42
- '#{scope_options}'
43
- ) AS highlighted_text",
44
- text, tsquery
45
- ]
46
- )
47
- ActiveRecord::Base.connection.execute(sanitized_sql).first["highlighted_text"]
34
+ text.gsub(regex) { |match| "<mark>#{match}</mark>" }
48
35
  end
49
36
  end
50
37
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PgSearchMultipleHighlight
4
- VERSION = "0.2.0"
4
+ VERSION = "0.3.0"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pg_search_multiple_highlight
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Suleyman Musayev
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-08-17 00:00:00.000000000 Z
11
+ date: 2024-01-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pg_search