typesense 5.0.0 → 5.1.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.
Files changed (56) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/tests.yml +2 -2
  3. data/.rubocop.yml +9 -1
  4. data/Gemfile +3 -7
  5. data/README.md +41 -0
  6. data/docker-compose.yml +1 -1
  7. data/flake.lock +61 -0
  8. data/flake.nix +56 -0
  9. data/lib/typesense/alias.rb +12 -0
  10. data/lib/typesense/aliases.rb +20 -0
  11. data/lib/typesense/analytics.rb +19 -0
  12. data/lib/typesense/analytics_events.rb +12 -0
  13. data/lib/typesense/analytics_events_v1.rb +6 -0
  14. data/lib/typesense/analytics_rule.rb +20 -1
  15. data/lib/typesense/analytics_rule_v1.rb +12 -0
  16. data/lib/typesense/analytics_rules.rb +34 -2
  17. data/lib/typesense/analytics_rules_v1.rb +20 -0
  18. data/lib/typesense/analytics_v1.rb +20 -0
  19. data/lib/typesense/api_call.rb +72 -5
  20. data/lib/typesense/client.rb +179 -2
  21. data/lib/typesense/collection.rb +56 -1
  22. data/lib/typesense/collections.rb +20 -0
  23. data/lib/typesense/configuration.rb +18 -4
  24. data/lib/typesense/curation_set.rb +29 -0
  25. data/lib/typesense/curation_set_item.rb +18 -0
  26. data/lib/typesense/curation_set_items.rb +14 -0
  27. data/lib/typesense/curation_sets.rb +20 -0
  28. data/lib/typesense/debug.rb +6 -0
  29. data/lib/typesense/document.rb +18 -0
  30. data/lib/typesense/documents.rb +62 -0
  31. data/lib/typesense/health.rb +6 -0
  32. data/lib/typesense/key.rb +12 -0
  33. data/lib/typesense/keys.rb +26 -0
  34. data/lib/typesense/metrics.rb +6 -0
  35. data/lib/typesense/multi_search.rb +8 -0
  36. data/lib/typesense/nl_search_model.rb +18 -0
  37. data/lib/typesense/nl_search_models.rb +20 -0
  38. data/lib/typesense/operations.rb +6 -0
  39. data/lib/typesense/override.rb +12 -0
  40. data/lib/typesense/overrides.rb +20 -0
  41. data/lib/typesense/preset.rb +12 -0
  42. data/lib/typesense/presets.rb +20 -0
  43. data/lib/typesense/stats.rb +6 -0
  44. data/lib/typesense/stemming.rb +11 -0
  45. data/lib/typesense/stemming_dictionaries.rb +20 -0
  46. data/lib/typesense/stemming_dictionary.rb +6 -0
  47. data/lib/typesense/synonym.rb +13 -0
  48. data/lib/typesense/synonym_set.rb +36 -0
  49. data/lib/typesense/synonym_set_item.rb +47 -0
  50. data/lib/typesense/synonym_set_items.rb +39 -0
  51. data/lib/typesense/synonym_sets.rb +20 -0
  52. data/lib/typesense/synonyms.rb +21 -0
  53. data/lib/typesense/version.rb +1 -1
  54. data/lib/typesense.rb +2 -0
  55. data/typesense.gemspec +5 -5
  56. metadata +46 -11
data/lib/typesense/key.rb CHANGED
@@ -7,10 +7,22 @@ module Typesense
7
7
  @api_call = api_call
8
8
  end
9
9
 
10
+ # Retrieve (metadata about) a key. Only the key prefix is returned when you retrieve a key. Due to security reasons, only the create endpoint returns the full API key.
11
+ #
12
+ # @example
13
+ # client.keys[1].retrieve
14
+ #
15
+ # @see https://typesense.org/docs/latest/api/api-keys.html#retrieve-an-api-key
10
16
  def retrieve
11
17
  @api_call.get(endpoint_path)
12
18
  end
13
19
 
20
+ # Delete an API key given its ID.
21
+ #
22
+ # @example
23
+ # client.keys[1].delete
24
+ #
25
+ # @see https://typesense.org/docs/latest/api/api-keys.html#delete-api-key
14
26
  def delete
15
27
  @api_call.delete(endpoint_path)
16
28
  end
@@ -13,14 +13,32 @@ module Typesense
13
13
  @keys = {}
14
14
  end
15
15
 
16
+ # Create an API Key with fine-grain access control. You can restrict access on both a per-collection and per-action level. The generated key is returned only during creation. You want to store this key carefully in a secure place.
17
+ #
18
+ # @example
19
+ # client.keys.create('description' => 'Search-only key', 'actions' => ['documents:search'], 'collections' => ['*'])
20
+ #
21
+ # @see https://typesense.org/docs/latest/api/api-keys.html#create-an-api-key
16
22
  def create(parameters)
17
23
  @api_call.post(RESOURCE_PATH, parameters)
18
24
  end
19
25
 
26
+ # Retrieve (metadata about) all keys.
27
+ #
28
+ # @example
29
+ # client.keys.retrieve
30
+ #
31
+ # @see https://typesense.org/docs/latest/api/api-keys.html#list-all-keys
20
32
  def retrieve
21
33
  @api_call.get(RESOURCE_PATH)
22
34
  end
23
35
 
36
+ # Generate a scoped search-only API key with embedded parameters such as `filter_by` or `expires_at`.
37
+ #
38
+ # @example
39
+ # client.keys.generate_scoped_search_key('search-only-key', 'filter_by' => 'company_id:124', 'expires_at' => 1700000000)
40
+ #
41
+ # @see https://typesense.org/docs/latest/api/api-keys.html#generate-scoped-search-key
24
42
  def generate_scoped_search_key(search_key, parameters)
25
43
  parameters_json = JSON.dump(parameters)
26
44
  digest = Base64.encode64(OpenSSL::HMAC.digest('sha256', search_key, parameters_json)).gsub("\n", '')
@@ -29,6 +47,14 @@ module Typesense
29
47
  Base64.encode64(raw_scoped_key).gsub("\n", '')
30
48
  end
31
49
 
50
+ # Access an individual API key by ID.
51
+ #
52
+ # @example
53
+ # client.keys[1].retrieve
54
+ #
55
+ # @see https://typesense.org/docs/latest/api/api-keys.html
56
+ #
57
+ # @return [Key]
32
58
  def [](id)
33
59
  @keys[id] ||= Key.new(id, @api_call)
34
60
  end
@@ -8,6 +8,12 @@ module Typesense
8
8
  @api_call = api_call
9
9
  end
10
10
 
11
+ # Get current RAM, CPU, Disk & Network usage metrics.
12
+ #
13
+ # @example
14
+ # client.metrics.retrieve
15
+ #
16
+ # @see https://typesense.org/docs/latest/api/cluster-operations.html
11
17
  def retrieve
12
18
  @api_call.get(RESOURCE_PATH)
13
19
  end
@@ -8,6 +8,14 @@ module Typesense
8
8
  @api_call = api_call
9
9
  end
10
10
 
11
+ # Send multiple search requests in a single HTTP request. Pass `union: true` to merge results, or omit it to receive a `results` array.
12
+ #
13
+ # @example
14
+ # client.multi_search.perform('searches' => [{ 'collection' => 'products', 'q' => '*' }])
15
+ # @example
16
+ # client.multi_search.perform('union' => true, 'searches' => [{ 'collection' => 'products', 'q' => '*' }])
17
+ #
18
+ # @see https://typesense.org/docs/latest/api/documents.html#federated-multi-search
11
19
  def perform(searches, query_params = {})
12
20
  @api_call.post(RESOURCE_PATH, searches, query_params)
13
21
  end
@@ -7,14 +7,32 @@ module Typesense
7
7
  @api_call = api_call
8
8
  end
9
9
 
10
+ # Retrieve a specific NL search model by its ID.
11
+ #
12
+ # @example
13
+ # client.nl_search_models['model-1'].retrieve
14
+ #
15
+ # @see https://typesense.org/docs/latest/api/natural-language-search.html
10
16
  def retrieve
11
17
  @api_call.get(endpoint_path)
12
18
  end
13
19
 
20
+ # Update an existing NL search model.
21
+ #
22
+ # @example
23
+ # client.nl_search_models['model-1'].update('model_name' => 'openai/gpt-4')
24
+ #
25
+ # @see https://typesense.org/docs/latest/api/natural-language-search.html
14
26
  def update(update_schema)
15
27
  @api_call.put(endpoint_path, update_schema)
16
28
  end
17
29
 
30
+ # Delete a specific NL search model by its ID.
31
+ #
32
+ # @example
33
+ # client.nl_search_models['model-1'].delete
34
+ #
35
+ # @see https://typesense.org/docs/latest/api/natural-language-search.html
18
36
  def delete
19
37
  @api_call.delete(endpoint_path)
20
38
  end
@@ -9,14 +9,34 @@ module Typesense
9
9
  @nl_search_models = {}
10
10
  end
11
11
 
12
+ # Create a new NL search model.
13
+ #
14
+ # @example
15
+ # client.nl_search_models.create('model_name' => 'openai/gpt-4', 'api_key' => '...')
16
+ #
17
+ # @see https://typesense.org/docs/latest/api/natural-language-search.html
12
18
  def create(schema)
13
19
  @api_call.post(RESOURCE_PATH, schema)
14
20
  end
15
21
 
22
+ # Retrieve all NL search models.
23
+ #
24
+ # @example
25
+ # client.nl_search_models.retrieve
26
+ #
27
+ # @see https://typesense.org/docs/latest/api/natural-language-search.html
16
28
  def retrieve
17
29
  @api_call.get(RESOURCE_PATH)
18
30
  end
19
31
 
32
+ # Access an individual NL search model by ID.
33
+ #
34
+ # @example
35
+ # client.nl_search_models['model-1'].retrieve
36
+ #
37
+ # @see https://typesense.org/docs/latest/api/natural-language-search.html
38
+ #
39
+ # @return [NlSearchModel]
20
40
  def [](model_id)
21
41
  @nl_search_models[model_id] ||= NlSearchModel.new(model_id, @api_call)
22
42
  end
@@ -8,6 +8,12 @@ module Typesense
8
8
  @api_call = api_call
9
9
  end
10
10
 
11
+ # Perform a cluster operation: snapshot, vote, cache/clear, db/compact, or a custom path.
12
+ #
13
+ # @example
14
+ # client.operations.perform('snapshot', 'snapshot_path' => '/tmp/snap')
15
+ #
16
+ # @see https://typesense.org/docs/latest/api/cluster-operations.html
11
17
  def perform(operation_name, query_params = {})
12
18
  @api_call.post("#{RESOURCE_PATH}/#{operation_name}", {}, query_params)
13
19
  end
@@ -8,10 +8,22 @@ module Typesense
8
8
  @api_call = api_call
9
9
  end
10
10
 
11
+ # Retrieve an override (curation rule) by ID on this collection.
12
+ #
13
+ # @example
14
+ # client.collections['products'].overrides['promote-hat'].retrieve
15
+ #
16
+ # @see https://typesense.org/docs/latest/api/curation.html
11
17
  def retrieve
12
18
  @api_call.get(endpoint_path)
13
19
  end
14
20
 
21
+ # Delete an override (curation rule) by ID on this collection.
22
+ #
23
+ # @example
24
+ # client.collections['products'].overrides['promote-hat'].delete
25
+ #
26
+ # @see https://typesense.org/docs/latest/api/curation.html
15
27
  def delete
16
28
  @api_call.delete(endpoint_path)
17
29
  end
@@ -10,14 +10,34 @@ module Typesense
10
10
  @overrides = {}
11
11
  end
12
12
 
13
+ # Create or update an override (curation rule) on this collection.
14
+ #
15
+ # @example
16
+ # client.collections['products'].overrides.upsert('promote-hat', 'rule' => { 'query' => 'hat', 'match' => 'exact' }, 'includes' => [])
17
+ #
18
+ # @see https://typesense.org/docs/latest/api/curation.html
13
19
  def upsert(override_id, params)
14
20
  @api_call.put(endpoint_path(override_id), params)
15
21
  end
16
22
 
23
+ # Retrieve all overrides (curation rules) on this collection.
24
+ #
25
+ # @example
26
+ # client.collections['products'].overrides.retrieve
27
+ #
28
+ # @see https://typesense.org/docs/latest/api/curation.html
17
29
  def retrieve
18
30
  @api_call.get(endpoint_path)
19
31
  end
20
32
 
33
+ # Access an individual override by ID within this collection.
34
+ #
35
+ # @example
36
+ # client.collections['products'].overrides['promote-hat'].retrieve
37
+ #
38
+ # @see https://typesense.org/docs/latest/api/curation.html
39
+ #
40
+ # @return [Override]
21
41
  def [](override_id)
22
42
  @overrides[override_id] ||= Override.new(@collection_name, override_id, @api_call)
23
43
  end
@@ -7,10 +7,22 @@ module Typesense
7
7
  @api_call = api_call
8
8
  end
9
9
 
10
+ # Retrieve the details of a preset, given it's name.
11
+ #
12
+ # @example
13
+ # client.presets['listing_view'].retrieve
14
+ #
15
+ # @see https://typesense.org/docs/latest/api/search.html#presets
10
16
  def retrieve
11
17
  @api_call.get(endpoint_path)
12
18
  end
13
19
 
20
+ # Permanently deletes a preset, given it's name.
21
+ #
22
+ # @example
23
+ # client.presets['listing_view'].delete
24
+ #
25
+ # @see https://typesense.org/docs/latest/api/search.html#presets
14
26
  def delete
15
27
  @api_call.delete(endpoint_path)
16
28
  end
@@ -9,14 +9,34 @@ module Typesense
9
9
  @presets = {}
10
10
  end
11
11
 
12
+ # Create or update an existing preset.
13
+ #
14
+ # @example
15
+ # client.presets.upsert('listing_view', 'value' => { 'q' => '*' })
16
+ #
17
+ # @see https://typesense.org/docs/latest/api/search.html#presets
12
18
  def upsert(preset_name, params)
13
19
  @api_call.put(endpoint_path(preset_name), params)
14
20
  end
15
21
 
22
+ # Retrieve the details of all presets
23
+ #
24
+ # @example
25
+ # client.presets.retrieve
26
+ #
27
+ # @see https://typesense.org/docs/latest/api/search.html#presets
16
28
  def retrieve
17
29
  @api_call.get(endpoint_path)
18
30
  end
19
31
 
32
+ # Access an individual preset by ID.
33
+ #
34
+ # @example
35
+ # client.presets['listing_view'].retrieve
36
+ #
37
+ # @see https://typesense.org/docs/latest/api/search.html#presets
38
+ #
39
+ # @return [Preset]
20
40
  def [](preset_name)
21
41
  @presets[preset_name] ||= Preset.new(preset_name, @api_call)
22
42
  end
@@ -8,6 +8,12 @@ module Typesense
8
8
  @api_call = api_call
9
9
  end
10
10
 
11
+ # Get stats about API endpoints.
12
+ #
13
+ # @example
14
+ # client.stats.retrieve
15
+ #
16
+ # @see https://typesense.org/docs/latest/api/cluster-operations.html
11
17
  def retrieve
12
18
  @api_call.get(RESOURCE_PATH)
13
19
  end
@@ -8,6 +8,17 @@ module Typesense
8
8
  @api_call = api_call
9
9
  end
10
10
 
11
+ # Access the stemming dictionaries resource. Use it to list or import dictionaries, or as an array
12
+ # to access a single dictionary by ID.
13
+ #
14
+ # @example
15
+ # client.stemming.dictionaries.retrieve
16
+ # @example
17
+ # client.stemming.dictionaries['en'].retrieve
18
+ #
19
+ # @see https://typesense.org/docs/latest/api/stemming.html
20
+ #
21
+ # @return [StemmingDictionaries]
11
22
  def dictionaries
12
23
  @dictionaries ||= StemmingDictionaries.new(@api_call)
13
24
  end
@@ -9,6 +9,12 @@ module Typesense
9
9
  @dictionaries = {}
10
10
  end
11
11
 
12
+ # Upload a JSONL file containing word mappings to create or update a stemming dictionary.
13
+ #
14
+ # @example
15
+ # client.stemming.dictionaries.upsert('irregular-plurals', [{ 'word' => 'people', 'root' => 'person' }])
16
+ #
17
+ # @see https://typesense.org/docs/latest/api/stemming.html
12
18
  def upsert(dict_id, words_and_roots_combinations)
13
19
  words_and_roots_combinations_in_jsonl = if words_and_roots_combinations.is_a?(Array)
14
20
  words_and_roots_combinations.map { |combo| JSON.dump(combo) }.join("\n")
@@ -31,11 +37,25 @@ module Typesense
31
37
  end
32
38
  end
33
39
 
40
+ # Retrieve a list of all available stemming dictionaries.
41
+ #
42
+ # @example
43
+ # client.stemming.dictionaries.retrieve
44
+ #
45
+ # @see https://typesense.org/docs/latest/api/stemming.html
34
46
  def retrieve
35
47
  response = @api_call.get(endpoint_path)
36
48
  response || { 'dictionaries' => [] }
37
49
  end
38
50
 
51
+ # Access an individual stemming dictionary by ID.
52
+ #
53
+ # @example
54
+ # client.stemming.dictionaries['en'].retrieve
55
+ #
56
+ # @see https://typesense.org/docs/latest/api/stemming.html
57
+ #
58
+ # @return [StemmingDictionary]
39
59
  def [](dict_id)
40
60
  @dictionaries[dict_id] ||= StemmingDictionary.new(dict_id, @api_call)
41
61
  end
@@ -7,6 +7,12 @@ module Typesense
7
7
  @api_call = api_call
8
8
  end
9
9
 
10
+ # Fetch details of a specific stemming dictionary.
11
+ #
12
+ # @example
13
+ # client.stemming.dictionaries['en'].retrieve
14
+ #
15
+ # @see https://typesense.org/docs/latest/api/stemming.html
10
16
  def retrieve
11
17
  @api_call.get(endpoint_path)
12
18
  end
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Typesense
4
+ # @deprecated Deprecated starting with Typesense Server v30. Please migrate to `client.synonym_sets` (new Synonym Sets APIs).
4
5
  class Synonym
5
6
  def initialize(collection_name, synonym_id, api_call)
6
7
  @collection_name = collection_name
@@ -8,10 +9,22 @@ module Typesense
8
9
  @api_call = api_call
9
10
  end
10
11
 
12
+ # Retrieve a synonym (legacy v1) by ID on this collection.
13
+ #
14
+ # @example
15
+ # client.collections['products'].synonyms['syn-1'].retrieve
16
+ #
17
+ # @see https://typesense.org/docs/29.0/api/synonyms.html
11
18
  def retrieve
12
19
  @api_call.get(endpoint_path)
13
20
  end
14
21
 
22
+ # Delete a synonym (legacy v1) by ID on this collection.
23
+ #
24
+ # @example
25
+ # client.collections['products'].synonyms['syn-1'].delete
26
+ #
27
+ # @see https://typesense.org/docs/29.0/api/synonyms.html
15
28
  def delete
16
29
  @api_call.delete(endpoint_path)
17
30
  end
@@ -2,15 +2,51 @@
2
2
 
3
3
  module Typesense
4
4
  class SynonymSet
5
+ # Access the items in this synonym set. Use it to list items, or as an array
6
+ # to access a single item by ID.
7
+ #
8
+ # @example
9
+ # client.synonym_sets['my-set'].items.retrieve
10
+ # @example
11
+ # client.synonym_sets['my-set'].items['smart-phone-synonyms'].retrieve
12
+ #
13
+ # @see https://typesense.org/docs/latest/api/synonyms.html
14
+ #
15
+ # @return [SynonymSetItems]
16
+ attr_reader :items
17
+
5
18
  def initialize(synonym_set_name, api_call)
6
19
  @synonym_set_name = synonym_set_name
7
20
  @api_call = api_call
21
+ @items = SynonymSetItems.new(@synonym_set_name, @api_call)
22
+ end
23
+
24
+ # Create or update a synonym set with the given name
25
+ #
26
+ # @example
27
+ # client.synonym_sets['my-set'].upsert('items' => [{ 'id' => 'syn-1', 'synonyms' => ['nyc', 'new york'] }])
28
+ #
29
+ # @see https://typesense.org/docs/latest/api/synonyms.html
30
+ def upsert(params)
31
+ @api_call.put(endpoint_path, params)
8
32
  end
9
33
 
34
+ # Retrieve a specific synonym set by its name
35
+ #
36
+ # @example
37
+ # client.synonym_sets['my-set'].retrieve
38
+ #
39
+ # @see https://typesense.org/docs/latest/api/synonyms.html
10
40
  def retrieve
11
41
  @api_call.get(endpoint_path)
12
42
  end
13
43
 
44
+ # Delete a specific synonym set by its name
45
+ #
46
+ # @example
47
+ # client.synonym_sets['my-set'].delete
48
+ #
49
+ # @see https://typesense.org/docs/latest/api/synonyms.html
14
50
  def delete
15
51
  @api_call.delete(endpoint_path)
16
52
  end
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Typesense
4
+ class SynonymSetItem
5
+ def initialize(synonym_set_name, item_id, api_call)
6
+ @synonym_set_name = synonym_set_name
7
+ @item_id = item_id
8
+ @api_call = api_call
9
+ end
10
+
11
+ # Retrieve a specific synonym item by its id
12
+ #
13
+ # @example
14
+ # client.synonym_sets['my-set'].items['smart-phone-synonyms'].retrieve
15
+ #
16
+ # @see https://typesense.org/docs/latest/api/synonyms.html
17
+ def retrieve
18
+ @api_call.get(endpoint_path)
19
+ end
20
+
21
+ # Create or update a synonym item with the given id
22
+ #
23
+ # @example
24
+ # client.synonym_sets['my-set'].items['smart-phone-synonyms'].upsert('synonyms' => ['smart phone', 'iphone'])
25
+ #
26
+ # @see https://typesense.org/docs/latest/api/synonyms.html
27
+ def upsert(params)
28
+ @api_call.put(endpoint_path, params)
29
+ end
30
+
31
+ # Delete a specific synonym item by its id
32
+ #
33
+ # @example
34
+ # client.synonym_sets['my-set'].items['smart-phone-synonyms'].delete
35
+ #
36
+ # @see https://typesense.org/docs/latest/api/synonyms.html
37
+ def delete
38
+ @api_call.delete(endpoint_path)
39
+ end
40
+
41
+ private
42
+
43
+ def endpoint_path
44
+ "#{SynonymSets::RESOURCE_PATH}/#{URI.encode_www_form_component(@synonym_set_name)}/items/#{URI.encode_www_form_component(@item_id)}"
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Typesense
4
+ class SynonymSetItems
5
+ def initialize(synonym_set_name, api_call)
6
+ @synonym_set_name = synonym_set_name
7
+ @api_call = api_call
8
+ @items = {}
9
+ end
10
+
11
+ # Retrieve all synonym items in a set
12
+ #
13
+ # @example
14
+ # client.synonym_sets['my-set'].items.retrieve
15
+ #
16
+ # @see https://typesense.org/docs/latest/api/synonyms.html
17
+ def retrieve
18
+ @api_call.get(endpoint_path)
19
+ end
20
+
21
+ # Access an individual synonym item by ID within this synonym set.
22
+ #
23
+ # @example
24
+ # client.synonym_sets['my-set'].items['smart-phone-synonyms'].retrieve
25
+ #
26
+ # @see https://typesense.org/docs/latest/api/synonyms.html
27
+ #
28
+ # @return [SynonymSetItem]
29
+ def [](item_id)
30
+ @items[item_id] ||= SynonymSetItem.new(@synonym_set_name, item_id, @api_call)
31
+ end
32
+
33
+ private
34
+
35
+ def endpoint_path
36
+ "#{SynonymSets::RESOURCE_PATH}/#{URI.encode_www_form_component(@synonym_set_name)}/items"
37
+ end
38
+ end
39
+ end
@@ -9,14 +9,34 @@ module Typesense
9
9
  @synonym_sets = {}
10
10
  end
11
11
 
12
+ # Create or update a synonym set with the given name
13
+ #
14
+ # @example
15
+ # client.synonym_sets.upsert('my-set', 'items' => [{ 'id' => 'syn-1', 'synonyms' => ['nyc', 'new york'] }])
16
+ #
17
+ # @see https://typesense.org/docs/latest/api/synonyms.html
12
18
  def upsert(synonym_set_name, params)
13
19
  @api_call.put(endpoint_path(synonym_set_name), params)
14
20
  end
15
21
 
22
+ # Retrieve all synonym sets
23
+ #
24
+ # @example
25
+ # client.synonym_sets.retrieve
26
+ #
27
+ # @see https://typesense.org/docs/latest/api/synonyms.html
16
28
  def retrieve
17
29
  @api_call.get(endpoint_path)
18
30
  end
19
31
 
32
+ # Access an individual synonym set by name.
33
+ #
34
+ # @example
35
+ # client.synonym_sets['my-set'].retrieve
36
+ #
37
+ # @see https://typesense.org/docs/latest/api/synonyms.html
38
+ #
39
+ # @return [SynonymSet]
20
40
  def [](synonym_set_name)
21
41
  @synonym_sets[synonym_set_name] ||= SynonymSet.new(synonym_set_name, @api_call)
22
42
  end
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Typesense
4
+ # @deprecated Deprecated starting with Typesense Server v30. Please migrate to `client.synonym_sets` (new Synonym Sets APIs).
4
5
  class Synonyms
5
6
  RESOURCE_PATH = '/synonyms'
6
7
 
@@ -10,14 +11,34 @@ module Typesense
10
11
  @synonyms = {}
11
12
  end
12
13
 
14
+ # Create or update a synonym (legacy v1) on this collection.
15
+ #
16
+ # @example
17
+ # client.collections['products'].synonyms.upsert('syn-1', 'synonyms' => ['nyc', 'new york'])
18
+ #
19
+ # @see https://typesense.org/docs/29.0/api/synonyms.html
13
20
  def upsert(synonym_id, params)
14
21
  @api_call.put(endpoint_path(synonym_id), params)
15
22
  end
16
23
 
24
+ # Retrieve all synonyms (legacy v1) on this collection.
25
+ #
26
+ # @example
27
+ # client.collections['products'].synonyms.retrieve
28
+ #
29
+ # @see https://typesense.org/docs/29.0/api/synonyms.html
17
30
  def retrieve
18
31
  @api_call.get(endpoint_path)
19
32
  end
20
33
 
34
+ # Access an individual synonym by ID within this collection.
35
+ #
36
+ # @example
37
+ # client.collections['products'].synonyms['syn-1'].retrieve
38
+ #
39
+ # @see https://typesense.org/docs/29.0/api/synonyms.html
40
+ #
41
+ # @return [Synonym]
21
42
  def [](synonym_id)
22
43
  @synonyms[synonym_id] ||= Synonym.new(@collection_name, synonym_id, @api_call)
23
44
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Typesense
4
- VERSION = '5.0.0'
4
+ VERSION = '5.1.0'
5
5
  end
data/lib/typesense.rb CHANGED
@@ -18,6 +18,8 @@ require_relative 'typesense/synonyms'
18
18
  require_relative 'typesense/synonym'
19
19
  require_relative 'typesense/synonym_sets'
20
20
  require_relative 'typesense/synonym_set'
21
+ require_relative 'typesense/synonym_set_items'
22
+ require_relative 'typesense/synonym_set_item'
21
23
  require_relative 'typesense/aliases'
22
24
  require_relative 'typesense/alias'
23
25
  require_relative 'typesense/keys'