typesense 0.2.0 → 0.4.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: 6dcd2c3b6cfbf9be0a2d466eb377a55d9a419ba9334861de46cb3eefe6542d56
4
- data.tar.gz: c3c6bbc4d9eb200a827d01ccbf25f2a9f660dce2237e483886237325f1ebb8eb
3
+ metadata.gz: 8c74454a48a4f170bbb99bb5e382199c8842e84ec5d2fbd6198106df89b45977
4
+ data.tar.gz: ca4772c87e84fabe0cef3af42bfb6e1bb889e305b402d9a2e2f83b10bdbe6d1b
5
5
  SHA512:
6
- metadata.gz: 3c76aff4123a3c2067319f6d4c168eeaf5b2f95cf50cd07fd1ab0e9c8aec9f628be408071aa52750e86e768d1751205b4da94dcfdd4246f7ccb667d2c0a1ff01
7
- data.tar.gz: 9e246a32ad33a084768b8b8c0eae17c61b969296294b757936d6f157a93beeb7b2d91c046a7322676ea62a363f7a09dadb89ed01a99c6071516ef227ba515280
6
+ metadata.gz: d1ab99d6e52d15257c8e664d765b1debb063d151d364916b273cef1658537dadcd0241e76fffa5807be50b15c83891b76c2aaef7105c875be2c3bb70728b88e0
7
+ data.tar.gz: db20bce0c42a7713a3c5fa25ca1c7a17bb6724bd8949b5dc16202d11538b348d806d960f0def0712e118d856184da8650a3b12ba861037754e20e172856d38c0
data/.gitignore CHANGED
@@ -11,5 +11,7 @@ Gemfile.lock
11
11
  .ruby-version
12
12
  .ruby-gemset
13
13
 
14
+ typesense-server-peers
15
+
14
16
  # rspec failure tracking
15
17
  .rspec_status
data/.rubocop.yml CHANGED
@@ -4,6 +4,7 @@ require: rubocop-rspec
4
4
 
5
5
  AllCops:
6
6
  TargetRubyVersion: "2.4"
7
+ NewCops: enable
7
8
 
8
9
  Metrics/BlockLength:
9
10
  Exclude:
data/.rubocop_todo.yml CHANGED
@@ -1,6 +1,6 @@
1
1
  # This configuration was generated by
2
2
  # `rubocop --auto-gen-config`
3
- # on 2018-03-17 15:11:06 -0700 using RuboCop version 0.53.0.
3
+ # on 2020-05-21 20:10:36 -0700 using RuboCop version 0.83.0.
4
4
  # The point is for the user to remove these configuration records
5
5
  # one by one as the offenses are removed from the code base.
6
6
  # Note that changes in the inspected code, or installation of new
@@ -11,27 +11,44 @@ Lint/ShadowedException:
11
11
  Exclude:
12
12
  - 'lib/typesense/api_call.rb'
13
13
 
14
+ # Offense count: 2
15
+ # Configuration parameters: AllowComments.
16
+ Lint/SuppressedException:
17
+ Exclude:
18
+ - 'examples/collections_and_documents.rb'
19
+ - 'examples/search.rb'
20
+
14
21
  # Offense count: 3
22
+ # Configuration parameters: IgnoredMethods.
15
23
  Metrics/AbcSize:
16
- Max: 37
24
+ Max: 43
17
25
 
18
26
  # Offense count: 1
27
+ # Configuration parameters: CountComments.
28
+ Metrics/ClassLength:
29
+ Max: 184
30
+
31
+ # Offense count: 3
32
+ # Configuration parameters: IgnoredMethods.
19
33
  Metrics/CyclomaticComplexity:
20
- Max: 13
34
+ Max: 11
21
35
 
22
- # Offense count: 1
23
- # Configuration parameters: CountComments.
36
+ # Offense count: 5
37
+ # Configuration parameters: CountComments, ExcludedMethods.
24
38
  Metrics/MethodLength:
25
- Max: 35
39
+ Max: 29
26
40
 
27
- # Offense count: 1
41
+ # Offense count: 3
42
+ # Configuration parameters: IgnoredMethods.
28
43
  Metrics/PerceivedComplexity:
29
- Max: 14
44
+ Max: 11
30
45
 
31
- # Offense count: 13
46
+ # Offense count: 25
32
47
  # Configuration parameters: Max.
33
48
  RSpec/ExampleLength:
34
49
  Exclude:
50
+ - 'spec/typesense/alias_spec.rb'
51
+ - 'spec/typesense/aliases_spec.rb'
35
52
  - 'spec/typesense/api_call_spec.rb'
36
53
  - 'spec/typesense/collection_spec.rb'
37
54
  - 'spec/typesense/collections_spec.rb'
@@ -40,20 +57,19 @@ RSpec/ExampleLength:
40
57
  - 'spec/typesense/documents_spec.rb'
41
58
  - 'spec/typesense/override_spec.rb'
42
59
  - 'spec/typesense/overrides_spec.rb'
43
- - 'spec/typesense/alias_spec.rb'
44
- - 'spec/typesense/aliases_spec.rb'
45
60
 
46
- # Offense count: 2
47
- # Configuration parameters: AggregateFailuresByDefault.
61
+ # Offense count: 10
48
62
  RSpec/MultipleExpectations:
49
- Max: 2
63
+ Max: 5
50
64
 
51
- # Offense count: 9
65
+ # Offense count: 13
52
66
  Style/Documentation:
53
67
  Exclude:
54
68
  - 'spec/**/*'
55
69
  - 'test/**/*'
56
70
  - 'lib/typesense.rb'
71
+ - 'lib/typesense/alias.rb'
72
+ - 'lib/typesense/aliases.rb'
57
73
  - 'lib/typesense/api_call.rb'
58
74
  - 'lib/typesense/client.rb'
59
75
  - 'lib/typesense/collection.rb'
@@ -64,11 +80,10 @@ Style/Documentation:
64
80
  - 'lib/typesense/documents.rb'
65
81
  - 'lib/typesense/override.rb'
66
82
  - 'lib/typesense/overrides.rb'
67
- - 'lib/typesense/alias.rb'
68
- - 'lib/typesense/aliases.rb'
69
83
 
70
- # Offense count: 92
71
- # Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
84
+ # Offense count: 157
85
+ # Cop supports --auto-correct.
86
+ # Configuration parameters: AutoCorrect, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
72
87
  # URISchemes: http, https
73
- Metrics/LineLength:
74
- Max: 245
88
+ Layout/LineLength:
89
+ Max: 312
data/README.md CHANGED
@@ -29,6 +29,13 @@ Here are some examples that show you how the Ruby client works: [examples](examp
29
29
 
30
30
  Tests are also a good place to know how the the library works internally: [spec](spec)
31
31
 
32
+ ## Compatibility
33
+
34
+ | Typesense Server | typesense-ruby |
35
+ |------------------|----------------|
36
+ | <= v0.11 | <= v0.3.0 |
37
+ | \>= v0.12 | \>= v0.4.0 |
38
+
32
39
  ## Development
33
40
 
34
41
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
data/codecov.yml ADDED
@@ -0,0 +1,10 @@
1
+ coverage:
2
+ status:
3
+ project:
4
+ default:
5
+ threshold: 10%
6
+ target: 90%
7
+ patch:
8
+ default:
9
+ threshold: 10%
10
+ target: 80%
data/examples/aliases.rb CHANGED
@@ -3,34 +3,12 @@
3
3
  ##
4
4
  # These examples walk you through operations specifically related to aliases
5
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
6
7
 
7
- require_relative '../lib/typesense'
8
- require 'awesome_print'
9
-
10
- AwesomePrint.defaults = {
11
- indent: -2
12
- }
13
-
14
- ##
15
- # Setup
16
- #
17
- # Start the master
18
- # $ docker run -p 8108:8108 -it -v/tmp/typesense-data-master/:/data -it typesense/typesense:0.8.0-rc1 --data-dir /data --api-key=abcd --listen-port 8108 --license-key=<>
19
- #
20
-
21
- ##
22
- # Create a client
23
- typesense = Typesense::Client.new(
24
- master_node: {
25
- host: 'localhost',
26
- port: 8108,
27
- protocol: 'http',
28
- api_key: 'abcd'
29
- }
30
- )
8
+ require_relative './client_initialization'
31
9
 
32
10
  # Create a collection
33
- create_response = typesense.collections.create(
11
+ create_response = @typesense.collections.create(
34
12
  "name": 'books_january',
35
13
  "fields": [
36
14
  { "name": 'title', "type": 'string' },
@@ -48,8 +26,8 @@ create_response = typesense.collections.create(
48
26
  ap create_response
49
27
 
50
28
  # Create or update an existing alias
51
- create_alias_response = typesense.aliases.upsert('books',
52
- "collection_name": 'books_january')
29
+ create_alias_response = @typesense.aliases.upsert('books',
30
+ "collection_name": 'books_january')
53
31
  ap create_alias_response
54
32
 
55
33
  # Add a book using the alias name `books`
@@ -61,20 +39,20 @@ hunger_games_book = {
61
39
  'ratings_count': 4_780_653
62
40
  }
63
41
 
64
- typesense.collections['books'].documents.create(hunger_games_book)
42
+ @typesense.collections['books'].documents.create(hunger_games_book)
65
43
 
66
44
  # Search using the alias
67
- ap typesense.collections['books'].documents.search(
45
+ ap @typesense.collections['books'].documents.search(
68
46
  'q': 'hunger',
69
47
  'query_by': 'title',
70
48
  'sort_by': 'ratings_count:desc'
71
49
  )
72
50
 
73
51
  # List all aliases
74
- ap typesense.aliases.retrieve
52
+ ap @typesense.aliases.retrieve
75
53
 
76
54
  # Retrieve the configuration of a specific alias
77
- ap typesense.aliases['books'].retrieve
55
+ ap @typesense.aliases['books'].retrieve
78
56
 
79
57
  # Delete an alias
80
- ap typesense.aliases['books'].delete
58
+ ap @typesense.aliases['books'].delete
@@ -0,0 +1,67 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../lib/typesense'
4
+ require 'awesome_print'
5
+
6
+ AwesomePrint.defaults = {
7
+ indent: -2
8
+ }
9
+
10
+ ##
11
+ ## Setup
12
+ #
13
+ ### Option 1: Start a single-node cluster
14
+ # $ 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.rc9 --data-dir /data --api-key=xyz --search-only-api-key=abcd --listen-port 8108 --enable-cors
15
+ #
16
+ ### Option 2: Start a 3-node cluster
17
+ #
18
+ # Create file in present working directory called typesense-server-peers (update IP Addresses appropriately to your local network):
19
+ # $ echo '172.17.0.2:8107:8108,172.17.0.3:7107:7108,172.17.0.4:9107:9108' > `pwd`/typesense-server-peers
20
+ #
21
+ # Start node 1:
22
+ # $ 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.rc9 --data-dir /data --api-key=xyz --search-only-api-key=abcd --listen-port 8108 --peering-port 8107 --enable-cors --nodes=/typesense-server-peers
23
+ #
24
+ # Start node 2:
25
+ # $ 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.rc9 --data-dir /data --api-key=xyz --search-only-api-key=abcd --listen-port 7108 --peering-port 7107 --enable-cors --nodes=/typesense-server-peers
26
+ #
27
+ # Start node 3:
28
+ # $ 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.rc9 --data-dir /data --api-key=xyz --search-only-api-key=abcd --listen-port 9108 --peering-port 9107 --enable-cors --nodes=/typesense-server-peers
29
+ #
30
+ # Note: Be sure to add `--license-key=<>` at the end when starting a Typesense Premium server
31
+
32
+ ##
33
+ # Create a client
34
+ @typesense = Typesense::Client.new(
35
+ nodes: [
36
+ {
37
+ host: 'localhost',
38
+ port: 8108,
39
+ protocol: 'http'
40
+ },
41
+ # Uncomment if starting a 3-node cluster, using Option 2 under Setup instructions above
42
+ {
43
+ host: 'localhost',
44
+ port: 7108,
45
+ protocol: 'http'
46
+ },
47
+ {
48
+ host: 'localhost',
49
+ port: 9108,
50
+ protocol: 'http'
51
+ }
52
+ ],
53
+ # If this optional key is specified, requests are always sent to this node first if it is healthy
54
+ # before falling back on the nodes mentioned in the `nodes` key. This is useful when running a distributed set of search clusters.
55
+ 'nearest_node': {
56
+ 'host': 'localhost',
57
+ 'port': '8108',
58
+ 'protocol': 'http'
59
+ },
60
+ api_key: 'xyz',
61
+ num_retries: 10,
62
+ healthcheck_interval_seconds: 1,
63
+ retry_interval_seconds: 0.01,
64
+ connection_timeout_seconds: 10,
65
+ logger: Logger.new(STDOUT),
66
+ log_level: Logger::DEBUG
67
+ )
@@ -4,41 +4,7 @@
4
4
  # These examples walk you through all the operations you can do on a collection and a document
5
5
  # Search is specifically covered in another file in the examples folder
6
6
 
7
- require_relative '../lib/typesense'
8
- require 'awesome_print'
9
-
10
- AwesomePrint.defaults = {
11
- indent: -2
12
- }
13
-
14
- ##
15
- # Setup
16
- #
17
- # Start the master
18
- # $ docker run -p 8108:8108 -it -v/tmp/typesense-data-master/:/data -it typesense/typesense:0.8.0-rc1 --data-dir /data --api-key=abcd --listen-port 8108
19
- #
20
- # Start the read replica
21
- # $ docker run -p 8109:8109 -it -v/tmp/typesense-data-read-replica-1/:/data -it typesense/typesense:0.8.0-rc1 --data-dir /data --api-key=wxyz --listen-port 8109 --master http://localhost:8108
22
-
23
- ##
24
- # Create a client
25
- typesense = Typesense::Client.new(
26
- master_node: {
27
- host: 'localhost',
28
- port: 8108,
29
- protocol: 'http',
30
- api_key: 'abcd'
31
- },
32
- read_replica_nodes: [
33
- {
34
- host: 'localhost',
35
- port: 8109,
36
- protocol: 'http',
37
- api_key: 'wxyz'
38
- }
39
- ],
40
- timeout_seconds: 10
41
- )
7
+ require_relative './client_initialization'
42
8
 
43
9
  ##
44
10
  # Create a collection
@@ -62,7 +28,13 @@ schema = {
62
28
  'default_sorting_field' => 'num_employees'
63
29
  }
64
30
 
65
- collection = typesense.collections.create(schema)
31
+ # Delete the collection if it already exists
32
+ begin
33
+ @typesense.collections['companies'].delete
34
+ rescue Typesense::Error::ObjectNotFound
35
+ end
36
+
37
+ collection = @typesense.collections.create(schema)
66
38
  ap collection
67
39
 
68
40
  # {
@@ -87,7 +59,8 @@ ap collection
87
59
 
88
60
  ##
89
61
  # Retrieve a collection
90
- collection = typesense.collections['companies'].retrieve
62
+ sleep 0.5 # Give Typesense cluster a few hundred ms to create the collection on all nodes, before reading it right after (eventually consistent)
63
+ collection = @typesense.collections['companies'].retrieve
91
64
  ap collection
92
65
 
93
66
  # {
@@ -115,7 +88,7 @@ ap collection
115
88
 
116
89
  ##
117
90
  # Retrieve all collections
118
- collections = typesense.collections.retrieve
91
+ collections = @typesense.collections.retrieve
119
92
  ap collections
120
93
 
121
94
  # [
@@ -146,7 +119,7 @@ ap collections
146
119
  ##
147
120
  # Delete a collection
148
121
  # Deletion returns the schema of the collection after deletion
149
- collection = typesense.collections['companies'].delete
122
+ collection = @typesense.collections['companies'].delete
150
123
  ap collection
151
124
 
152
125
  # {
@@ -173,7 +146,7 @@ ap collection
173
146
  # }
174
147
 
175
148
  # Let's create the collection again for use in our remaining examples
176
- typesense.collections.create(schema)
149
+ @typesense.collections.create(schema)
177
150
 
178
151
  ##
179
152
  # Create (index) a document
@@ -184,7 +157,7 @@ document = {
184
157
  'country' => 'USA'
185
158
  }
186
159
 
187
- document = typesense.collections['companies'].documents.create(document)
160
+ document = @typesense.collections['companies'].documents.create(document)
188
161
  ap document
189
162
 
190
163
  # {
@@ -196,7 +169,8 @@ ap document
196
169
 
197
170
  ##
198
171
  # Retrieve a document
199
- document = typesense.collections['companies'].documents['124'].retrieve
172
+ sleep 0.5 # Give Typesense cluster a few hundred ms to create the document on all nodes, before reading it right after (eventually consistent)
173
+ document = @typesense.collections['companies'].documents['124'].retrieve
200
174
  ap document
201
175
 
202
176
  # {
@@ -209,7 +183,7 @@ ap document
209
183
  ##
210
184
  # Delete a document
211
185
  # Deleting a document, returns the document after deletion
212
- document = typesense.collections['companies'].documents['124'].delete
186
+ document = @typesense.collections['companies'].documents['124'].delete
213
187
  ap document
214
188
 
215
189
  # {
@@ -219,25 +193,28 @@ ap document
219
193
  # "num_employees" => 5215
220
194
  # }
221
195
 
222
- # Let's create two documents again for use in our remaining examples
223
- typesense.collections['companies'].documents.create(
224
- 'id' => '124',
225
- 'company_name' => 'Stark Industries',
226
- 'num_employees' => 5215,
227
- 'country' => 'USA'
228
- )
229
-
230
- typesense.collections['companies'].documents.create(
231
- 'id' => '125',
232
- 'company_name' => 'Acme Corp',
233
- 'num_employees' => 1002,
234
- 'country' => 'France'
235
- )
196
+ # Let's bulk create two documents again for use in our remaining examples
197
+ documents = [
198
+ {
199
+ 'id' => '124',
200
+ 'company_name' => 'Stark Industries',
201
+ 'num_employees' => 5215,
202
+ 'country' => 'USA'
203
+ },
204
+ {
205
+ 'id' => '125',
206
+ 'company_name' => 'Acme Corp',
207
+ 'num_employees' => 1002,
208
+ 'country' => 'France'
209
+ }
210
+ ]
211
+ ap @typesense.collections['companies'].documents.create_many(documents)
236
212
 
237
213
  ##
238
214
  # Export all documents in a collection in JSON Lines format
239
215
  # We use JSON Lines format for performance reasons. You can choose to parse selected lines (elements in the array) as needed.
240
- array_of_json_strings = typesense.collections['companies'].documents.export
216
+ sleep 0.5 # Give Typesense cluster a few hundred ms to create the document on all nodes, before reading it right after (eventually consistent)
217
+ array_of_json_strings = @typesense.collections['companies'].documents.export
241
218
  ap array_of_json_strings
242
219
 
243
220
  # [
@@ -248,4 +225,4 @@ ap array_of_json_strings
248
225
  ##
249
226
  # Cleanup
250
227
  # Drop the collection
251
- typesense.collections['companies'].delete
228
+ @typesense.collections['companies'].delete