typesense-rails 1.0.0.rc2 → 1.0.0.rc4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +31 -31
- data/README.md +2 -1
- data/lib/typesense/config.rb +40 -0
- data/lib/typesense/pagination/pagy.rb +1 -1
- data/lib/typesense/version.rb +1 -1
- data/lib/typesense-rails.rb +38 -9
- 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: 235c4761cba73de6042fe41ac751658c001b0a44fa2a7e2959fea7b398bf186c
|
4
|
+
data.tar.gz: deaaded73d6ac588e47c0439f515ff4771f05ab063692d651cdb00ab60c7513e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6004a8189a68987366577a1903404a22c2eb3fad4ac4226d6deeeacf6a34a7411d35ca6da0a9ec585278932b27b1c96a568fa192eeb69e3d1cb2b708df750768
|
7
|
+
data.tar.gz: 10626d38245d494eff9b81d28d5f8c2e2d409fbdc69f6bc217acd0e78079504a9b3eaf2a38fc62fe4f5582742758e6c4f14206c04125953bca2c1690061fee31
|
data/Gemfile.lock
CHANGED
@@ -66,12 +66,12 @@ GEM
|
|
66
66
|
tzinfo (~> 2.0)
|
67
67
|
zeitwerk (~> 2.3)
|
68
68
|
ast (2.4.3)
|
69
|
-
base64 (0.
|
70
|
-
bigdecimal (3.
|
69
|
+
base64 (0.3.0)
|
70
|
+
bigdecimal (3.2.3)
|
71
71
|
builder (3.3.0)
|
72
72
|
case_transform (0.2)
|
73
73
|
activesupport
|
74
|
-
cgi (0.
|
74
|
+
cgi (0.5.0)
|
75
75
|
concurrent-ruby (1.3.5)
|
76
76
|
crass (1.0.6)
|
77
77
|
date (3.4.1)
|
@@ -79,14 +79,14 @@ GEM
|
|
79
79
|
erb (4.0.4)
|
80
80
|
cgi (>= 0.3.3)
|
81
81
|
erubi (1.13.1)
|
82
|
-
ethon (0.
|
82
|
+
ethon (0.15.0)
|
83
83
|
ffi (>= 1.15.0)
|
84
84
|
ffi (1.17.2)
|
85
|
-
globalid (1.
|
85
|
+
globalid (1.3.0)
|
86
86
|
activesupport (>= 6.1)
|
87
87
|
i18n (1.14.7)
|
88
88
|
concurrent-ruby (~> 1.0)
|
89
|
-
json (2.
|
89
|
+
json (2.15.0)
|
90
90
|
jsonapi-renderer (0.2.2)
|
91
91
|
kaminari (0.17.0)
|
92
92
|
actionpack (>= 3.0.0)
|
@@ -103,7 +103,7 @@ GEM
|
|
103
103
|
net-imap
|
104
104
|
net-pop
|
105
105
|
net-smtp
|
106
|
-
marcel (1.0
|
106
|
+
marcel (1.1.0)
|
107
107
|
method_source (1.1.0)
|
108
108
|
mini_mime (1.1.5)
|
109
109
|
mini_portile2 (2.8.9)
|
@@ -121,21 +121,21 @@ GEM
|
|
121
121
|
nokogiri (1.15.7)
|
122
122
|
mini_portile2 (~> 2.8.2)
|
123
123
|
racc (~> 1.4)
|
124
|
-
oj (3.16.
|
124
|
+
oj (3.16.11)
|
125
125
|
bigdecimal (>= 3.0)
|
126
126
|
ostruct (>= 0.2)
|
127
|
-
ostruct (0.6.
|
127
|
+
ostruct (0.6.3)
|
128
128
|
pagy (6.5.0)
|
129
129
|
parallel (1.27.0)
|
130
|
-
parser (3.3.
|
130
|
+
parser (3.3.9.0)
|
131
131
|
ast (~> 2.4.1)
|
132
132
|
racc
|
133
|
-
prism (1.
|
133
|
+
prism (1.5.1)
|
134
134
|
psych (5.2.6)
|
135
135
|
date
|
136
136
|
stringio
|
137
137
|
racc (1.8.1)
|
138
|
-
rack (2.2.
|
138
|
+
rack (2.2.18)
|
139
139
|
rack-test (2.2.0)
|
140
140
|
rack (>= 1.3)
|
141
141
|
rails (6.1.7.10)
|
@@ -167,25 +167,25 @@ GEM
|
|
167
167
|
rake (>= 12.2)
|
168
168
|
thor (~> 1.0)
|
169
169
|
rainbow (3.1.1)
|
170
|
-
rake (13.
|
171
|
-
rdoc (6.14.
|
170
|
+
rake (13.3.0)
|
171
|
+
rdoc (6.14.2)
|
172
172
|
erb
|
173
173
|
psych (>= 4.0.0)
|
174
|
-
regexp_parser (2.
|
175
|
-
rspec (3.13.
|
174
|
+
regexp_parser (2.11.3)
|
175
|
+
rspec (3.13.1)
|
176
176
|
rspec-core (~> 3.13.0)
|
177
177
|
rspec-expectations (~> 3.13.0)
|
178
178
|
rspec-mocks (~> 3.13.0)
|
179
|
-
rspec-core (3.13.
|
179
|
+
rspec-core (3.13.5)
|
180
180
|
rspec-support (~> 3.13.0)
|
181
|
-
rspec-expectations (3.13.
|
181
|
+
rspec-expectations (3.13.5)
|
182
182
|
diff-lcs (>= 1.2.0, < 2.0)
|
183
183
|
rspec-support (~> 3.13.0)
|
184
|
-
rspec-mocks (3.13.
|
184
|
+
rspec-mocks (3.13.5)
|
185
185
|
diff-lcs (>= 1.2.0, < 2.0)
|
186
186
|
rspec-support (~> 3.13.0)
|
187
|
-
rspec-support (3.13.
|
188
|
-
rubocop (1.
|
187
|
+
rspec-support (3.13.6)
|
188
|
+
rubocop (1.81.1)
|
189
189
|
json (~> 2.3)
|
190
190
|
language_server-protocol (~> 3.17.0.2)
|
191
191
|
lint_roller (~> 1.1.0)
|
@@ -193,14 +193,14 @@ GEM
|
|
193
193
|
parser (>= 3.3.0.2)
|
194
194
|
rainbow (>= 2.2.2, < 4.0)
|
195
195
|
regexp_parser (>= 2.9.3, < 3.0)
|
196
|
-
rubocop-ast (>= 1.
|
196
|
+
rubocop-ast (>= 1.47.1, < 2.0)
|
197
197
|
ruby-progressbar (~> 1.7)
|
198
198
|
unicode-display_width (>= 2.4.0, < 4.0)
|
199
|
-
rubocop-ast (1.
|
199
|
+
rubocop-ast (1.47.1)
|
200
200
|
parser (>= 3.3.7.2)
|
201
201
|
prism (~> 1.4)
|
202
202
|
ruby-progressbar (1.13.0)
|
203
|
-
sequel (5.
|
203
|
+
sequel (5.96.0)
|
204
204
|
bigdecimal
|
205
205
|
sprockets (4.2.2)
|
206
206
|
concurrent-ruby (~> 1.0)
|
@@ -213,19 +213,19 @@ GEM
|
|
213
213
|
sqlite3 (1.6.9)
|
214
214
|
mini_portile2 (~> 2.8.0)
|
215
215
|
stringio (3.1.7)
|
216
|
-
thor (1.
|
216
|
+
thor (1.4.0)
|
217
217
|
timeout (0.4.3)
|
218
218
|
typesense (0.13.0)
|
219
219
|
oj (~> 3.11)
|
220
220
|
typhoeus (~> 1.4)
|
221
|
-
typhoeus (1.
|
222
|
-
ethon (>= 0.9.0)
|
221
|
+
typhoeus (1.5.0)
|
222
|
+
ethon (>= 0.9.0, < 0.16.0)
|
223
223
|
tzinfo (2.0.6)
|
224
224
|
concurrent-ruby (~> 1.0)
|
225
|
-
unicode-display_width (3.
|
226
|
-
unicode-emoji (~> 4.
|
227
|
-
unicode-emoji (4.0
|
228
|
-
websocket-driver (0.
|
225
|
+
unicode-display_width (3.2.0)
|
226
|
+
unicode-emoji (~> 4.1)
|
227
|
+
unicode-emoji (4.1.0)
|
228
|
+
websocket-driver (0.8.0)
|
229
229
|
base64
|
230
230
|
websocket-extensions (>= 0.1.0)
|
231
231
|
websocket-extensions (0.1.5)
|
data/README.md
CHANGED
@@ -47,7 +47,8 @@ Typesense.configuration = {
|
|
47
47
|
protocol: 'http' # For Typesense Cloud use https
|
48
48
|
}],
|
49
49
|
api_key: 'your-api-key',
|
50
|
-
connection_timeout_seconds: 2
|
50
|
+
connection_timeout_seconds: 2,
|
51
|
+
log_level: :info # Messages below this level will be silenced. One of (:debug, :info, :warn, :error, :fatal)
|
51
52
|
}
|
52
53
|
```
|
53
54
|
|
data/lib/typesense/config.rb
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
module Typesense
|
2
2
|
module Config
|
3
|
+
@@pagination_backend = nil unless defined?(@@pagination_backend)
|
4
|
+
@@log_level = nil unless defined?(@@log_level)
|
5
|
+
@@configuration = nil unless defined?(@@configuration)
|
3
6
|
def initiliaze
|
4
7
|
@client = nil
|
5
8
|
end
|
@@ -11,6 +14,7 @@ module Typesense
|
|
11
14
|
|
12
15
|
def configuration=(configuration)
|
13
16
|
@@pagination_backend = configuration[:pagination_backend] if configuration.key?(:pagination_backend)
|
17
|
+
@@log_level = configuration[:log_level] if configuration.key?(:log_level)
|
14
18
|
@@configuration = configuration
|
15
19
|
end
|
16
20
|
|
@@ -18,6 +22,42 @@ module Typesense
|
|
18
22
|
@@pagination_backend
|
19
23
|
end
|
20
24
|
|
25
|
+
def log_level
|
26
|
+
defined?(@@log_level) ? @@log_level : nil
|
27
|
+
end
|
28
|
+
|
29
|
+
def log_level_to_const(level)
|
30
|
+
# Be more forgiving in inputs.
|
31
|
+
# Accepts Integer (e.g., Logger::WARN), Symbol/String (e.g., :warn, "warn", "WARN", "Logger::WARN")
|
32
|
+
return level if level.is_a?(Integer)
|
33
|
+
return Logger::WARN if level.nil?
|
34
|
+
|
35
|
+
str = level.to_s
|
36
|
+
|
37
|
+
# Handle fully-qualified constants like "Logger::WARN"
|
38
|
+
if str.include?("::")
|
39
|
+
const = str.split("::").last
|
40
|
+
return Logger.const_get(const) if Logger.const_defined?(const)
|
41
|
+
end
|
42
|
+
|
43
|
+
# Normalize common misnomer
|
44
|
+
upper = str.upcase
|
45
|
+
upper = "WARN" if upper == "WARNING"
|
46
|
+
return Logger.const_get(upper) if Logger.const_defined?(upper)
|
47
|
+
|
48
|
+
# Fallback to explicit mapping
|
49
|
+
case str.downcase.to_sym
|
50
|
+
when :debug then Logger::DEBUG
|
51
|
+
when :info then Logger::INFO
|
52
|
+
when :warn, :warning then Logger::WARN
|
53
|
+
when :error then Logger::ERROR
|
54
|
+
when :fatal then Logger::FATAL
|
55
|
+
when :unknown then Logger::UNKNOWN
|
56
|
+
else
|
57
|
+
Logger::WARN
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
21
61
|
def client
|
22
62
|
setup_client if @client.nil?
|
23
63
|
@client
|
data/lib/typesense/version.rb
CHANGED
data/lib/typesense-rails.rb
CHANGED
@@ -17,8 +17,6 @@ rescue LoadError
|
|
17
17
|
end
|
18
18
|
|
19
19
|
require "logger"
|
20
|
-
Rails.logger = ActiveSupport::TaggedLogging.new(ActiveSupport::Logger.new(STDOUT))
|
21
|
-
Rails.logger.level = Logger::INFO
|
22
20
|
|
23
21
|
module Typesense
|
24
22
|
class NotConfigured < StandardError; end
|
@@ -32,6 +30,37 @@ module Typesense
|
|
32
30
|
|
33
31
|
class << self
|
34
32
|
attr_reader :included_in
|
33
|
+
attr_writer :logger
|
34
|
+
|
35
|
+
def logger
|
36
|
+
return @logger if defined?(@logger) && @logger
|
37
|
+
|
38
|
+
rails_logger = (defined?(::Rails) && Rails.respond_to?(:logger)) ? Rails.logger : nil
|
39
|
+
@logger = rails_logger || Logger.new($stdout)
|
40
|
+
end
|
41
|
+
|
42
|
+
def log(severity, message = nil, &block)
|
43
|
+
# If a min log level is configured, skip below-threshold messages
|
44
|
+
min_level = log_level
|
45
|
+
if min_level && !passes_min_level?(severity, min_level)
|
46
|
+
return
|
47
|
+
end
|
48
|
+
|
49
|
+
sev_const = log_level_to_const(severity)
|
50
|
+
if logger.respond_to?(:tagged)
|
51
|
+
logger.tagged("Typesense") { logger.add(sev_const, message, &block) }
|
52
|
+
else
|
53
|
+
logger.add(sev_const, message, &block)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def passes_min_level?(severity, min_level)
|
58
|
+
return true if min_level.nil?
|
59
|
+
|
60
|
+
sev_const = log_level_to_const(severity)
|
61
|
+
min_const = log_level_to_const(min_level)
|
62
|
+
sev_const >= min_const
|
63
|
+
end
|
35
64
|
|
36
65
|
def included(klass)
|
37
66
|
@included_in ||= []
|
@@ -269,7 +298,7 @@ module Typesense
|
|
269
298
|
metadata ? { "metadata" => metadata } : {}
|
270
299
|
)
|
271
300
|
)
|
272
|
-
|
301
|
+
Typesense.log(:debug, "Collection '#{collection_name}' created!")
|
273
302
|
|
274
303
|
typesense_multi_way_synonyms(collection_name, multi_way_synonyms) if multi_way_synonyms
|
275
304
|
|
@@ -542,7 +571,7 @@ module Typesense
|
|
542
571
|
end
|
543
572
|
jsonl_object = documents.join("\n")
|
544
573
|
ImportJob.perform(jsonl_object, collection_obj[:alias_name], batch_size)
|
545
|
-
|
574
|
+
Typesense.log(:debug, "#{objects.length} objects enqueued for import into #{collection_obj[:collection_name]}")
|
546
575
|
end
|
547
576
|
nil
|
548
577
|
end
|
@@ -557,7 +586,7 @@ module Typesense
|
|
557
586
|
end
|
558
587
|
jsonl_object = documents.join("\n")
|
559
588
|
import_documents(jsonl_object, "upsert", collection_obj[:alias_name], batch_size: batch_size)
|
560
|
-
|
589
|
+
Typesense.log(:debug, "#{objects.length} objects upserted into #{collection_obj[:collection_name]}!")
|
561
590
|
end
|
562
591
|
nil
|
563
592
|
end
|
@@ -588,7 +617,7 @@ module Typesense
|
|
588
617
|
begin
|
589
618
|
api_response = delete_document(object_id, collection_obj[:collection_name])
|
590
619
|
rescue Typesense::Error::ObjectNotFound => e
|
591
|
-
|
620
|
+
Typesense.log(:error, "Object not found in index: #{e.message}")
|
592
621
|
end
|
593
622
|
end
|
594
623
|
end
|
@@ -611,9 +640,9 @@ module Typesense
|
|
611
640
|
begin
|
612
641
|
delete_document(object_id, collection_obj[:alias_name])
|
613
642
|
rescue Typesense::Error::ObjectNotFound => e
|
614
|
-
|
643
|
+
Typesense.log(:error, "Object #{object_id} could not be removed from #{collection_obj[:collection_name]} collection! Use reindex to update the collection.")
|
615
644
|
end
|
616
|
-
|
645
|
+
Typesense.log(:debug, "Removed document with object id '#{object_id}' from #{collection_obj[:collection_name]}")
|
617
646
|
end
|
618
647
|
nil
|
619
648
|
end
|
@@ -626,7 +655,7 @@ module Typesense
|
|
626
655
|
collection_obj = typesense_ensure_init(options, settings, false)
|
627
656
|
|
628
657
|
delete_collection(collection_obj[:alias_name])
|
629
|
-
|
658
|
+
Typesense.log(:debug, "Deleted #{collection_obj[:alias_name]} collection!")
|
630
659
|
@typesense_indexes[settings] = nil
|
631
660
|
end
|
632
661
|
nil
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: typesense-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.0.
|
4
|
+
version: 1.0.0.rc4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- typesense
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-
|
11
|
+
date: 2025-09-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|