search_redux 1.0.1 → 1.0.3

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: 86700938a5c434f1ce72e73c04abb6989fec09942fd298020dce5339cf301c60
4
- data.tar.gz: 715e706619ed1f332137e3e10523b4a2b1c1602e3f101604003b3069781d35d9
3
+ metadata.gz: ce847ad403cbeee48d3b05f898e3dbe7546a7adc8c867bebabb4f2719b4195a9
4
+ data.tar.gz: cda46990f26ce3f3b81ff2f84476c1b1d9b7042475a6432b84b18d8bce918a35
5
5
  SHA512:
6
- metadata.gz: 2bb28270a7d91abe411f90fa4756cc89ad4fae1cd914e9af89bb19edeb7a71a5b7e38e571316f5f7fdce29e47414acf4bf2ba6d1d668737506024af27e8ca618
7
- data.tar.gz: 834408dbfe6ea11d5b9c1401126938aff038fa2203c1037a176867a98d64137116f3b225229a4b47909e363f382a8c5b59dbe1fe61b0403c8df6190cafa3368f
6
+ metadata.gz: 9bf739fb959eef39255ed45fb6db3c43df957c8cbc90ce6d870060f801d2928e576723bce508378c067017943871344d9fbe56933fd6c6e95cfe75c1f92ec341
7
+ data.tar.gz: 18f54b7457be50c66b89828343bcb3d38bd29b1488d7e1cd70bfbbf8ff776b4e18419ee4fab597f311a786b012ad479acbac7fd634012cdbd0171fb75d732e5d
@@ -4,20 +4,25 @@ module SearchRedux
4
4
  attr_accessor :sanitized_query
5
5
 
6
6
  def compatible_search(options)
7
- query = options[:query]
7
+ query = to_ts_query(options[:query])
8
8
  rank_query = rank_sql(options[:rank], query)
9
9
  search_query = search_sql(options[:columns])
10
10
 
11
11
  ->(obj) { obj.where(Arel.sql(search_query), q: Arel.sql(query)).order(Arel.sql(rank_query)) }
12
12
  end
13
13
 
14
+ def to_ts_query(query)
15
+ words = query.scan(/\s*("([^"]+)"|\w+)\s*/)&.flatten&.compact
16
+ words.map { |ts| "#{ts}:*" }.join(" & ")
17
+ end
18
+
14
19
  def rank_sql(rank_column, query)
15
- "ts_rank(to_tsvector(#{rank_column}), plainto_tsquery('#{query}')) desc"
20
+ "ts_rank(to_tsvector(#{rank_column}), to_tsquery('#{query}')) desc"
16
21
  end
17
22
 
18
23
  def search_sql(columns)
19
24
  template = ->(column_name) {
20
- return "to_tsvector('english', #{column_name}) @@ plainto_tsquery(:q)"
25
+ return "to_tsvector('english', #{column_name}) @@ to_tsquery(:q)"
21
26
  }
22
27
 
23
28
  columns.map { |c| template.call(c) }.join(' OR ')
@@ -1,3 +1,3 @@
1
1
  module SearchRedux
2
- VERSION = '1.0.1' unless defined? SearchRedux::VERSION
2
+ VERSION = '1.0.3' unless defined? SearchRedux::VERSION
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: search_redux
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marian Posaceanu
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-03-06 00:00:00.000000000 Z
11
+ date: 2023-03-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord