Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: upgrade to newest API client version #449

Open
wants to merge 40 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
2578da0
chore: update algolia version
DevinCodes Oct 7, 2024
9b1c417
WIP: fix tests until FowardToReplicas
DevinCodes Oct 9, 2024
bc80b19
chore: fix SubReplicas tests
DevinCodes Oct 9, 2024
c32aed4
chore: fix Book tests
DevinCodes Oct 9, 2024
4cc7e77
chore: fix pagination tests
DevinCodes Oct 9, 2024
fb27573
chore: fix disabled indexing tests
DevinCodes Oct 14, 2024
8ac0225
fix tests
DevinCodes Oct 14, 2024
b6ea1a3
ensure latest gem version
DevinCodes Oct 14, 2024
bc48f9a
fix: virtual replica test
DevinCodes Oct 14, 2024
7998182
test matrix
DevinCodes Oct 14, 2024
c41e65d
Update Gemfile
DevinCodes Oct 14, 2024
bfe1a89
Update config.yml
DevinCodes Oct 14, 2024
99e68db
Update Gemfile
DevinCodes Oct 14, 2024
544278f
Update config.yml
DevinCodes Oct 14, 2024
f5f0e3d
Update config.yml
DevinCodes Oct 14, 2024
a7f2952
Update algoliasearch-rails.rb
DevinCodes Oct 14, 2024
2e25bb1
sanitizer
DevinCodes Oct 14, 2024
d158342
Update algoliasearch-rails.rb
DevinCodes Oct 14, 2024
9e698f4
Update algoliasearch-rails.rb
DevinCodes Oct 14, 2024
74413b0
Update algoliasearch-rails.rb
DevinCodes Oct 14, 2024
5b6af12
Update pagy.rb
DevinCodes Oct 14, 2024
f421f52
Update integration_spec.rb
DevinCodes Oct 14, 2024
dbbcc76
Update pagy.rb
DevinCodes Oct 14, 2024
1ecad6c
Update integration_spec.rb
DevinCodes Oct 14, 2024
1bba7f3
Update pagy.rb
DevinCodes Oct 14, 2024
8a32e9b
Update pagy.rb
DevinCodes Oct 14, 2024
2836446
Update integration_spec.rb
DevinCodes Oct 14, 2024
91ccfc5
Update integration_spec.rb
DevinCodes Oct 14, 2024
079c71d
sanitizer
DevinCodes Oct 14, 2024
cd3c1de
chore: clean up algoliasearch/configuration
DevinCodes Oct 14, 2024
531d98a
remove `index` method
DevinCodes Oct 14, 2024
ab2d74b
chore: handle todos
DevinCodes Oct 14, 2024
8338b52
Update algoliasearch-rails.gemspec
DevinCodes Oct 14, 2024
7c56ebe
Update spec_helper.rb
DevinCodes Oct 14, 2024
fc5e4a1
address feedback
DevinCodes Oct 14, 2024
1d81f47
feat: allow setting user agent
DevinCodes Oct 15, 2024
72998fd
pin version
DevinCodes Oct 17, 2024
5b3ceea
Update algoliasearch-rails.gemspec
DevinCodes Oct 17, 2024
54e696f
Update config.yml
DevinCodes Oct 18, 2024
b23f7f2
prep release
DevinCodes Oct 18, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 18 additions & 42 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ aliases:
curl -s https://algoliasearch-client-keygen.herokuapp.com | sh >> $BASH_ENV
fi

- &install_sqlite
name: Install SQLite
command: sudo apt-get update && sudo apt-get install -y sqlite3 libsqlite3-dev

- &check_bundler
name: Which bundler?
command: bundle -v
Expand Down Expand Up @@ -33,7 +37,7 @@ aliases:

references:
default_docker_ruby_executor: &default_docker_ruby_executor
image: circleci/ruby:<< parameters.version >>
image: cimg/ruby:<< parameters.version >>
environment:
BUNDLE_JOBS: 3
BUNDLE_RETRY: 3
Expand All @@ -57,6 +61,7 @@ jobs:
- *default_docker_ruby_executor
steps:
- checkout
- run: *install_sqlite
- run: *check_bundler
- restore_cache: *restore_cache
- run: *install_bundler
Expand All @@ -69,45 +74,16 @@ workflows:
ci:
jobs:
- test:
name: 'Rails 5.1 - Ruby 2.4'
version: '2.4'
rails-version: '5.1'
sequel-version: '5.0'
- test:
name: 'Rails 5.1 - Ruby 2.5'
version: '2.5'
rails-version: '5.1'
sequel-version: '5.0'
- test:
name: 'Rails 5.1 - Ruby 2.6'
version: '2.6'
rails-version: '5.1'
sequel-version: '5.0'


- test:
name: 'Rails 6.0 - Ruby 2.5'
version: '2.5'
rails-version: '6.0'
sequel-version: '5.0'
- test:
name: 'Rails 6.0 - Ruby 2.6'
version: '2.6'
rails-version: '6.0'
sequel-version: '5.0'
- test:
name: 'Rails 6.0 - Ruby 2.7'
version: '2.7'
rails-version: '6.0'
sequel-version: '5.0'

- test:
name: 'Rails 6.1 - Ruby 2.7'
version: '2.7'
rails-version: '6.1'
sequel-version: '5.0'
name: "Ruby << matrix.version >> - Rails << matrix.rails-version >>"
matrix:
parameters:
version: [ '2.5', '2.6', '2.7', '3.0', '3.1' ]
rails-version: [ '6.0', '6.1' ]
sequel-version: [ '5.0' ]
- test:
name: 'Rails 6.1 - Ruby 3.0'
version: '3.0'
rails-version: '6.1'
sequel-version: '5.0'
name: "Ruby << matrix.version >> - Rails << matrix.rails-version >>"
matrix:
parameters:
version: ['3.0', '3.1']
rails-version: ['7.0']
sequel-version: ['5.0']
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

first time I'm seeing it written like it's pronounced

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haha, yes this is for a gem named sequel 😄

6 changes: 5 additions & 1 deletion CHANGELOG.MD
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# CHANGELOG

## [Unreleased](https://github.com/algolia/algoliasearch-rails/compare/2.2.1...master)
## [Unreleased](https://github.com/algolia/algoliasearch-rails/compare/3.0.0...master)

## [3.0.0](https://github.com/algolia/algoliasearch-rails/compare/2.3.2...3.0.0)
This new major version leverages the latest version of the Ruby Algolia API client. It also drops (official) support for Rails 5.x and Ruby versions older than 2.5
For a list of known breaking changes, please refer to [the upgrade guide](./UPGRADING_TO_V3.MD)

## [2.3.2](https://github.com/algolia/algoliasearch-rails/compare/2.3.1...2.3.2)
### Added
Expand Down
6 changes: 3 additions & 3 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
source "http://rubygems.org"

gem 'json', '>= 1.5.1'
gem 'algolia', '< 3.0.0'
gem 'algolia', '>= 3.5.2'

if defined?(RUBY_ENGINE) && RUBY_ENGINE == 'rbx'
gem 'rubysl', '~> 2.0', :platform => :rbx
Expand All @@ -16,7 +16,7 @@ group :test do
else
gem 'sqlite3', '< 1.4.0', :platform => [:rbx, :ruby]
end
gem 'rspec', '>= 2.5.0', '< 3.0'
gem 'rspec', '~> 3.0'
gem 'jdbc-sqlite3', :platform => :jruby
gem 'activerecord-jdbc-adapter', :platform => :jruby
gem 'activerecord-jdbcsqlite3-adapter', :platform => :jruby
Expand All @@ -27,7 +27,7 @@ group :test do
end

group :development do
gem 'rake', '~> 10.1.0'
gem 'rake', '>= 10.1.0'
gem 'rdoc'
end

Expand Down
66 changes: 66 additions & 0 deletions UPGRADING_TO_V3.MD
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
Version 3 of the `algoliasearch-rails` gem replaces the Algolia API client version in use from version 2 to version 3.
These versions of the API client differ significantly, so you likely need to make code changes when updating.
We've tried keeping most of the changes internal, but there are still some breaking changes you need to be aware of when upgrading.

If you encounter any breaking changes to the Rail integration that are not listed here, please open a Pull Request to add them to this list.

## Breaking changes

`algolia_ensure_init` (this method is protected and shouldn't be called manually, but we list it here anyways): the method no longer returns an initialized `index` object as this is not part of the new API client. The method now returns nothing, but it still ensures the index exists and applies settings if needed.

---
`Model.search`, `Model.raw_search`: response keys in the new API client are no longer strings, but are *always* symbols. For example:
```ruby
# Before
results = Product.raw_search('shirt')
p results['hits']

# After
results = Product.raw_search('shirt')
p results[:hits]
```
---
`Model.search_for_facet_values`: this no longer returns an array of hashes, but an array of objects of type `Algolia::Search::FacetHits`:
```ruby
# Before
facets = Color.search_for_facet_values('short_name', 'bl', :query => 'black')
puts facets.first['value']

# After
facets = Color.search_for_facet_values('short_name', 'bl', :query => 'black')
facets.first.value
```

---
`Model.index_name` takes an additional, optional parameter. You can use this if you want to get the name of one of your replica indices, which ensures the index naming takes configuration that modifies the index name into account.
For example, if you have the `:per_environment` option set to true, it will automatically add the environment name in the index name.
```ruby
def Product
include AlgoliaSearch

algoliasearch({ per_environment: true }) do
add_replica 'Suits', per_environment: true do
# replica settings
end
end

end
main_index_name = Product.index_name
replica_index_name = Product.index_name('Suits')
```

---
`AlgoliaSearch::Configuration.client_opts`, `AlgoliaSearch::Configuration::REQUIRED_CONFIGURATION` and `AlgoliaSearch::SafeIndex` have been removed.
If you need to configure the API client other than the ways that are provided now, it's recommended to set up an instance manually.

---
`Model.index` and `Model.algolia_index` have been removed, as there is no notion of an `Index` object in the new version of the API clients.
Instead, you can use `Model.index_name` to get the name of the index to target, and use this on an instance of the API client directly.

```ruby
# Before
res = Product.index.search('shoe')

# After
res = AlgoliaSearch.client.search_single_index(Product.index_name, { query: 'shoe' })
```
6 changes: 3 additions & 3 deletions algoliasearch-rails.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -79,19 +79,19 @@ Gem::Specification.new do |s|

if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
s.add_runtime_dependency(%q<json>, [">= 1.5.1"])
s.add_runtime_dependency(%q<algolia>, ["< 3.0.0"])
s.add_runtime_dependency(%q<algolia>, [">= 3.5.2"])
s.add_development_dependency(%q<will_paginate>, [">= 2.3.15"])
s.add_development_dependency(%q<kaminari>, [">= 0"])
s.add_development_dependency(%q<pagy>, [">= 0"])
s.add_development_dependency "rake"
s.add_development_dependency "rdoc"
else
s.add_dependency(%q<json>, [">= 1.5.1"])
s.add_dependency(%q<algolia>, ["< 3.0.0"])
s.add_dependency(%q<algolia>, [">= 3.5.2"])
end
else
s.add_dependency(%q<json>, [">= 1.5.1"])
s.add_dependency(%q<algolia>, ["< 3.0.0"])
s.add_dependency(%q<algolia>, [">= 3.5.2"])
end
end

Loading