typesense 3.0.1 → 3.2.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0b16a7f00600eadbcf0769d6eec67994e52d89784d4d5900dbbb2cd4ea23b364
4
- data.tar.gz: 4a278a32c83aaff66f7fb23f8e9688f222604c5f90f25236a3eb55b1416247c5
3
+ metadata.gz: d9adfab903d2cd5d7063cde39ee3db9c0be4b736c714fd146d0527c18e27b683
4
+ data.tar.gz: e2117b54725a861fbf989097100b44ae72a78a781c1b610b7aa12d81ad086b8f
5
5
  SHA512:
6
- metadata.gz: 179ee2a5b661699d0fc7eb311f92dcd1ec913ed9aae99a13124f96ad3ef314ac872a1db4cee70f0d8abd84011a8887cf7d188bdd048219151d7f843700763f3b
7
- data.tar.gz: 4aedda18915d7c2f3f17626d3d9b90cc1ddd4fa81f828536235d9775fcc1e9de0c838bde2988f3de38b337ab1a7b6e5b489547e07cfa9101754cb5a0ce2a05aa
6
+ metadata.gz: 0c29843ebf31fad00242a59c2b01e9fe9389bc5444545715b32abe84955c00576e308f2d69f5615870b67cf3f83ae41d27aae8f15f51e7142b454815e7315f30
7
+ data.tar.gz: 951e630fb0ab2fe2aa1d18366857d5c1326eb9dbfaaae34e17cc17e5d5f61370893af6b26f7aadbb32fb9cd61b758527802d9e61733077893c62abcd85abb243
data/.gitignore CHANGED
@@ -1,4 +1,5 @@
1
1
  /.bundle/
2
+ /vendor/
2
3
  /.yardoc
3
4
  /_yardoc/
4
5
  /coverage/
data/.rubocop.yml CHANGED
@@ -1,4 +1,4 @@
1
- require: rubocop-rspec
1
+ plugins: rubocop-rspec
2
2
 
3
3
  AllCops:
4
4
  NewCops: enable
@@ -48,4 +48,4 @@ RSpec/MultipleExpectations:
48
48
  Enabled: false
49
49
 
50
50
  Style/HashSyntax:
51
- Enabled: false # We still want to support older versions of Ruby
51
+ Enabled: false # We still want to support older versions of Ruby
data/Gemfile CHANGED
@@ -16,7 +16,7 @@ gem 'rspec', '~> 3.9'
16
16
  gem 'rspec_junit_formatter', '~> 0.4'
17
17
  gem 'rspec-legacy_formatters', '~> 1.0' # For codecov formatter
18
18
  gem 'rubocop', '~> 1.12'
19
- gem 'rubocop-rspec', '~> 2.4', require: false
19
+ gem 'rubocop-rspec', '~> 3.6', require: false
20
20
  gem 'simplecov', '~> 0.18'
21
21
  gem 'timecop', '~> 0.9'
22
22
  gem 'webmock', '~> 3.8'
@@ -147,8 +147,8 @@ ap collection
147
147
 
148
148
  ###
149
149
  # Truncate a collection
150
- # Deletion returns the number of documents deleted
151
- collection = @typesense.collections['companies'].truncate
150
+ # Truncation returns the number of documents deleted
151
+ collection = @typesense.collections['companies'].documents.truncate
152
152
  ap collection
153
153
 
154
154
  # {
@@ -24,7 +24,7 @@ module Typesense
24
24
  private
25
25
 
26
26
  def endpoint_path(operation = nil)
27
- "#{AnalyticsRules::RESOURCE_PATH}#{operation.nil? ? '' : "/#{URI.encode_www_form_component(operation)}"}"
27
+ "#{AnalyticsRules::RESOURCE_PATH}#{"/#{URI.encode_www_form_component(operation)}" unless operation.nil?}"
28
28
  end
29
29
  end
30
30
  end
@@ -85,7 +85,7 @@ module Typesense
85
85
  req.body = body
86
86
  end
87
87
  end
88
- set_node_healthcheck(node, is_healthy: true) if response.status >= 1 && response.status <= 499
88
+ set_node_healthcheck(node, is_healthy: true) if response.status.between?(1, 499)
89
89
 
90
90
  @logger.debug "Request #{method}:#{uri_for(endpoint, node)} to Node #{node[:index]} was successfully made (at the network layer). response.status was #{response.status}."
91
91
 
@@ -96,7 +96,7 @@ module Typesense
96
96
  end
97
97
 
98
98
  # If response is 2xx return the object, else raise the response as an exception
99
- return parsed_response if response.status >= 200 && response.status <= 299
99
+ return parsed_response if response.status.between?(200, 299)
100
100
 
101
101
  exception_message = (parsed_response && parsed_response['message']) || 'Error'
102
102
  raise custom_exception_klass_for(response), exception_message
@@ -190,7 +190,7 @@ module Typesense
190
190
  Typesense::Error::ObjectAlreadyExists.new(response: response)
191
191
  elsif response.status == 422
192
192
  Typesense::Error::ObjectUnprocessable.new(response: response)
193
- elsif response.status >= 500 && response.status <= 599
193
+ elsif response.status.between?(500, 599)
194
194
  Typesense::Error::ServerError.new(response: response)
195
195
  elsif response.respond_to?(:timed_out?) && response.timed_out?
196
196
  Typesense::Error::TimeoutError.new(response: response)
@@ -3,7 +3,7 @@
3
3
  module Typesense
4
4
  class Client
5
5
  attr_reader :configuration, :collections, :aliases, :keys, :debug, :health, :metrics, :stats, :operations,
6
- :multi_search, :analytics, :presets, :stemming
6
+ :multi_search, :analytics, :presets, :stemming, :nl_search_models
7
7
 
8
8
  def initialize(options = {})
9
9
  @configuration = Configuration.new(options)
@@ -20,6 +20,7 @@ module Typesense
20
20
  @analytics = Analytics.new(@api_call)
21
21
  @stemming = Stemming.new(@api_call)
22
22
  @presets = Presets.new(@api_call)
23
+ @nl_search_models = NlSearchModels.new(@api_call)
23
24
  end
24
25
  end
25
26
  end
@@ -50,7 +50,16 @@ module Typesense
50
50
  )
51
51
 
52
52
  if documents.is_a?(Array)
53
- results_in_jsonl_format.split("\n").map { |r| Oj.load(r) }
53
+ results_in_jsonl_format.split("\n").map do |r|
54
+ Oj.load(r)
55
+ rescue Oj::ParseError => e
56
+ {
57
+ 'success' => false,
58
+ 'exception' => e.class.name,
59
+ 'error' => e.message,
60
+ 'json' => r
61
+ }
62
+ end
54
63
  else
55
64
  results_in_jsonl_format
56
65
  end
@@ -79,7 +88,7 @@ module Typesense
79
88
  private
80
89
 
81
90
  def endpoint_path(operation = nil)
82
- "#{Collections::RESOURCE_PATH}/#{URI.encode_www_form_component(@collection_name)}#{Documents::RESOURCE_PATH}#{operation.nil? ? '' : "/#{operation}"}"
91
+ "#{Collections::RESOURCE_PATH}/#{URI.encode_www_form_component(@collection_name)}#{Documents::RESOURCE_PATH}#{"/#{operation}" unless operation.nil?}"
83
92
  end
84
93
  end
85
94
  end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Typesense
4
+ class NlSearchModel
5
+ def initialize(model_id, api_call)
6
+ @model_id = model_id
7
+ @api_call = api_call
8
+ end
9
+
10
+ def retrieve
11
+ @api_call.get(endpoint_path)
12
+ end
13
+
14
+ def update(update_schema)
15
+ @api_call.put(endpoint_path, update_schema)
16
+ end
17
+
18
+ def delete
19
+ @api_call.delete(endpoint_path)
20
+ end
21
+
22
+ private
23
+
24
+ def endpoint_path
25
+ "#{NlSearchModels::RESOURCE_PATH}/#{URI.encode_www_form_component(@model_id)}"
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Typesense
4
+ class NlSearchModels
5
+ RESOURCE_PATH = '/nl_search_models'
6
+
7
+ def initialize(api_call)
8
+ @api_call = api_call
9
+ @nl_search_models = {}
10
+ end
11
+
12
+ def create(schema)
13
+ @api_call.post(RESOURCE_PATH, schema)
14
+ end
15
+
16
+ def retrieve
17
+ @api_call.get(RESOURCE_PATH)
18
+ end
19
+
20
+ def [](model_id)
21
+ @nl_search_models[model_id] ||= NlSearchModel.new(model_id, @api_call)
22
+ end
23
+ end
24
+ end
@@ -25,7 +25,7 @@ module Typesense
25
25
  private
26
26
 
27
27
  def endpoint_path(operation = nil)
28
- "#{Collections::RESOURCE_PATH}/#{URI.encode_www_form_component(@collection_name)}#{Overrides::RESOURCE_PATH}#{operation.nil? ? '' : "/#{URI.encode_www_form_component(operation)}"}"
28
+ "#{Collections::RESOURCE_PATH}/#{URI.encode_www_form_component(@collection_name)}#{Overrides::RESOURCE_PATH}#{"/#{URI.encode_www_form_component(operation)}" unless operation.nil?}"
29
29
  end
30
30
  end
31
31
  end
@@ -24,7 +24,7 @@ module Typesense
24
24
  private
25
25
 
26
26
  def endpoint_path(operation = nil)
27
- "#{Presets::RESOURCE_PATH}#{operation.nil? ? '' : "/#{URI.encode_www_form_component(operation)}"}"
27
+ "#{Presets::RESOURCE_PATH}#{"/#{URI.encode_www_form_component(operation)}" unless operation.nil?}"
28
28
  end
29
29
  end
30
30
  end
@@ -43,7 +43,7 @@ module Typesense
43
43
  private
44
44
 
45
45
  def endpoint_path(operation = nil)
46
- "#{StemmingDictionaries::RESOURCE_PATH}#{operation.nil? ? '' : "/#{URI.encode_www_form_component(operation)}"}"
46
+ "#{StemmingDictionaries::RESOURCE_PATH}#{"/#{URI.encode_www_form_component(operation)}" unless operation.nil?}"
47
47
  end
48
48
  end
49
49
  end
@@ -25,7 +25,7 @@ module Typesense
25
25
  private
26
26
 
27
27
  def endpoint_path(operation = nil)
28
- "#{Collections::RESOURCE_PATH}/#{URI.encode_www_form_component(@collection_name)}#{Synonyms::RESOURCE_PATH}#{operation.nil? ? '' : "/#{URI.encode_www_form_component(operation)}"}"
28
+ "#{Collections::RESOURCE_PATH}/#{URI.encode_www_form_component(@collection_name)}#{Synonyms::RESOURCE_PATH}#{"/#{URI.encode_www_form_component(operation)}" unless operation.nil?}"
29
29
  end
30
30
  end
31
31
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Typesense
4
- VERSION = '3.0.1'
4
+ VERSION = '3.2.0'
5
5
  end
data/lib/typesense.rb CHANGED
@@ -35,3 +35,5 @@ require_relative 'typesense/error'
35
35
  require_relative 'typesense/stemming'
36
36
  require_relative 'typesense/stemming_dictionaries'
37
37
  require_relative 'typesense/stemming_dictionary'
38
+ require_relative 'typesense/nl_search_models'
39
+ require_relative 'typesense/nl_search_model'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: typesense
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.1
4
+ version: 3.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Typesense, Inc.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2025-02-24 00:00:00.000000000 Z
11
+ date: 2025-07-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: base64
@@ -99,6 +99,8 @@ files:
99
99
  - lib/typesense/keys.rb
100
100
  - lib/typesense/metrics.rb
101
101
  - lib/typesense/multi_search.rb
102
+ - lib/typesense/nl_search_model.rb
103
+ - lib/typesense/nl_search_models.rb
102
104
  - lib/typesense/operations.rb
103
105
  - lib/typesense/override.rb
104
106
  - lib/typesense/overrides.rb