typesense 4.1.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.
- checksums.yaml +4 -4
- data/.github/workflows/tests.yml +2 -2
- data/.rubocop.yml +9 -1
- data/Gemfile +3 -7
- data/README.md +42 -0
- data/docker-compose.yml +1 -1
- data/flake.lock +61 -0
- data/flake.nix +56 -0
- data/lib/typesense/alias.rb +12 -0
- data/lib/typesense/aliases.rb +20 -0
- data/lib/typesense/analytics.rb +23 -0
- data/lib/typesense/analytics_events.rb +31 -0
- data/lib/typesense/analytics_events_v1.rb +27 -0
- data/lib/typesense/analytics_rule.rb +23 -0
- data/lib/typesense/analytics_rule_v1.rb +36 -0
- data/lib/typesense/analytics_rules.rb +37 -12
- data/lib/typesense/analytics_rules_v1.rb +50 -0
- data/lib/typesense/analytics_v1.rb +39 -0
- data/lib/typesense/api_call.rb +72 -5
- data/lib/typesense/client.rb +182 -2
- data/lib/typesense/collection.rb +56 -1
- data/lib/typesense/collections.rb +20 -0
- data/lib/typesense/configuration.rb +18 -4
- data/lib/typesense/curation_set.rb +60 -0
- data/lib/typesense/curation_set_item.rb +47 -0
- data/lib/typesense/curation_set_items.rb +39 -0
- data/lib/typesense/curation_sets.rb +43 -0
- data/lib/typesense/debug.rb +6 -0
- data/lib/typesense/document.rb +18 -0
- data/lib/typesense/documents.rb +62 -0
- data/lib/typesense/health.rb +6 -0
- data/lib/typesense/key.rb +12 -0
- data/lib/typesense/keys.rb +26 -0
- data/lib/typesense/metrics.rb +6 -0
- data/lib/typesense/multi_search.rb +8 -0
- data/lib/typesense/nl_search_model.rb +18 -0
- data/lib/typesense/nl_search_models.rb +20 -0
- data/lib/typesense/operations.rb +6 -0
- data/lib/typesense/override.rb +12 -0
- data/lib/typesense/overrides.rb +20 -0
- data/lib/typesense/preset.rb +12 -0
- data/lib/typesense/presets.rb +20 -0
- data/lib/typesense/stats.rb +6 -0
- data/lib/typesense/stemming.rb +11 -0
- data/lib/typesense/stemming_dictionaries.rb +20 -0
- data/lib/typesense/stemming_dictionary.rb +6 -0
- data/lib/typesense/synonym.rb +13 -0
- data/lib/typesense/synonym_set.rb +60 -0
- data/lib/typesense/synonym_set_item.rb +47 -0
- data/lib/typesense/synonym_set_items.rb +39 -0
- data/lib/typesense/synonym_sets.rb +50 -0
- data/lib/typesense/synonyms.rb +21 -0
- data/lib/typesense/version.rb +1 -1
- data/lib/typesense.rb +13 -0
- data/typesense.gemspec +5 -5
- metadata +57 -11
data/lib/typesense/document.rb
CHANGED
|
@@ -8,14 +8,32 @@ module Typesense
|
|
|
8
8
|
@api_call = api_call
|
|
9
9
|
end
|
|
10
10
|
|
|
11
|
+
# Fetch an individual document from a collection by using its ID.
|
|
12
|
+
#
|
|
13
|
+
# @example
|
|
14
|
+
# client.collections['products'].documents['1'].retrieve
|
|
15
|
+
#
|
|
16
|
+
# @see https://typesense.org/docs/latest/api/documents.html#retrieve-a-document
|
|
11
17
|
def retrieve
|
|
12
18
|
@api_call.get(endpoint_path)
|
|
13
19
|
end
|
|
14
20
|
|
|
21
|
+
# Delete an individual document from a collection by using its ID.
|
|
22
|
+
#
|
|
23
|
+
# @example
|
|
24
|
+
# client.collections['products'].documents['1'].delete
|
|
25
|
+
#
|
|
26
|
+
# @see https://typesense.org/docs/latest/api/documents.html#delete-a-document
|
|
15
27
|
def delete
|
|
16
28
|
@api_call.delete(endpoint_path)
|
|
17
29
|
end
|
|
18
30
|
|
|
31
|
+
# Update an individual document by ID by merging the provided fields.
|
|
32
|
+
#
|
|
33
|
+
# @example
|
|
34
|
+
# client.collections['products'].documents['1'].update('in_stock' => true)
|
|
35
|
+
#
|
|
36
|
+
# @see https://typesense.org/docs/latest/api/documents.html#update-a-document
|
|
19
37
|
def update(partial_document, options = {})
|
|
20
38
|
@api_call.patch(endpoint_path, partial_document, options)
|
|
21
39
|
end
|
data/lib/typesense/documents.rb
CHANGED
|
@@ -12,14 +12,34 @@ module Typesense
|
|
|
12
12
|
@documents = {}
|
|
13
13
|
end
|
|
14
14
|
|
|
15
|
+
# Index a single document. The document must conform to the schema of the collection.
|
|
16
|
+
#
|
|
17
|
+
# @example
|
|
18
|
+
# client.collections['products'].documents.create('id' => '1', 'title' => 'Hat')
|
|
19
|
+
#
|
|
20
|
+
# @see https://typesense.org/docs/latest/api/documents.html#index-a-single-document
|
|
15
21
|
def create(document, options = {})
|
|
16
22
|
@api_call.post(endpoint_path, document, options)
|
|
17
23
|
end
|
|
18
24
|
|
|
25
|
+
# Upsert a single document. Creates the document if it does not exist, otherwise updates it.
|
|
26
|
+
#
|
|
27
|
+
# @example
|
|
28
|
+
# client.collections['products'].documents.upsert('id' => '1', 'title' => 'Hat')
|
|
29
|
+
#
|
|
30
|
+
# @see https://typesense.org/docs/latest/api/documents.html#upsert
|
|
19
31
|
def upsert(document, options = {})
|
|
20
32
|
@api_call.post(endpoint_path, document, options.merge(action: :upsert))
|
|
21
33
|
end
|
|
22
34
|
|
|
35
|
+
# Update documents matching a `filter_by` condition, or update a single document with `action: "update"` semantics.
|
|
36
|
+
#
|
|
37
|
+
# @example
|
|
38
|
+
# client.collections['products'].documents.update({ 'in_stock' => true }, filter_by: 'category:=hats')
|
|
39
|
+
# @example
|
|
40
|
+
# client.collections['products'].documents.update('id' => '1', 'title' => 'Hat')
|
|
41
|
+
#
|
|
42
|
+
# @see https://typesense.org/docs/latest/api/documents.html#update-documents-with-conditional-query
|
|
23
43
|
def update(document, options = {})
|
|
24
44
|
if options['filter_by'] || options[:filter_by]
|
|
25
45
|
@api_call.patch(endpoint_path, document, options)
|
|
@@ -28,11 +48,21 @@ module Typesense
|
|
|
28
48
|
end
|
|
29
49
|
end
|
|
30
50
|
|
|
51
|
+
# @deprecated Use {#import} instead, which accepts both an array of documents or a JSONL string.
|
|
31
52
|
def create_many(documents, options = {})
|
|
32
53
|
@api_call.logger.warn('#create_many is deprecated and will be removed in a future version. Use #import instead, which now takes both an array of documents or a JSONL string of documents')
|
|
33
54
|
import(documents, options)
|
|
34
55
|
end
|
|
35
56
|
|
|
57
|
+
# Import documents into a collection. Accepts a JSONL string or an array of document hashes.
|
|
58
|
+
#
|
|
59
|
+
# @example
|
|
60
|
+
# client.collections['products'].documents.import([{ 'id' => '1', 'title' => 'Hat' }, { 'id' => '2', 'title' => 'Shirt' }])
|
|
61
|
+
# @example
|
|
62
|
+
# client.collections['products'].documents.import(jsonl_string)
|
|
63
|
+
#
|
|
64
|
+
# @see https://typesense.org/docs/latest/api/documents.html#index-multiple-documents
|
|
65
|
+
#
|
|
36
66
|
# @param [Array,String] documents An array of document hashes or a JSONL string of documents.
|
|
37
67
|
def import(documents, options = {})
|
|
38
68
|
documents_in_jsonl_format = if documents.is_a?(Array)
|
|
@@ -65,22 +95,54 @@ module Typesense
|
|
|
65
95
|
end
|
|
66
96
|
end
|
|
67
97
|
|
|
98
|
+
# Export all documents in a collection as a JSONL string.
|
|
99
|
+
#
|
|
100
|
+
# @example
|
|
101
|
+
# client.collections['products'].documents.export
|
|
102
|
+
#
|
|
103
|
+
# @see https://typesense.org/docs/latest/api/documents.html#export-documents
|
|
68
104
|
def export(options = {})
|
|
69
105
|
@api_call.get(endpoint_path('export'), options)
|
|
70
106
|
end
|
|
71
107
|
|
|
108
|
+
# Search for documents in a collection that match the search criteria.
|
|
109
|
+
#
|
|
110
|
+
# @example
|
|
111
|
+
# client.collections['products'].documents.search('q' => '*', 'query_by' => 'title')
|
|
112
|
+
#
|
|
113
|
+
# @see https://typesense.org/docs/latest/api/search.html
|
|
72
114
|
def search(search_parameters)
|
|
73
115
|
@api_call.get(endpoint_path('search'), search_parameters)
|
|
74
116
|
end
|
|
75
117
|
|
|
118
|
+
# Access an individual document by ID within this collection.
|
|
119
|
+
#
|
|
120
|
+
# @example
|
|
121
|
+
# client.collections['products'].documents['1'].retrieve
|
|
122
|
+
#
|
|
123
|
+
# @see https://typesense.org/docs/latest/api/documents.html
|
|
124
|
+
#
|
|
125
|
+
# @return [Document]
|
|
76
126
|
def [](document_id)
|
|
77
127
|
@documents[document_id] ||= Document.new(@collection_name, document_id, @api_call)
|
|
78
128
|
end
|
|
79
129
|
|
|
130
|
+
# Delete a bunch of documents that match a specific filter condition.
|
|
131
|
+
#
|
|
132
|
+
# @example
|
|
133
|
+
# client.collections['products'].documents.delete(filter_by: 'in_stock:=false')
|
|
134
|
+
#
|
|
135
|
+
# @see https://typesense.org/docs/latest/api/documents.html#delete-by-query
|
|
80
136
|
def delete(query_parameters = {})
|
|
81
137
|
@api_call.delete(endpoint_path, query_parameters)
|
|
82
138
|
end
|
|
83
139
|
|
|
140
|
+
# Truncate all documents in the collection.
|
|
141
|
+
#
|
|
142
|
+
# @example
|
|
143
|
+
# client.collections['products'].documents.truncate
|
|
144
|
+
#
|
|
145
|
+
# @see https://typesense.org/docs/latest/api/documents.html#delete-by-query
|
|
84
146
|
def truncate
|
|
85
147
|
@api_call.delete(endpoint_path, { truncate: true })
|
|
86
148
|
end
|
data/lib/typesense/health.rb
CHANGED
|
@@ -8,6 +8,12 @@ module Typesense
|
|
|
8
8
|
@api_call = api_call
|
|
9
9
|
end
|
|
10
10
|
|
|
11
|
+
# Checks if Typesense server is ready to accept requests.
|
|
12
|
+
#
|
|
13
|
+
# @example
|
|
14
|
+
# client.health.retrieve
|
|
15
|
+
#
|
|
16
|
+
# @see https://typesense.org/docs/latest/api/cluster-operations.html#health
|
|
11
17
|
def retrieve
|
|
12
18
|
@api_call.get(RESOURCE_PATH)
|
|
13
19
|
end
|
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
|
data/lib/typesense/keys.rb
CHANGED
|
@@ -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
|
data/lib/typesense/metrics.rb
CHANGED
|
@@ -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
|
data/lib/typesense/operations.rb
CHANGED
|
@@ -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
|
data/lib/typesense/override.rb
CHANGED
|
@@ -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
|
data/lib/typesense/overrides.rb
CHANGED
|
@@ -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
|
data/lib/typesense/preset.rb
CHANGED
|
@@ -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
|
data/lib/typesense/presets.rb
CHANGED
|
@@ -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
|
data/lib/typesense/stats.rb
CHANGED
|
@@ -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
|
data/lib/typesense/stemming.rb
CHANGED
|
@@ -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
|
data/lib/typesense/synonym.rb
CHANGED
|
@@ -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
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Typesense
|
|
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
|
+
|
|
18
|
+
def initialize(synonym_set_name, api_call)
|
|
19
|
+
@synonym_set_name = synonym_set_name
|
|
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)
|
|
32
|
+
end
|
|
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
|
|
40
|
+
def retrieve
|
|
41
|
+
@api_call.get(endpoint_path)
|
|
42
|
+
end
|
|
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
|
|
50
|
+
def delete
|
|
51
|
+
@api_call.delete(endpoint_path)
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
private
|
|
55
|
+
|
|
56
|
+
def endpoint_path
|
|
57
|
+
"#{SynonymSets::RESOURCE_PATH}/#{URI.encode_www_form_component(@synonym_set_name)}"
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
end
|