typesense-rails 1.0.0.rc1 → 1.0.0.rc3
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 +0 -1
- data/Gemfile.lock +1 -3
- data/README.md +39 -3
- data/lib/typesense/config.rb +26 -0
- data/lib/typesense/version.rb +1 -1
- data/lib/typesense-rails.rb +7 -7
- 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: 6eccd8d0b15d3ad1bcfa4fb34a952f6e52989a5a95adc5296793e3b9c7e9d94a
|
4
|
+
data.tar.gz: f2e31e14a80da87f6a63473ba05c226cc83127b5e7f3c218a86af0a378ec1331
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 855009638b2c9f5cbd6b3b82170da7241ae74db850221588eaf3b088eb210f205a1c53271d0cc535905ca270d0e0885c740ef5acee83dbb41447edd0aee5cddc
|
7
|
+
data.tar.gz: 22ea6071f533f79050df6cefefb3d104e641d0a88f635981af4318a70064ce1c5bd0ddc61b63674899858549579efdb1a722838ffe8b54dcc6eee1219892328f
|
data/Gemfile
CHANGED
@@ -21,7 +21,6 @@ group :test do
|
|
21
21
|
gem 'jdbc-sqlite3', :platform => :jruby
|
22
22
|
gem 'activerecord-jdbc-adapter', :platform => :jruby
|
23
23
|
gem 'activerecord-jdbcsqlite3-adapter', :platform => :jruby
|
24
|
-
gem 'redgreen'
|
25
24
|
|
26
25
|
sequel_version = ENV['SEQUEL_VERSION'] ? "~> #{ENV['SEQUEL_VERSION']}" : '>= 4.0'
|
27
26
|
gem 'sequel', sequel_version
|
data/Gemfile.lock
CHANGED
@@ -135,7 +135,7 @@ GEM
|
|
135
135
|
date
|
136
136
|
stringio
|
137
137
|
racc (1.8.1)
|
138
|
-
rack (2.2.
|
138
|
+
rack (2.2.17)
|
139
139
|
rack-test (2.2.0)
|
140
140
|
rack (>= 1.3)
|
141
141
|
rails (6.1.7.10)
|
@@ -171,7 +171,6 @@ GEM
|
|
171
171
|
rdoc (6.14.0)
|
172
172
|
erb
|
173
173
|
psych (>= 4.0.0)
|
174
|
-
redgreen (1.2.2)
|
175
174
|
regexp_parser (2.10.0)
|
176
175
|
rspec (3.13.0)
|
177
176
|
rspec-core (~> 3.13.0)
|
@@ -248,7 +247,6 @@ DEPENDENCIES
|
|
248
247
|
rails (~> 6.1)
|
249
248
|
rake (>= 10.1.0)
|
250
249
|
rdoc
|
251
|
-
redgreen
|
252
250
|
rspec (~> 3.0)
|
253
251
|
rubocop (~> 1.19)
|
254
252
|
sequel (>= 4.0)
|
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 # Optional: Set logging level (:debug, :info, :warn, :error, :fatal, :unknown)
|
51
52
|
}
|
52
53
|
```
|
53
54
|
|
@@ -126,11 +127,29 @@ class Profile < ApplicationRecord
|
|
126
127
|
end
|
127
128
|
```
|
128
129
|
|
130
|
+
### Working with ActionText
|
131
|
+
|
132
|
+
ActionText `has_rich_text` defines an association to the ActionText::RichText model. Use `to_plain_text` on this association to get a plain text version for indexing with Typesense.
|
133
|
+
|
134
|
+
```ruby
|
135
|
+
class Product < ApplicationRecord
|
136
|
+
include Typesense
|
137
|
+
|
138
|
+
has_rich_text :description
|
139
|
+
|
140
|
+
typesense do
|
141
|
+
attribute :description do
|
142
|
+
description.to_plain_text
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
146
|
+
```
|
147
|
+
|
129
148
|
### Searching
|
130
149
|
|
131
150
|
```ruby
|
132
|
-
# Basic search
|
133
|
-
results = Product.search('phone', 'name')
|
151
|
+
# Basic search of "phone" against name and description attributes
|
152
|
+
results = Product.search('phone', 'name,description')
|
134
153
|
|
135
154
|
# Search with filters and sorting
|
136
155
|
results = Product.search('phone', 'name', {
|
@@ -211,6 +230,23 @@ Typesense.configuration = {
|
|
211
230
|
}
|
212
231
|
```
|
213
232
|
|
233
|
+
### Pagination & Search in a controller with Pagy
|
234
|
+
|
235
|
+
```ruby
|
236
|
+
class ProductsController < ApplicationController
|
237
|
+
def index
|
238
|
+
# If `params[:q]` is blank, Typesense will automatically use "*" to return all documents
|
239
|
+
@pagy, @products = Product.search(params[:q], "name,description")
|
240
|
+
end
|
241
|
+
end
|
242
|
+
```
|
243
|
+
|
244
|
+
```erb
|
245
|
+
<h1>Search results for <%= params[:q] %></h1>
|
246
|
+
<%= render @products %>
|
247
|
+
<%== pagy_nav(@pagy) if @pagy.pages > 1 %>
|
248
|
+
```
|
249
|
+
|
214
250
|
## Testing
|
215
251
|
|
216
252
|
To run the test suite:
|
data/lib/typesense/config.rb
CHANGED
@@ -11,13 +11,39 @@ module Typesense
|
|
11
11
|
|
12
12
|
def configuration=(configuration)
|
13
13
|
@@pagination_backend = configuration[:pagination_backend] if configuration.key?(:pagination_backend)
|
14
|
+
@@log_level = configuration[:log_level] if configuration.key?(:log_level)
|
14
15
|
@@configuration = configuration
|
16
|
+
|
17
|
+
Rails.logger.level = log_level_to_const(configuration[:log_level])
|
15
18
|
end
|
16
19
|
|
17
20
|
def pagination_backend
|
18
21
|
@@pagination_backend
|
19
22
|
end
|
20
23
|
|
24
|
+
def log_level
|
25
|
+
@@log_level
|
26
|
+
end
|
27
|
+
|
28
|
+
def log_level_to_const(level)
|
29
|
+
case level
|
30
|
+
when :debug
|
31
|
+
Logger::DEBUG
|
32
|
+
when :info
|
33
|
+
Logger::INFO
|
34
|
+
when :warn
|
35
|
+
Logger::WARN
|
36
|
+
when :error
|
37
|
+
Logger::ERROR
|
38
|
+
when :fatal
|
39
|
+
Logger::FATAL
|
40
|
+
when :unknown
|
41
|
+
Logger::UNKNOWN
|
42
|
+
else
|
43
|
+
Logger::WARN # default fallback
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
21
47
|
def client
|
22
48
|
setup_client if @client.nil?
|
23
49
|
@client
|
data/lib/typesense/version.rb
CHANGED
data/lib/typesense-rails.rb
CHANGED
@@ -18,7 +18,7 @@ end
|
|
18
18
|
|
19
19
|
require "logger"
|
20
20
|
Rails.logger = ActiveSupport::TaggedLogging.new(ActiveSupport::Logger.new(STDOUT))
|
21
|
-
Rails.logger.level = Logger::
|
21
|
+
Rails.logger.level = Logger::WARN
|
22
22
|
|
23
23
|
module Typesense
|
24
24
|
class NotConfigured < StandardError; end
|
@@ -269,7 +269,7 @@ module Typesense
|
|
269
269
|
metadata ? { "metadata" => metadata } : {}
|
270
270
|
)
|
271
271
|
)
|
272
|
-
Rails.logger.
|
272
|
+
Rails.logger.debug "Collection '#{collection_name}' created!"
|
273
273
|
|
274
274
|
typesense_multi_way_synonyms(collection_name, multi_way_synonyms) if multi_way_synonyms
|
275
275
|
|
@@ -365,7 +365,7 @@ module Typesense
|
|
365
365
|
if options[:enqueue]
|
366
366
|
proc = if options[:enqueue] == true
|
367
367
|
proc do |record, remove|
|
368
|
-
|
368
|
+
TypesenseJob.perform_later(record, remove ? "typesense_remove_from_index!" : "typesense_index!")
|
369
369
|
end
|
370
370
|
elsif options[:enqueue].respond_to?(:call)
|
371
371
|
options[:enqueue]
|
@@ -542,7 +542,7 @@ module Typesense
|
|
542
542
|
end
|
543
543
|
jsonl_object = documents.join("\n")
|
544
544
|
ImportJob.perform(jsonl_object, collection_obj[:alias_name], batch_size)
|
545
|
-
Rails.logger.
|
545
|
+
Rails.logger.debug "#{objects.length} objects enqueued for import into #{collection_obj[:collection_name]}"
|
546
546
|
end
|
547
547
|
nil
|
548
548
|
end
|
@@ -557,7 +557,7 @@ module Typesense
|
|
557
557
|
end
|
558
558
|
jsonl_object = documents.join("\n")
|
559
559
|
import_documents(jsonl_object, "upsert", collection_obj[:alias_name], batch_size: batch_size)
|
560
|
-
Rails.logger.
|
560
|
+
Rails.logger.debug "#{objects.length} objects upserted into #{collection_obj[:collection_name]}!"
|
561
561
|
end
|
562
562
|
nil
|
563
563
|
end
|
@@ -613,7 +613,7 @@ module Typesense
|
|
613
613
|
rescue Typesense::Error::ObjectNotFound => e
|
614
614
|
Rails.logger.error "Object #{object_id} could not be removed from #{collection_obj[:collection_name]} collection! Use reindex to update the collection."
|
615
615
|
end
|
616
|
-
Rails.logger.
|
616
|
+
Rails.logger.debug "Removed document with object id '#{object_id}' from #{collection_obj[:collection_name]}"
|
617
617
|
end
|
618
618
|
nil
|
619
619
|
end
|
@@ -626,7 +626,7 @@ module Typesense
|
|
626
626
|
collection_obj = typesense_ensure_init(options, settings, false)
|
627
627
|
|
628
628
|
delete_collection(collection_obj[:alias_name])
|
629
|
-
Rails.logger.
|
629
|
+
Rails.logger.debug "Deleted #{collection_obj[:alias_name]} collection!"
|
630
630
|
@typesense_indexes[settings] = nil
|
631
631
|
end
|
632
632
|
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.rc3
|
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-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|