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 +4 -4
- data/CHANGELOG.md +2 -0
- data/Gemfile.lock +9 -9
- data/lib/pg_search_multiple_highlight/tsearch.rb +3 -16
- data/lib/pg_search_multiple_highlight/version.rb +1 -1
- 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: 1102e138d69bc59b4fbcb29b470530af8ffb8111e9bc2035cb80bea3c4909333
|
4
|
+
data.tar.gz: d6b092296fc0ecdae01cbb5308dce5a77915643d4d75ca0a385311873564b922
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 936c9289a3ee0752e306a5c63c7ee4bf4e10fe7c9153d6314175a7724f6c17fb56cd14cfe4c22e0d89ab8b84146536b6188bf78ae35aa422d380f8aff8cb832b
|
7
|
+
data.tar.gz: f63fb8d7697b3dc76be7a1db7561681cb2dcf4a7dd7fcbf90acb3478488cf84d8bfdeeca4382c3b18a73e4b62c8fb9e0cb9564d1e4711f0160f8f46181a44797
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,18 +1,18 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
pg_search_multiple_highlight (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.
|
11
|
-
activesupport (= 7.0.
|
12
|
-
activerecord (7.0.
|
13
|
-
activemodel (= 7.0.
|
14
|
-
activesupport (= 7.0.
|
15
|
-
activesupport (7.0.
|
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.
|
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.
|
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
|
-
|
30
|
+
split_words = query.split(/\s+/).map { |word| Regexp.escape(word) }
|
31
31
|
|
32
|
-
|
32
|
+
regex = Regexp.new("\\b(#{split_words.join("|")})\\b", Regexp::IGNORECASE)
|
33
33
|
|
34
|
-
|
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
|
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.
|
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:
|
11
|
+
date: 2024-01-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pg_search
|