redi_search 6.3.0 → 6.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.ruby-version +1 -1
- data/lib/redi_search/aggregate/clauses/apply.rb +24 -0
- data/lib/redi_search/aggregate/clauses/filter.rb +22 -0
- data/lib/redi_search/aggregate/clauses/group_by.rb +79 -0
- data/lib/redi_search/aggregate/clauses/limit.rb +28 -0
- data/lib/redi_search/aggregate/clauses/load.rb +22 -0
- data/lib/redi_search/aggregate/clauses/sort_by.rb +43 -0
- data/lib/redi_search/aggregate/clauses/verbatim.rb +17 -0
- data/lib/redi_search/aggregate/reducers/average.rb +26 -0
- data/lib/redi_search/aggregate/reducers/count.rb +23 -0
- data/lib/redi_search/aggregate/reducers/distinct_count.rb +26 -0
- data/lib/redi_search/aggregate/reducers/distinctish_count.rb +26 -0
- data/lib/redi_search/aggregate/reducers/max.rb +26 -0
- data/lib/redi_search/aggregate/reducers/min.rb +26 -0
- data/lib/redi_search/aggregate/reducers/quantile.rb +30 -0
- data/lib/redi_search/aggregate/reducers/stdev.rb +26 -0
- data/lib/redi_search/aggregate/reducers/sum.rb +26 -0
- data/lib/redi_search/aggregate/reducers/to_list.rb +26 -0
- data/lib/redi_search/aggregate.rb +104 -0
- data/lib/redi_search/application_clause.rb +37 -0
- data/lib/redi_search/client.rb +5 -4
- data/lib/redi_search/index.rb +4 -0
- data/lib/redi_search/log_subscriber.rb +4 -3
- data/lib/redi_search/model.rb +5 -1
- data/lib/redi_search/schema/tag_field.rb +8 -0
- data/lib/redi_search/search/clauses/highlight.rb +3 -1
- data/lib/redi_search/search/clauses/in_order.rb +2 -0
- data/lib/redi_search/search/clauses/language.rb +1 -0
- data/lib/redi_search/search/clauses/limit.rb +1 -0
- data/lib/redi_search/search/clauses/no_content.rb +2 -0
- data/lib/redi_search/search/clauses/no_stop_words.rb +2 -0
- data/lib/redi_search/search/clauses/return.rb +1 -0
- data/lib/redi_search/search/clauses/slop.rb +1 -0
- data/lib/redi_search/search/clauses/sort_by.rb +1 -0
- data/lib/redi_search/search/clauses/timeout.rb +24 -0
- data/lib/redi_search/search/clauses/verbatim.rb +2 -0
- data/lib/redi_search/search/clauses/with_payloads.rb +17 -0
- data/lib/redi_search/search/clauses/with_scores.rb +2 -0
- data/lib/redi_search/search/clauses/with_sort_keys.rb +17 -0
- data/lib/redi_search/search/clauses.rb +36 -55
- data/lib/redi_search/search/{clauses → queries}/and.rb +1 -1
- data/lib/redi_search/search/{clauses → queries}/boolean.rb +4 -4
- data/lib/redi_search/search/{clauses → queries}/or.rb +1 -1
- data/lib/redi_search/search/{clauses → queries}/where.rb +2 -2
- data/lib/redi_search/search/queries.rb +39 -0
- data/lib/redi_search/search.rb +7 -6
- data/lib/redi_search/version.rb +1 -1
- metadata +30 -8
- data/lib/redi_search/search/clauses/application_clause.rb +0 -31
data/lib/redi_search/client.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require "redis"
|
4
3
|
require "active_support/notifications"
|
5
4
|
|
6
5
|
module RediSearch
|
@@ -18,11 +17,12 @@ module RediSearch
|
|
18
17
|
end
|
19
18
|
|
20
19
|
def multi
|
21
|
-
|
22
|
-
|
20
|
+
instrument("pipeline", query: ["begin pipeline"])
|
21
|
+
Response.new(redis.pipelined do |pipeline|
|
23
22
|
capture_pipeline(pipeline) { yield }
|
24
|
-
instrument("pipeline", query: ["finish pipeline"])
|
25
23
|
end)
|
24
|
+
ensure
|
25
|
+
instrument("pipeline", query: ["finish pipeline"])
|
26
26
|
end
|
27
27
|
|
28
28
|
private
|
@@ -33,6 +33,7 @@ module RediSearch
|
|
33
33
|
def capture_pipeline(pipeline)
|
34
34
|
self.pipeline = pipeline
|
35
35
|
yield
|
36
|
+
ensure
|
36
37
|
self.pipeline = false
|
37
38
|
end
|
38
39
|
|
data/lib/redi_search/index.rb
CHANGED
@@ -14,6 +14,10 @@ module RediSearch
|
|
14
14
|
Search.new(self, term, **term_options)
|
15
15
|
end
|
16
16
|
|
17
|
+
def aggregate(term = nil, **term_options)
|
18
|
+
Aggregate.new(self, term, **term_options)
|
19
|
+
end
|
20
|
+
|
17
21
|
def spellcheck(query, distance: 1)
|
18
22
|
Spellcheck.new(self, query, distance: distance)
|
19
23
|
end
|
@@ -30,19 +30,20 @@ module RediSearch
|
|
30
30
|
command = command_string(event)
|
31
31
|
debug_color = action_color(event.payload[:action])
|
32
32
|
|
33
|
-
debug " #{log_name(event)} #{color(command, debug_color, true)}"
|
33
|
+
debug " #{log_name(event)} #{color(command, debug_color, bold: true)}"
|
34
34
|
end
|
35
35
|
|
36
36
|
private
|
37
37
|
|
38
38
|
def log_name(event)
|
39
|
-
color("#{event.payload[:name]} (#{event.duration.round(1)}ms)",
|
39
|
+
color("#{event.payload[:name]} (#{event.duration.round(1)}ms)",
|
40
|
+
RED, bold: true)
|
40
41
|
end
|
41
42
|
|
42
43
|
# rubocop:disable Metrics/MethodLength
|
43
44
|
def action_color(action)
|
44
45
|
case action.to_sym
|
45
|
-
when :search, :spellcheck then YELLOW
|
46
|
+
when :search, :spellcheck, :aggregate then YELLOW
|
46
47
|
when :create, :hset then GREEN
|
47
48
|
when :dropindex, :del then RED
|
48
49
|
when :hgetall, :info then CYAN
|
data/lib/redi_search/model.rb
CHANGED
@@ -18,7 +18,7 @@ module RediSearch
|
|
18
18
|
)
|
19
19
|
register_search_commit_hooks
|
20
20
|
|
21
|
-
scope :search_import, -> { all }
|
21
|
+
scope :search_import, -> { all } unless defined?(search_import)
|
22
22
|
|
23
23
|
include InstanceMethods
|
24
24
|
extend ModelClassMethods
|
@@ -39,6 +39,10 @@ module RediSearch
|
|
39
39
|
search_index.search(term, **term_options)
|
40
40
|
end
|
41
41
|
|
42
|
+
def aggregate(term = nil, **term_options)
|
43
|
+
search_index.aggregate(term, **term_options)
|
44
|
+
end
|
45
|
+
|
42
46
|
def spellcheck(term, distance: 1)
|
43
47
|
search_index.spellcheck(term, distance: distance)
|
44
48
|
end
|
@@ -28,6 +28,14 @@ module RediSearch
|
|
28
28
|
value.split(separator)
|
29
29
|
end
|
30
30
|
|
31
|
+
def serialize(record)
|
32
|
+
if value_block
|
33
|
+
record.instance_exec(&value_block)
|
34
|
+
else
|
35
|
+
record.public_send(name)
|
36
|
+
end.to_a
|
37
|
+
end
|
38
|
+
|
31
39
|
private
|
32
40
|
|
33
41
|
attr_reader :separator, :sortable, :no_index
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RediSearch
|
4
|
+
class Search
|
5
|
+
module Clauses
|
6
|
+
class Timeout < ApplicationClause
|
7
|
+
clause_term :timeout,
|
8
|
+
numericality: { within: 0..Float::INFINITY,
|
9
|
+
only_integer: true }
|
10
|
+
clause_order 14
|
11
|
+
|
12
|
+
def initialize(timeout:)
|
13
|
+
@timeout = timeout
|
14
|
+
end
|
15
|
+
|
16
|
+
def clause
|
17
|
+
validate!
|
18
|
+
|
19
|
+
["TIMEOUT", timeout]
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -3,96 +3,77 @@
|
|
3
3
|
module RediSearch
|
4
4
|
class Search
|
5
5
|
module Clauses
|
6
|
-
def
|
7
|
-
|
8
|
-
fields: fields, opening_tag: opening_tag, closing_tag: closing_tag
|
9
|
-
))
|
10
|
-
end
|
11
|
-
|
12
|
-
def slop(slop)
|
13
|
-
add_to_clause(Slop.new(slop: slop))
|
14
|
-
end
|
15
|
-
|
16
|
-
def in_order
|
17
|
-
add_to_clause(InOrder.new)
|
6
|
+
def no_content
|
7
|
+
add_to_clauses(NoContent.new)
|
18
8
|
end
|
19
9
|
|
20
10
|
def verbatim
|
21
|
-
|
11
|
+
add_to_clauses(Verbatim.new)
|
22
12
|
end
|
23
13
|
|
24
14
|
def no_stop_words
|
25
|
-
|
15
|
+
add_to_clauses(NoStopWords.new)
|
26
16
|
end
|
27
17
|
|
28
18
|
def with_scores
|
29
|
-
|
19
|
+
add_to_clauses(WithScores.new)
|
30
20
|
end
|
31
21
|
|
32
|
-
def
|
33
|
-
|
22
|
+
def with_payloads
|
23
|
+
add_to_clauses(WithPayloads.new)
|
34
24
|
end
|
35
25
|
|
36
|
-
def
|
37
|
-
|
26
|
+
def with_sort_keys
|
27
|
+
add_to_clauses(WithSortKeys.new)
|
38
28
|
end
|
39
29
|
|
40
|
-
def
|
41
|
-
|
30
|
+
def return(*fields)
|
31
|
+
add_to_clauses(Return.new(fields: fields))
|
42
32
|
end
|
43
33
|
|
44
|
-
def
|
45
|
-
|
34
|
+
def highlight(fields: [], opening_tag: "<b>", closing_tag: "</b>")
|
35
|
+
add_to_clauses(Highlight.new(
|
36
|
+
fields: fields, opening_tag: opening_tag, closing_tag: closing_tag
|
37
|
+
))
|
46
38
|
end
|
47
39
|
|
48
|
-
def
|
49
|
-
|
40
|
+
def slop(slop)
|
41
|
+
add_to_clauses(Slop.new(slop: slop))
|
50
42
|
end
|
51
43
|
|
52
|
-
def
|
53
|
-
|
54
|
-
|
55
|
-
RediSearch.client.call!(
|
56
|
-
"SEARCH", index.name, term_clause.to_s, *Limit.new(total: 0).clause
|
57
|
-
).first
|
44
|
+
def timeout(timeout)
|
45
|
+
add_to_clauses(Timeout.new(timeout: timeout))
|
58
46
|
end
|
59
47
|
|
60
|
-
def
|
61
|
-
|
62
|
-
|
63
|
-
self
|
48
|
+
def in_order
|
49
|
+
add_to_clauses(InOrder.new)
|
64
50
|
end
|
65
51
|
|
66
|
-
def
|
67
|
-
|
68
|
-
|
69
|
-
@term_clause.not(condition)
|
52
|
+
def language(language)
|
53
|
+
add_to_clauses(Language.new(language: language))
|
70
54
|
end
|
71
55
|
|
72
|
-
def
|
73
|
-
|
56
|
+
def sort_by(field, order: :asc)
|
57
|
+
add_to_clauses(SortBy.new(field: field, order: order))
|
58
|
+
end
|
74
59
|
|
75
|
-
|
76
|
-
|
77
|
-
else
|
78
|
-
self
|
79
|
-
end
|
60
|
+
def limit(total, offset = 0)
|
61
|
+
add_to_clauses(Limit.new(total: total, offset: offset))
|
80
62
|
end
|
81
63
|
|
82
|
-
def
|
83
|
-
|
64
|
+
def count
|
65
|
+
return to_a.size if loaded?
|
84
66
|
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
self
|
89
|
-
end
|
67
|
+
RediSearch.client.call!(
|
68
|
+
"SEARCH", index.name, query.to_s, *Limit.new(total: 0).clause
|
69
|
+
).first
|
90
70
|
end
|
91
71
|
|
92
72
|
private
|
93
73
|
|
94
|
-
def
|
95
|
-
clauses.push(
|
74
|
+
def add_to_clauses(clause)
|
75
|
+
clause.validate! && clauses.push(clause) if
|
76
|
+
used_clauses.add?(clause.class)
|
96
77
|
|
97
78
|
self
|
98
79
|
end
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
module RediSearch
|
4
4
|
class Search
|
5
|
-
module
|
5
|
+
module Queries
|
6
6
|
class Boolean
|
7
7
|
extend Forwardable
|
8
8
|
|
@@ -65,10 +65,10 @@ module RediSearch
|
|
65
65
|
end
|
66
66
|
|
67
67
|
def queryify_search
|
68
|
-
if term.
|
69
|
-
term.
|
68
|
+
if term.query.is_a?(RediSearch::Search::Queries::Where)
|
69
|
+
term.query
|
70
70
|
else
|
71
|
-
"(#{term.
|
71
|
+
"(#{term.query})"
|
72
72
|
end
|
73
73
|
end
|
74
74
|
end
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
module RediSearch
|
4
4
|
class Search
|
5
|
-
module
|
5
|
+
module Queries
|
6
6
|
class Where
|
7
7
|
extend Forwardable
|
8
8
|
|
@@ -39,7 +39,7 @@ module RediSearch
|
|
39
39
|
|
40
40
|
def queryify_term
|
41
41
|
if term.is_a? RediSearch::Search
|
42
|
-
"(#{term.
|
42
|
+
"(#{term.query})"
|
43
43
|
else
|
44
44
|
term.to_s
|
45
45
|
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RediSearch
|
4
|
+
class Search
|
5
|
+
module Queries
|
6
|
+
def where(**condition)
|
7
|
+
@query = Search::Queries::Where.new(self, condition, @query)
|
8
|
+
|
9
|
+
self
|
10
|
+
end
|
11
|
+
|
12
|
+
def not(**condition)
|
13
|
+
raise NoMethodError unless @query.is_a?(Search::Queries::Where)
|
14
|
+
|
15
|
+
@query.not(condition)
|
16
|
+
end
|
17
|
+
|
18
|
+
def and(new_term = nil, **term_options)
|
19
|
+
@query = Queries::And.new(self, new_term, @query, **term_options)
|
20
|
+
|
21
|
+
if new_term.nil?
|
22
|
+
@query
|
23
|
+
else
|
24
|
+
self
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def or(new_term = nil, **term_options)
|
29
|
+
@query = Queries::Or.new(self, new_term, @query, **term_options)
|
30
|
+
|
31
|
+
if new_term.nil?
|
32
|
+
@query
|
33
|
+
else
|
34
|
+
self
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
data/lib/redi_search/search.rb
CHANGED
@@ -5,8 +5,9 @@ module RediSearch
|
|
5
5
|
extend Forwardable
|
6
6
|
include LazilyLoad
|
7
7
|
include Clauses
|
8
|
+
include Queries
|
8
9
|
|
9
|
-
attr_reader :
|
10
|
+
attr_reader :query, :used_clauses, :index, :clauses
|
10
11
|
|
11
12
|
def_delegator :index, :model
|
12
13
|
|
@@ -15,8 +16,7 @@ module RediSearch
|
|
15
16
|
@clauses = []
|
16
17
|
@used_clauses = Set.new
|
17
18
|
|
18
|
-
@
|
19
|
-
And.new(self, term, nil, **term_options)
|
19
|
+
@query = term && And.new(self, term, nil, **term_options)
|
20
20
|
end
|
21
21
|
|
22
22
|
def results
|
@@ -31,7 +31,7 @@ module RediSearch
|
|
31
31
|
|
32
32
|
def explain
|
33
33
|
RediSearch.client.call!(
|
34
|
-
"EXPLAINCLI", index.name,
|
34
|
+
"EXPLAINCLI", index.name, query.to_s
|
35
35
|
).join(" ").strip
|
36
36
|
end
|
37
37
|
|
@@ -44,7 +44,8 @@ module RediSearch
|
|
44
44
|
attr_writer :index, :clauses
|
45
45
|
|
46
46
|
def command
|
47
|
-
["SEARCH", index.name,
|
47
|
+
["SEARCH", index.name, query.to_s,
|
48
|
+
*clauses.sort_by(&:clause_order).flat_map(&:clause)]
|
48
49
|
end
|
49
50
|
|
50
51
|
def parse_response(response)
|
@@ -52,7 +53,7 @@ module RediSearch
|
|
52
53
|
end
|
53
54
|
|
54
55
|
def valid?
|
55
|
-
!
|
56
|
+
!query.to_s.empty?
|
56
57
|
end
|
57
58
|
end
|
58
59
|
end
|
data/lib/redi_search/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: redi_search
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 6.3.
|
4
|
+
version: 6.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nick Pezza
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-03-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -141,6 +141,25 @@ files:
|
|
141
141
|
- gemfiles/activerecord_70.gemfile
|
142
142
|
- lib/redi_search.rb
|
143
143
|
- lib/redi_search/add_field.rb
|
144
|
+
- lib/redi_search/aggregate.rb
|
145
|
+
- lib/redi_search/aggregate/clauses/apply.rb
|
146
|
+
- lib/redi_search/aggregate/clauses/filter.rb
|
147
|
+
- lib/redi_search/aggregate/clauses/group_by.rb
|
148
|
+
- lib/redi_search/aggregate/clauses/limit.rb
|
149
|
+
- lib/redi_search/aggregate/clauses/load.rb
|
150
|
+
- lib/redi_search/aggregate/clauses/sort_by.rb
|
151
|
+
- lib/redi_search/aggregate/clauses/verbatim.rb
|
152
|
+
- lib/redi_search/aggregate/reducers/average.rb
|
153
|
+
- lib/redi_search/aggregate/reducers/count.rb
|
154
|
+
- lib/redi_search/aggregate/reducers/distinct_count.rb
|
155
|
+
- lib/redi_search/aggregate/reducers/distinctish_count.rb
|
156
|
+
- lib/redi_search/aggregate/reducers/max.rb
|
157
|
+
- lib/redi_search/aggregate/reducers/min.rb
|
158
|
+
- lib/redi_search/aggregate/reducers/quantile.rb
|
159
|
+
- lib/redi_search/aggregate/reducers/stdev.rb
|
160
|
+
- lib/redi_search/aggregate/reducers/sum.rb
|
161
|
+
- lib/redi_search/aggregate/reducers/to_list.rb
|
162
|
+
- lib/redi_search/application_clause.rb
|
144
163
|
- lib/redi_search/client.rb
|
145
164
|
- lib/redi_search/client/response.rb
|
146
165
|
- lib/redi_search/configuration.rb
|
@@ -161,22 +180,25 @@ files:
|
|
161
180
|
- lib/redi_search/schema/text_field.rb
|
162
181
|
- lib/redi_search/search.rb
|
163
182
|
- lib/redi_search/search/clauses.rb
|
164
|
-
- lib/redi_search/search/clauses/and.rb
|
165
|
-
- lib/redi_search/search/clauses/application_clause.rb
|
166
|
-
- lib/redi_search/search/clauses/boolean.rb
|
167
183
|
- lib/redi_search/search/clauses/highlight.rb
|
168
184
|
- lib/redi_search/search/clauses/in_order.rb
|
169
185
|
- lib/redi_search/search/clauses/language.rb
|
170
186
|
- lib/redi_search/search/clauses/limit.rb
|
171
187
|
- lib/redi_search/search/clauses/no_content.rb
|
172
188
|
- lib/redi_search/search/clauses/no_stop_words.rb
|
173
|
-
- lib/redi_search/search/clauses/or.rb
|
174
189
|
- lib/redi_search/search/clauses/return.rb
|
175
190
|
- lib/redi_search/search/clauses/slop.rb
|
176
191
|
- lib/redi_search/search/clauses/sort_by.rb
|
192
|
+
- lib/redi_search/search/clauses/timeout.rb
|
177
193
|
- lib/redi_search/search/clauses/verbatim.rb
|
178
|
-
- lib/redi_search/search/clauses/
|
194
|
+
- lib/redi_search/search/clauses/with_payloads.rb
|
179
195
|
- lib/redi_search/search/clauses/with_scores.rb
|
196
|
+
- lib/redi_search/search/clauses/with_sort_keys.rb
|
197
|
+
- lib/redi_search/search/queries.rb
|
198
|
+
- lib/redi_search/search/queries/and.rb
|
199
|
+
- lib/redi_search/search/queries/boolean.rb
|
200
|
+
- lib/redi_search/search/queries/or.rb
|
201
|
+
- lib/redi_search/search/queries/where.rb
|
180
202
|
- lib/redi_search/search/result.rb
|
181
203
|
- lib/redi_search/search/term.rb
|
182
204
|
- lib/redi_search/spellcheck.rb
|
@@ -211,7 +233,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
211
233
|
- !ruby/object:Gem::Version
|
212
234
|
version: '0'
|
213
235
|
requirements: []
|
214
|
-
rubygems_version: 3.4.
|
236
|
+
rubygems_version: 3.4.6
|
215
237
|
signing_key:
|
216
238
|
specification_version: 4
|
217
239
|
summary: RediSearch ruby wrapper that can integrate with Rails
|