Skip to content

Commit 139f434

Browse files
committed
Migrate to Algolia Ruby v3 API
1 parent 81c0272 commit 139f434

3 files changed

Lines changed: 10 additions & 9 deletions

File tree

.github/workflows/test-algolia-upload.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
name: Test Algolia Upload
33
on:
44
workflow_dispatch:
5+
push:
6+
branches:
7+
- algolia
58
jobs:
69
test-upload:
710
runs-on: ubuntu-latest
@@ -14,7 +17,7 @@ jobs:
1417
ruby-version: 3.0.2
1518
- name: Install Algolia API Dependencies
1619
run: |
17-
gem install algolia -v 2.3.4
20+
gem install algolia -v '~> 3.0'
1821
- name: Upload Index to test_QUARTO
1922
run: |
2023
ruby .github/workflows/upload-algolia.rb
Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
gem 'algolia', '=2.3.4'
21
require 'json'
32
require 'algolia'
43
require 'open-uri'
@@ -13,26 +12,25 @@
1312
download = URI.open(indexUrl)
1413
IO.copy_stream(download, indexFile)
1514

16-
client = Algolia::Search::Client.create(appId, apiKey)
17-
index = client.init_index(indexName)
15+
client = Algolia::SearchClient.create(appId, apiKey)
1816
file = File.read(indexFile)
1917
records = JSON.parse(file)
2018

2119
# The API client automatically batches your records
22-
index.replace_all_objects(records, {})
20+
client.replace_all_objects(indexName, records)
2321

2422
# Apply settings from config file
2523
configFile = File.read('.github/workflows/algolia-config.json')
2624
config = JSON.parse(configFile)
2725

28-
index.set_settings(config['settings'])
26+
client.set_settings(indexName, config['settings'])
2927

3028
# Apply synonyms if present
3129
if config['synonyms'] && !config['synonyms'].empty?
32-
index.save_synonyms(config['synonyms'], { replaceExistingSynonyms: true })
30+
client.save_synonyms(indexName, config['synonyms'], nil, true)
3331
end
3432

3533
# Apply rules if present
3634
if config['rules'] && !config['rules'].empty?
37-
index.save_rules(config['rules'], { clearExistingRules: true })
35+
client.save_rules(indexName, config['rules'], nil, true)
3836
end

.github/workflows/upload-index.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
ruby-version: 3.0.2
1818
- name: Install Algolia API Dependencies
1919
run: |
20-
gem install algolia -v 2.3.4
20+
gem install algolia -v '~> 3.0'
2121
- name: Upload Index for release website
2222
run: |
2323
pwd

0 commit comments

Comments
 (0)