Skip to content

Commit 881843f

Browse files
authored
Merge pull request #45 from tharropoulos/nl-search
feat(nl-search): add natural language search models support
2 parents 73390bc + 2949110 commit 881843f

12 files changed

+180
-7
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/.bundle/
2+
/vendor/
23
/.yardoc
34
/_yardoc/
45
/coverage/

lib/typesense.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,5 @@ module Typesense
3535
require_relative 'typesense/stemming'
3636
require_relative 'typesense/stemming_dictionaries'
3737
require_relative 'typesense/stemming_dictionary'
38+
require_relative 'typesense/nl_search_models'
39+
require_relative 'typesense/nl_search_model'

lib/typesense/analytics_rules.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def [](rule_name)
2424
private
2525

2626
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?}"
2828
end
2929
end
3030
end

lib/typesense/client.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
module Typesense
44
class Client
55
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
77

88
def initialize(options = {})
99
@configuration = Configuration.new(options)
@@ -20,6 +20,7 @@ def initialize(options = {})
2020
@analytics = Analytics.new(@api_call)
2121
@stemming = Stemming.new(@api_call)
2222
@presets = Presets.new(@api_call)
23+
@nl_search_models = NlSearchModels.new(@api_call)
2324
end
2425
end
2526
end

lib/typesense/documents.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ def truncate
8888
private
8989

9090
def endpoint_path(operation = nil)
91-
"#{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?}"
9292
end
9393
end
9494
end

lib/typesense/nl_search_model.rb

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

lib/typesense/nl_search_models.rb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

lib/typesense/overrides.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def [](override_id)
2525
private
2626

2727
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?}"
2929
end
3030
end
3131
end

lib/typesense/presets.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def [](preset_name)
2424
private
2525

2626
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?}"
2828
end
2929
end
3030
end

lib/typesense/stemming_dictionaries.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def [](dict_id)
4343
private
4444

4545
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?}"
4747
end
4848
end
4949
end

0 commit comments

Comments
 (0)