search_redux 1.0.1 → 1.0.2

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: 2e38a9e09ad47bb9223780ed4b5abe6f6dba9c1d3436e79942fa92b82787e241
4
+ data.tar.gz: 0caf36ef1c0d6cdd2acadc8e2edefebf3c3264f644d4c8960ccacd5c51e5de6d
5
5
  SHA512:
6
- metadata.gz: 2bb28270a7d91abe411f90fa4756cc89ad4fae1cd914e9af89bb19edeb7a71a5b7e38e571316f5f7fdce29e47414acf4bf2ba6d1d668737506024af27e8ca618
7
- data.tar.gz: 834408dbfe6ea11d5b9c1401126938aff038fa2203c1037a176867a98d64137116f3b225229a4b47909e363f382a8c5b59dbe1fe61b0403c8df6190cafa3368f
6
+ metadata.gz: 28b3fdad95a054363fd2608a845f70c0a4f2d11b55b8e97fa5f747bc5f70b5e81f386e434b07cecad761c7560c1fcfbf52de60bcb8eed49fbaf1abf40dfed2db
7
+ data.tar.gz: 7cf80dae2a11c2497451ce5e1170b0884a623a854c40c9b84ab35d6f8569d77822c457297d2cf31acbef35e2ba2f9d6321f000bf37f154cd64c4cbbf96df6f6e
@@ -4,20 +4,24 @@ 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
+ query.split.map { |ts| "#{ts}:*" }.join(" & ")
16
+ end
17
+
14
18
  def rank_sql(rank_column, query)
15
- "ts_rank(to_tsvector(#{rank_column}), plainto_tsquery('#{query}')) desc"
19
+ "ts_rank(to_tsvector(#{rank_column}), to_tsquery('#{query}')) desc"
16
20
  end
17
21
 
18
22
  def search_sql(columns)
19
23
  template = ->(column_name) {
20
- return "to_tsvector('english', #{column_name}) @@ plainto_tsquery(:q)"
24
+ return "to_tsvector('english', #{column_name}) @@ to_tsquery(:q)"
21
25
  }
22
26
 
23
27
  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.2' 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.2
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-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord