Skip to content

Commit 08f825b

Browse files
authored
Merge branch 'typesense:master' into response-malformed-json-error
2 parents eb5518c + 9240cda commit 08f825b

51 files changed

Lines changed: 541 additions & 143 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/tests.yml

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,35 @@ jobs:
1010
runs-on: ubuntu-latest
1111
strategy:
1212
matrix:
13-
ruby-version: ['2.6', '2.7', '3.0']
13+
ruby-version: ['3.0', '3.2', '3.3']
14+
services:
15+
typesense:
16+
image: typesense/typesense:28.0
17+
ports:
18+
- 8108:8108
19+
volumes:
20+
- /tmp/typesense-data:/data
21+
- /tmp/typesense-analytics:/analytics
22+
env:
23+
TYPESENSE_API_KEY: xyz
24+
TYPESENSE_DATA_DIR: /data
25+
TYPESENSE_ENABLE_CORS: true
26+
TYPESENSE_ANALYTICS_DIR: /analytics
27+
TYPESENSE_ENABLE_SEARCH_ANALYTICS: true
1428

1529
steps:
30+
- name: Wait for Typesense
31+
run: |
32+
timeout 20 bash -c 'while [[ "$(curl -s -o /dev/null -w ''%{http_code}'' localhost:8108/health)" != "200" ]]; do sleep 1; done' || false
1633
- uses: actions/checkout@v3
1734
- uses: ruby/setup-ruby@v1
1835
with:
1936
ruby-version: ${{ matrix.ruby-version }}
2037
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
2138
- run: bundle exec rubocop
2239
- run: bundle exec rspec --format documentation
23-
- uses: actions/upload-artifact@v3
40+
- uses: actions/upload-artifact@v4
2441
with:
25-
name: coverage
42+
name: coverage-ruby-${{ matrix.ruby-version }}
2643
path: coverage/
2744
retention-days: 1

.rubocop.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1+
require: rubocop-rspec
2+
13
AllCops:
24
NewCops: enable
5+
TargetRubyVersion: 2.7
36

47
Style/Documentation:
58
Enabled: false
@@ -37,3 +40,12 @@ Layout/LineLength:
3740
Lint/SuppressedException:
3841
Exclude:
3942
- examples/**
43+
44+
RSpec/ExampleLength:
45+
Enabled: false
46+
47+
RSpec/MultipleExpectations:
48+
Enabled: false
49+
50+
Style/HashSyntax:
51+
Enabled: false # We still want to support older versions of Ruby

Gemfile

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,22 @@ source 'https://rubygems.org'
44

55
git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
66

7+
# Dev dependencies
8+
gem 'awesome_print', '~> 1.8'
9+
gem 'bundler', '~> 2.0'
10+
gem 'codecov', '~> 0.1'
11+
gem 'erb'
12+
gem 'guard', '~> 2.16'
13+
gem 'guard-rubocop', '~> 1.3'
14+
gem 'rake', '~> 13.0'
15+
gem 'rspec', '~> 3.9'
16+
gem 'rspec_junit_formatter', '~> 0.4'
17+
gem 'rspec-legacy_formatters', '~> 1.0' # For codecov formatter
18+
gem 'rubocop', '~> 1.12'
19+
gem 'rubocop-rspec', '~> 2.4', require: false
20+
gem 'simplecov', '~> 0.18'
21+
gem 'timecop', '~> 0.9'
22+
gem 'webmock', '~> 3.8'
23+
724
# Specify your gem's dependencies in typesense.gemspec
825
gemspec

README.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ Tests are also a good place to know how the the library works internally: [spec]
3333

3434
| Typesense Server | typesense-ruby |
3535
|------------------|----------------|
36-
| \>= v0.25.0 | \>= v0.15.0 |
36+
| \>= v28.0 | \>= v3.0.0 |
37+
| \>= v0.25.0 | \>= v1.0.0 |
3738
| \>= v0.23.0 | \>= v0.14.0 |
3839
| \>= v0.21.0 | \>= v0.13.0 |
3940
| \>= v0.20.0 | \>= v0.12.0 |
@@ -50,7 +51,11 @@ Tests are also a good place to know how the the library works internally: [spec]
5051

5152
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.
5253

53-
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
54+
To install this gem onto your local machine, run `bundle exec rake install`.
55+
56+
### Releasing
57+
58+
To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
5459

5560
## Contributing
5661

examples/aliases.rb

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,47 +3,47 @@
33
##
44
# These examples walk you through operations specifically related to aliases
55

6-
require_relative './client_initialization'
6+
require_relative 'client_initialization'
77

88
# Create a collection
99
create_response = @typesense.collections.create(
10-
"name": 'books_january',
11-
"fields": [
12-
{ "name": 'title', "type": 'string' },
13-
{ "name": 'authors', "type": 'string[]' },
14-
{ "name": 'authors_facet', "type": 'string[]', "facet": true },
15-
{ "name": 'publication_year', "type": 'int32' },
16-
{ "name": 'publication_year_facet', "type": 'string', "facet": true },
17-
{ "name": 'ratings_count', "type": 'int32' },
18-
{ "name": 'average_rating', "type": 'float' },
19-
{ "name": 'image_url', "type": 'string' }
10+
name: 'books_january',
11+
fields: [
12+
{ name: 'title', type: 'string' },
13+
{ name: 'authors', type: 'string[]' },
14+
{ name: 'authors_facet', type: 'string[]', facet: true },
15+
{ name: 'publication_year', type: 'int32' },
16+
{ name: 'publication_year_facet', type: 'string', facet: true },
17+
{ name: 'ratings_count', type: 'int32' },
18+
{ name: 'average_rating', type: 'float' },
19+
{ name: 'image_url', type: 'string' }
2020
],
21-
"default_sorting_field": 'ratings_count'
21+
default_sorting_field: 'ratings_count'
2222
)
2323

2424
ap create_response
2525

2626
# Create or update an existing alias
2727
create_alias_response = @typesense.aliases.upsert('books',
28-
"collection_name": 'books_january')
28+
collection_name: 'books_january')
2929
ap create_alias_response
3030

3131
# Add a book using the alias name `books`
3232
hunger_games_book = {
33-
'id': '1', 'original_publication_year': 2008, 'authors': ['Suzanne Collins'], 'average_rating': 4.34,
34-
'publication_year': 2008, 'publication_year_facet': '2008', 'authors_facet': ['Suzanne Collins'],
35-
'title': 'The Hunger Games',
36-
'image_url': 'https://images.gr-assets.com/books/1447303603m/2767052.jpg',
37-
'ratings_count': 4_780_653
33+
id: '1', original_publication_year: 2008, authors: ['Suzanne Collins'], average_rating: 4.34,
34+
publication_year: 2008, publication_year_facet: '2008', authors_facet: ['Suzanne Collins'],
35+
title: 'The Hunger Games',
36+
image_url: 'https://images.gr-assets.com/books/1447303603m/2767052.jpg',
37+
ratings_count: 4_780_653
3838
}
3939

4040
@typesense.collections['books'].documents.create(hunger_games_book)
4141

4242
# Search using the alias
4343
ap @typesense.collections['books'].documents.search(
44-
'q': 'hunger',
45-
'query_by': 'title',
46-
'sort_by': 'ratings_count:desc'
44+
q: 'hunger',
45+
query_by: 'title',
46+
sort_by: 'ratings_count:desc'
4747
)
4848

4949
# List all aliases

examples/collections_and_documents.rb

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# These examples walk you through all the operations you can do on a collection and a document
55
# Search is specifically covered in another file in the examples folder
66

7-
require_relative './client_initialization'
7+
require_relative 'client_initialization'
88

99
##
1010
# Create a collection
@@ -145,6 +145,16 @@
145145
# "num_documents" => 0
146146
# }
147147

148+
###
149+
# Truncate a collection
150+
# Truncation returns the number of documents deleted
151+
collection = @typesense.collections['companies'].documents.truncate
152+
ap collection
153+
154+
# {
155+
# "num_deleted": 125
156+
# }
157+
148158
# Let's create the collection again for use in our remaining examples
149159
@typesense.collections.create(schema)
150160

examples/keys.rb

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
##
44
# These examples walk you through operations to manage API Keys
55

6-
require_relative './client_initialization'
6+
require_relative 'client_initialization'
77

88
# Let's setup some test data for this example
99
schema = {
@@ -95,18 +95,18 @@
9595
# This is useful when you store multi-tenant data in a single Typesense server, but you only want
9696
# a particular tenant to access their own data. You'd generate one scoped search key per tenant.
9797
# IMPORTANT: scoped search keys should only be generated *server-side*, so as to not leak the unscoped main search key to clients
98-
scoped_search_only_api_key = @typesense.keys.generate_scoped_search_key(unscoped_search_only_api_key, { 'filter_by': 'company_id:124' })
98+
scoped_search_only_api_key = @typesense.keys.generate_scoped_search_key(unscoped_search_only_api_key, { filter_by: 'company_id:124' })
9999
ap "scoped_search_only_api_key: #{scoped_search_only_api_key}"
100100

101101
# Now let's search the data using the scoped API Key for company_id:124
102102
# You can do searches with this scoped_search_only_api_key from the server-side or client-side
103103
scoped_typesense_client = Typesense::Client.new({
104-
'nodes': [{
105-
'host': 'localhost',
106-
'port': '8108',
107-
'protocol': 'http'
104+
nodes: [{
105+
host: 'localhost',
106+
port: '8108',
107+
protocol: 'http'
108108
}],
109-
'api_key': scoped_search_only_api_key
109+
api_key: scoped_search_only_api_key
110110
})
111111

112112
search_results = scoped_typesense_client.collections['users'].documents.search({
@@ -117,8 +117,8 @@
117117

118118
# Search for a user that exists, but is outside the current key's scope
119119
search_results = scoped_typesense_client.collections['users'].documents.search({
120-
'q': 'Maxwell',
121-
'query_by': 'user_name'
120+
q: 'Maxwell',
121+
query_by: 'user_name'
122122
})
123123
ap search_results # Will return empty result set
124124

examples/overrides.rb

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
##
44
# These examples walk you through operations specifically related to result overrides / curation
55

6-
require_relative './client_initialization'
6+
require_relative 'client_initialization'
77

88
# Delete the collection if it already exists
99
begin
@@ -69,19 +69,19 @@
6969

7070
@typesense.collections['companies'].overrides.upsert(
7171
'promote-doofenshmirtz',
72-
"rule": {
73-
"query": 'doofen',
74-
"match": 'exact'
72+
rule: {
73+
query: 'doofen',
74+
match: 'exact'
7575
},
76-
"includes": [{ 'id' => '126', 'position' => 1 }]
76+
includes: [{ 'id' => '126', 'position' => 1 }]
7777
)
7878
@typesense.collections['companies'].overrides.upsert(
7979
'promote-acme',
80-
"rule": {
81-
"query": 'stark',
82-
"match": 'exact'
80+
rule: {
81+
query: 'stark',
82+
match: 'exact'
8383
},
84-
"includes": [{ 'id' => '125', 'position' => 1 }]
84+
includes: [{ 'id' => '125', 'position' => 1 }]
8585
)
8686

8787
##

examples/search.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
##
44
# These examples walk you through operations specifically related to search
55

6-
require_relative './client_initialization'
6+
require_relative 'client_initialization'
77

88
##
99
# Create a collection
@@ -110,7 +110,9 @@
110110
# Search for more documents
111111
results = @typesense.collections['companies'].documents.search(
112112
'q' => 'Non-existent',
113-
'query_by' => 'company_name'
113+
'query_by' => 'company_name',
114+
# Optionally add a user id if you use Analytics & Query Suggestions
115+
'x-typesense-user-id' => 42
114116
)
115117
ap results
116118

examples/synonyms.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
##
44
# These examples walk you through operations specifically related to synonyms
55

6-
require_relative './client_initialization'
6+
require_relative 'client_initialization'
77

88
# Delete the collection if it already exists
99
begin

0 commit comments

Comments
 (0)