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 +4 -4
- data/lib/search_redux/rdbms/postgres.rb +8 -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: ce847ad403cbeee48d3b05f898e3dbe7546a7adc8c867bebabb4f2719b4195a9
|
4
|
+
data.tar.gz: cda46990f26ce3f3b81ff2f84476c1b1d9b7042475a6432b84b18d8bce918a35
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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}),
|
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}) @@
|
25
|
+
return "to_tsvector('english', #{column_name}) @@ to_tsquery(:q)"
|
21
26
|
}
|
22
27
|
|
23
28
|
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.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-
|
11
|
+
date: 2023-03-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|