pg_textsearch 0.1.5 → 0.1.6

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: b69df64862d16087f26e8ac10958731b9c25a93817353c9b1eaa3aaed9f105ba
4
- data.tar.gz: f383ee7ab07e467dc735e7194fe839e5977fce9e1cc712c7cffcea75b8379cd7
3
+ metadata.gz: 3681d0d4400114ac5d0c519c466bbf1b7bf23bc33ab3889f92a246380372da9c
4
+ data.tar.gz: 10558790e5201e11ec236b07cda132903698c7af0156c52b58e5d11ae6318dfe
5
5
  SHA512:
6
- metadata.gz: 13443e933e3c936bfd2d2eee2270f9461ce6d5d4e6201d7398d5d3758a65bd3e5c69ff65ee2d5de977f7c42269769f69caf9185993e33db403fbcd5db78b8739
7
- data.tar.gz: 910b15ce2ef6bdaa8a4a2e9aa5c8cfda6f391fa2942532cf6b596dcddeb0f039f872f4c7c8154e73791aedfb0b7a8602db1c2de8d13941e7548e3e420866a847
6
+ metadata.gz: 246e9edf704ef5a5c027702f5fccd1bab6cd34beb820dbe573fbd7cf6f64c90616a3cf1877a36e162f4d168f2084d09e8b809de50b6fa642631dc92388d6e4aa
7
+ data.tar.gz: cf8df0694a4e8ea834d2a3be6c9d55ab5a8cf95a1f05f6ff1a25cc9df4b69b46675f409f46d82ce44f80d0d1bdf9361d6c3719e3a0d4201ea941dd705f9f93d6
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.1.6] - 2026-11-19
4
+
5
+ ### Fixed
6
+ - **#22**: `prefix: true` filter now quotes/escapes tsquery lexemes in the `@@ to_tsquery(...)` path, preventing `PG::SyntaxError` for inputs containing tsquery operators or punctuation (e.g. `:`, `&`, parentheses).
7
+
3
8
  ## [0.1.5] - 2026-11-19
4
9
 
5
10
  ### Fixed
@@ -143,12 +143,11 @@ module PgTextsearch
143
143
  end
144
144
 
145
145
  def bm25_prefix_filter_sql(target_sql, query, options)
146
- words = query.to_s.split
147
- words = words.map { |w| "#{w}:*" }
146
+ lexemes = query.to_s.split.map { |w| "'#{w.gsub("'", "''")}':*" }
148
147
  tsquery_text = if options[:any_word]
149
- words.join(" | ")
148
+ lexemes.join(" | ")
150
149
  else
151
- words.join(" & ")
150
+ lexemes.join(" & ")
152
151
  end
153
152
 
154
153
  config = options[:text_config] || options[:ts_config] || "english"
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PgTextsearch
4
- VERSION = "0.1.5"
4
+ VERSION = "0.1.6"
5
5
  end
data/test/issues_test.rb CHANGED
@@ -35,7 +35,7 @@ class PgTextsearchIssuesTest < Minitest::Test # rubocop:disable Metrics/ClassLen
35
35
  # Issue #1: prefix: true should filter via @@ to_tsquery (supports :* expansion)
36
36
  def test_prefix_applies_to_where_clause
37
37
  sql = IssueProductNoDefault.bm25_search(:search_text, "iph", index: :idx, prefix: true).to_sql
38
- assert_match(/WHERE .*@@ to_tsquery\('english', 'iph:\*'\)/m, sql)
38
+ assert_match(/WHERE .*@@ to_tsquery\('english', '''iph'':\*'\)/m, sql)
39
39
  assert_match(/ORDER BY .*to_bm25query\('iph:\*', 'idx'\)/m, sql)
40
40
  end
41
41
 
@@ -203,4 +203,15 @@ class PgTextsearchIssuesTest < Minitest::Test # rubocop:disable Metrics/ClassLen
203
203
  assert_match(/to_bm25query\(unaccent\('café'\), 'idx'\)/, sql)
204
204
  refute_match(/to_bm25query\('unaccent/, sql)
205
205
  end
206
+
207
+ # Issue #22: prefix filter should quote lexemes in to_tsquery input
208
+ def test_prefix_filter_quotes_tsquery_lexemes
209
+ sql = IssueProductNoDefault.bm25_search(:search_text, "rock & roll", index: :idx, prefix: true).to_sql
210
+ assert_match(/@@ to_tsquery\('english', '''rock'':\* & ''&'':\* & ''roll'':\*'\)/, sql)
211
+ end
212
+
213
+ def test_prefix_filter_quotes_lexemes_with_special_chars
214
+ sql = IssueProductNoDefault.bm25_search(:search_text, "a:b (x)", index: :idx, prefix: true).to_sql
215
+ assert_match(/@@ to_tsquery\('english', '''a:b'':\* & ''\(x\)'':\*'\)/, sql)
216
+ end
206
217
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pg_textsearch
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aboobacker MK