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 +4 -4
- data/lib/search_redux/rdbms/postgres.rb +7 -3
- data/lib/search_redux/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: 2e38a9e09ad47bb9223780ed4b5abe6f6dba9c1d3436e79942fa92b82787e241
|
4
|
+
data.tar.gz: 0caf36ef1c0d6cdd2acadc8e2edefebf3c3264f644d4c8960ccacd5c51e5de6d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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}),
|
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}) @@
|
24
|
+
return "to_tsvector('english', #{column_name}) @@ to_tsquery(:q)"
|
21
25
|
}
|
22
26
|
|
23
27
|
columns.map { |c| template.call(c) }.join(' OR ')
|
data/lib/search_redux/version.rb
CHANGED
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.
|
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-
|
11
|
+
date: 2023-03-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|