typesense 0.9.0 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 717b58a0ddf1e2e262d8cf0e4c0a5e3e2f90a8e0cb259337a5d243a3fb0f901c
4
- data.tar.gz: 89a094ce8f884ce68d068122b91a6a2df733cc7e77b128e49dd3396cb4c2f5ce
3
+ metadata.gz: 2a9a804d053011ec4aed72f8a7a401db1c4a171152d1d171e8de7d2861b9f04e
4
+ data.tar.gz: cfc7041f6221f8d5ee321b289e38ee82b4ee4d3decceeace13df3ae061cd621a
5
5
  SHA512:
6
- metadata.gz: 69bbef4fea77ec0a97aa15d34a12168d5853c7eccb4a86866605fc536f8348fb80a31e807ff3b25ae342f95ff3569b421c54fd383164646a1585174bf66ad402
7
- data.tar.gz: 8abf2ce30d9858d76150c8f81534d7f3e9bc6ad06a4fc33c2c01e0e6ffcfe49e7b0d02282e862bc95c5574a538966cc51c2f39e43e843abbb68333ef43f368da
6
+ metadata.gz: 2eb9a9633cb01ef642e6a03ac4e98f67128ce47065f37484c108e843f2984be4fe2903841f1c78005cb6f6cc22e145f156bc2b6705c01a562fdcd2f45778c17a
7
+ data.tar.gz: 20c0869a33ae76f0dcc6a11a3cb32db546d3cc40014403816887a1311e6c54f1fe7e98686550155fb56464385c6d5c28b8e7d387a464dbda931930af83f188af
data/README.md CHANGED
@@ -33,6 +33,7 @@ Tests are also a good place to know how the the library works internally: [spec]
33
33
 
34
34
  | Typesense Server | typesense-ruby |
35
35
  |------------------|----------------|
36
+ | \>= v0.18.0 | \>= v0.10.0 |
36
37
  | \>= v0.17.0 | \>= v0.9.0 |
37
38
  | \>= v0.16.0 | \>= v0.8.0 |
38
39
  | \>= v0.15.0 | \>= v0.7.0 |
@@ -2,8 +2,6 @@
2
2
 
3
3
  ##
4
4
  # These examples walk you through operations specifically related to aliases
5
- # # This is a Typesense Premium feature (see: https://typesense.org/premium)
6
- # Be sure to add `--license-key=<>` as a parameter, when starting a Typesense Premium server
7
5
 
8
6
  require_relative './client_initialization'
9
7
 
@@ -12,7 +12,7 @@ AwesomePrint.defaults = {
12
12
  ## Setup
13
13
  #
14
14
  ### Option 1: Start a single-node cluster
15
- # $ docker run -i -p 8108:8108 -v/tmp/typesense-server-data-1b/:/data -v`pwd`/typesense-server-peers:/typesense-server-peers typesense/typesense:0.12.1.rc1 --data-dir /data --api-key=xyz --listen-port 8108 --enable-cors
15
+ # $ docker run -i -p 8108:8108 -v/tmp/typesense-server-data-1b/:/data -v`pwd`/typesense-server-peers:/typesense-server-peers typesense/typesense:0.18.0 --data-dir /data --api-key=xyz --listen-port 8108 --enable-cors
16
16
  #
17
17
  ### Option 2: Start a 3-node cluster
18
18
  #
@@ -20,13 +20,13 @@ AwesomePrint.defaults = {
20
20
  # $ echo '172.17.0.2:8107:8108,172.17.0.3:7107:7108,172.17.0.4:9107:9108' > `pwd`/typesense-server-peers
21
21
  #
22
22
  # Start node 1:
23
- # $ docker run -i -p 8108:8108 -p 8107:8107 -v/tmp/typesense-server-data-1b/:/data -v`pwd`/typesense-server-peers:/typesense-server-peers typesense/typesense:0.12.1.rc1 --data-dir /data --api-key=xyz --listen-port 8108 --peering-port 8107 --enable-cors --nodes=/typesense-server-peers
23
+ # $ docker run -i -p 8108:8108 -p 8107:8107 -v/tmp/typesense-server-data-1b/:/data -v`pwd`/typesense-server-peers:/typesense-server-peers typesense/typesense:0.18.0 --data-dir /data --api-key=xyz --listen-port 8108 --peering-port 8107 --enable-cors --nodes=/typesense-server-peers
24
24
  #
25
25
  # Start node 2:
26
- # $ docker run -i -p 7108:7108 -p 7107:7107 -v/tmp/.typesense-server-data-2b/:/data -v`pwd`/typesense-server-peers:/typesense-server-peers typesense/typesense:0.12.1.rc1 --data-dir /data --api-key=xyz --listen-port 7108 --peering-port 7107 --enable-cors --nodes=/typesense-server-peers
26
+ # $ docker run -i -p 7108:7108 -p 7107:7107 -v/tmp/.typesense-server-data-2b/:/data -v`pwd`/typesense-server-peers:/typesense-server-peers typesense/typesense:0.18.0 --data-dir /data --api-key=xyz --listen-port 7108 --peering-port 7107 --enable-cors --nodes=/typesense-server-peers
27
27
  #
28
28
  # Start node 3:
29
- # $ docker run -i -p 9108:9108 -p 9107:9107 -v/tmp/.typesense-server-data-3b/:/data -v`pwd`/typesense-server-peers:/typesense-server-peers typesense/typesense:0.12.1.rc1 --data-dir /data --api-key=xyz --listen-port 9108 --peering-port 9107 --enable-cors --nodes=/typesense-server-peers
29
+ # $ docker run -i -p 9108:9108 -p 9107:9107 -v/tmp/.typesense-server-data-3b/:/data -v`pwd`/typesense-server-peers:/typesense-server-peers typesense/typesense:0.18.0 --data-dir /data --api-key=xyz --listen-port 9108 --peering-port 9107 --enable-cors --nodes=/typesense-server-peers
30
30
  #
31
31
  # Note: Be sure to add `--license-key=<>` at the end when starting a Typesense Premium server
32
32
 
@@ -64,5 +64,5 @@ AwesomePrint.defaults = {
64
64
  retry_interval_seconds: 0.01,
65
65
  connection_timeout_seconds: 10,
66
66
  logger: Logger.new($stdout),
67
- log_level: Logger::DEBUG
67
+ log_level: Logger::INFO
68
68
  )
@@ -1,12 +1,16 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  ##
4
- # These examples walk you through operations specifically related to overrides
5
- # This is a Typesense Premium feature (see: https://typesense.org/premium)
6
- # Be sure to add `--license-key=<>` as a parameter, when starting a Typesense Premium server
4
+ # These examples walk you through operations specifically related to result overrides / curation
7
5
 
8
6
  require_relative './client_initialization'
9
7
 
8
+ # Delete the collection if it already exists
9
+ begin
10
+ @typesense.collections['companies'].delete
11
+ rescue Typesense::Error::ObjectNotFound
12
+ end
13
+
10
14
  ##
11
15
  # Create a collection
12
16
  schema = {
@@ -63,16 +67,16 @@ schema = {
63
67
  ##
64
68
  # Create overrides
65
69
 
66
- @typesense.collections['companies'].overrides.create(
67
- "id": 'promote-doofenshmirtz',
70
+ @typesense.collections['companies'].overrides.upsert(
71
+ 'promote-doofenshmirtz',
68
72
  "rule": {
69
73
  "query": 'doofen',
70
74
  "match": 'exact'
71
75
  },
72
76
  "includes": [{ 'id' => '126', 'position' => 1 }]
73
77
  )
74
- @typesense.collections['companies'].overrides.create(
75
- "id": 'promote-acme',
78
+ @typesense.collections['companies'].overrides.upsert(
79
+ 'promote-acme',
76
80
  "rule": {
77
81
  "query": 'stark',
78
82
  "match": 'exact'
@@ -0,0 +1,127 @@
1
+ # frozen_string_literal: true
2
+
3
+ ##
4
+ # These examples walk you through operations specifically related to synonyms
5
+
6
+ require_relative './client_initialization'
7
+
8
+ # Delete the collection if it already exists
9
+ begin
10
+ @typesense.collections['companies'].delete
11
+ rescue Typesense::Error::ObjectNotFound
12
+ end
13
+
14
+ ##
15
+ # Create a collection
16
+ schema = {
17
+ 'name' => 'companies',
18
+ 'fields' => [
19
+ {
20
+ 'name' => 'company_name',
21
+ 'type' => 'string'
22
+ },
23
+ {
24
+ 'name' => 'num_employees',
25
+ 'type' => 'int32'
26
+ },
27
+ {
28
+ 'name' => 'country',
29
+ 'type' => 'string',
30
+ 'facet' => true
31
+ }
32
+ ],
33
+ 'default_sorting_field' => 'num_employees'
34
+ }
35
+
36
+ @typesense.collections.create(schema)
37
+
38
+ # Let's create a couple documents for us to use in our search examples
39
+ @typesense.collections['companies'].documents.create(
40
+ 'id' => '124',
41
+ 'company_name' => 'Stark Industries',
42
+ 'num_employees' => 5215,
43
+ 'country' => 'USA'
44
+ )
45
+
46
+ @typesense.collections['companies'].documents.create(
47
+ 'id' => '127',
48
+ 'company_name' => 'Stark Corp',
49
+ 'num_employees' => 1031,
50
+ 'country' => 'USA'
51
+ )
52
+
53
+ @typesense.collections['companies'].documents.create(
54
+ 'id' => '125',
55
+ 'company_name' => 'Acme Corp',
56
+ 'num_employees' => 1002,
57
+ 'country' => 'France'
58
+ )
59
+
60
+ @typesense.collections['companies'].documents.create(
61
+ 'id' => '126',
62
+ 'company_name' => 'Doofenshmirtz Inc',
63
+ 'num_employees' => 2,
64
+ 'country' => 'Tri-State Area'
65
+ )
66
+
67
+ ##
68
+ # Create synonyms
69
+
70
+ ap @typesense.collections['companies'].synonyms.upsert(
71
+ 'synonyms-doofenshmirtz',
72
+ {
73
+ 'synonyms' => %w[Doofenshmirtz Heinz Evil]
74
+ }
75
+ )
76
+
77
+ ##
78
+ # Search for documents
79
+ # Should return Doofenshmirtz Inc, since it's set as a synonym
80
+ results = @typesense.collections['companies'].documents.search(
81
+ 'q' => 'Heinz',
82
+ 'query_by' => 'company_name'
83
+ )
84
+ ap results
85
+
86
+ ##
87
+ # List all synonyms
88
+ ap @typesense.collections['companies'].synonyms.retrieve
89
+
90
+ ##
91
+ # Retrieve specific synonym
92
+ ap @typesense.collections['companies'].synonyms['synonyms-doofenshmirtz'].retrieve
93
+
94
+ ##
95
+ # Update synonym to a one-way synonym
96
+ ap @typesense.collections['companies'].synonyms.upsert(
97
+ 'synonyms-doofenshmirtz',
98
+ {
99
+ 'root' => 'Evil',
100
+ 'synonyms' => %w[Doofenshmirtz Heinz]
101
+ }
102
+ )
103
+
104
+ ##
105
+ # Search for documents
106
+ # Should return Doofenshmirtz Inc, since it's set as a synonym
107
+ results = @typesense.collections['companies'].documents.search(
108
+ 'q' => 'Evil',
109
+ 'query_by' => 'company_name'
110
+ )
111
+ ap results
112
+
113
+ # Should not return any results, since this is a one-way synonym
114
+ results = @typesense.collections['companies'].documents.search(
115
+ 'q' => 'Heinz',
116
+ 'query_by' => 'company_name'
117
+ )
118
+ ap results
119
+
120
+ ##
121
+ # Delete synonym
122
+ ap @typesense.collections['companies'].synonyms['synonyms-doofenshmirtz'].delete
123
+
124
+ ##
125
+ # Cleanup
126
+ # Drop the collection
127
+ @typesense.collections['companies'].delete
@@ -13,6 +13,8 @@ require_relative 'typesense/documents'
13
13
  require_relative 'typesense/document'
14
14
  require_relative 'typesense/overrides'
15
15
  require_relative 'typesense/override'
16
+ require_relative 'typesense/synonyms'
17
+ require_relative 'typesense/synonym'
16
18
  require_relative 'typesense/aliases'
17
19
  require_relative 'typesense/alias'
18
20
  require_relative 'typesense/keys'
@@ -20,4 +22,5 @@ require_relative 'typesense/key'
20
22
  require_relative 'typesense/debug'
21
23
  require_relative 'typesense/health'
22
24
  require_relative 'typesense/metrics'
25
+ require_relative 'typesense/operations'
23
26
  require_relative 'typesense/error'
@@ -78,7 +78,7 @@ module Typesense
78
78
 
79
79
  unless body_parameters.nil?
80
80
  body = body_parameters
81
- body = Oj.dump(body_parameters) if request_options[:headers]['Content-Type'] == 'application/json'
81
+ body = Oj.dump(body_parameters, mode: :compat) if request_options[:headers]['Content-Type'] == 'application/json'
82
82
  request_options.merge!(body: body)
83
83
  end
84
84
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Typesense
4
4
  class Client
5
- attr_reader :configuration, :collections, :aliases, :keys, :debug, :health, :metrics
5
+ attr_reader :configuration, :collections, :aliases, :keys, :debug, :health, :metrics, :operations
6
6
 
7
7
  def initialize(options = {})
8
8
  @configuration = Configuration.new(options)
@@ -13,6 +13,7 @@ module Typesense
13
13
  @debug = Debug.new(@api_call)
14
14
  @health = Health.new(@api_call)
15
15
  @metrics = Metrics.new(@api_call)
16
+ @operations = Operations.new(@api_call)
16
17
  end
17
18
  end
18
19
  end
@@ -2,13 +2,14 @@
2
2
 
3
3
  module Typesense
4
4
  class Collection
5
- attr_reader :documents, :overrides
5
+ attr_reader :documents, :overrides, :synonyms
6
6
 
7
7
  def initialize(name, api_call)
8
8
  @name = name
9
9
  @api_call = api_call
10
10
  @documents = Documents.new(@name, @api_call)
11
11
  @overrides = Overrides.new(@name, @api_call)
12
+ @synonyms = Synonyms.new(@name, @api_call)
12
13
  end
13
14
 
14
15
  def retrieve
@@ -1,6 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'base64'
4
+ require 'json'
5
+ require 'openssl'
4
6
 
5
7
  module Typesense
6
8
  class Keys
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Typesense
4
+ class Operations
5
+ RESOURCE_PATH = '/operations'
6
+
7
+ def initialize(api_call)
8
+ @api_call = api_call
9
+ end
10
+
11
+ def perform(operation_name, query_params = {})
12
+ @api_call.post("#{RESOURCE_PATH}/#{operation_name}", {}, query_params)
13
+ end
14
+ end
15
+ end
@@ -10,8 +10,8 @@ module Typesense
10
10
  @overrides = {}
11
11
  end
12
12
 
13
- def create(params)
14
- @api_call.put(endpoint_path, params)
13
+ def upsert(override_id, params)
14
+ @api_call.put(endpoint_path(override_id), params)
15
15
  end
16
16
 
17
17
  def retrieve
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Typesense
4
+ class Synonym
5
+ def initialize(collection_name, synonym_id, api_call)
6
+ @collection_name = collection_name
7
+ @synonym_id = synonym_id
8
+ @api_call = api_call
9
+ end
10
+
11
+ def retrieve
12
+ @api_call.get(endpoint_path)
13
+ end
14
+
15
+ def delete
16
+ @api_call.delete(endpoint_path)
17
+ end
18
+
19
+ private
20
+
21
+ def endpoint_path
22
+ "#{Collections::RESOURCE_PATH}/#{@collection_name}#{Synonyms::RESOURCE_PATH}/#{@synonym_id}"
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Typesense
4
+ class Synonyms
5
+ RESOURCE_PATH = '/synonyms'
6
+
7
+ def initialize(collection_name, api_call)
8
+ @collection_name = collection_name
9
+ @api_call = api_call
10
+ @synonyms = {}
11
+ end
12
+
13
+ def upsert(synonym_id, params)
14
+ @api_call.put(endpoint_path(synonym_id), params)
15
+ end
16
+
17
+ def retrieve
18
+ @api_call.get(endpoint_path)
19
+ end
20
+
21
+ def [](synonym_id)
22
+ @synonyms[synonym_id] ||= Synonym.new(@collection_name, synonym_id, @api_call)
23
+ end
24
+
25
+ private
26
+
27
+ def endpoint_path(operation = nil)
28
+ "#{Collections::RESOURCE_PATH}/#{@collection_name}#{Synonyms::RESOURCE_PATH}#{operation.nil? ? '' : "/#{operation}"}"
29
+ end
30
+ end
31
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Typesense
4
- VERSION = '0.9.0'
4
+ VERSION = '0.10.0'
5
5
  end
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: 0.9.0
4
+ version: 0.10.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: 2020-11-17 00:00:00.000000000 Z
11
+ date: 2020-12-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: awesome_print
@@ -274,6 +274,7 @@ files:
274
274
  - examples/keys.rb
275
275
  - examples/overrides.rb
276
276
  - examples/search.rb
277
+ - examples/synonyms.rb
277
278
  - lib/typesense.rb
278
279
  - lib/typesense/alias.rb
279
280
  - lib/typesense/aliases.rb
@@ -290,8 +291,11 @@ files:
290
291
  - lib/typesense/key.rb
291
292
  - lib/typesense/keys.rb
292
293
  - lib/typesense/metrics.rb
294
+ - lib/typesense/operations.rb
293
295
  - lib/typesense/override.rb
294
296
  - lib/typesense/overrides.rb
297
+ - lib/typesense/synonym.rb
298
+ - lib/typesense/synonyms.rb
295
299
  - lib/typesense/version.rb
296
300
  - typesense.gemspec
297
301
  homepage: https://typesense.org