-
Notifications
You must be signed in to change notification settings - Fork 119
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
Add configuration-based index_name prefix or suffix #341
Comments
Hi,
Each developer puts their name in
AlgoliaSearch.configuration = {
application_id: ENV['ALGOLIA_APP_ID'],
api_key: ENV['ALGOLIA_ADMIN_API_KEY']
disable_indexing: ENV['ALGOLIA_DISABLE_INDEXING'] == "true" || Rails.env.test?,
env: ENV.fetch('ALGOLIA_ENV', Rails.env)
}
puts "Algolia indexing is disabled" if AlgoliaSearch.configuration[:disable_indexing]
class Page < ApplicationRecord
include AlgoliaSearch
# ...
unless AlgoliaSearch.configuration[:disable_indexing]
algoliasearch index_name: "Page_#{AlgoliaSearch.configuration[:env]}_#{I18n.default_locale}" do
attribute :title, :content
end
end
end What I'd love is to be able to set a global "pattern" for index names (such as |
Thank you for posting this, that's an interesting solution. Can't you do this instead? module ApplicationAlgoliaSearch
def self.included(base)
base.include AlgoliaSearch
base.extend ClassMethods
end
module ClassMethods do
def application_algoliasearch(options = {}, &block)
return if AlgoliaSearch.configuration[:disable_indexing]
options[:index_name] = "#{self.name}_#{AlgoliaSearch.configuration[:env]}_#{I18n.default_locale}" if options[:index_name].blank?
algoliasearch(options, &block)
end
end
end
class Page < ApplicationRecord
include ApplicationAlgoliaSearch
application_algoliasearch do
attribute :title, :content
end
end |
I have to try it, but I guess that's a good way to make it DRY 👍 |
Thank you for sharing your solutions 🙏 So ideallly, from what I understand, we'd need to have a function which:
Is this correct? |
Yes @julienbourdeau that would be awesome! |
@julienbourdeau customizable index_name modification function may be great, but simply having additional initializer configuration options (suffix/prefix, per_environment) may work fine as well (at least for me). |
The really simple change I'd like to see is for That would be the easiest way to provide more envs without having to create additional "real" Rails Envs. In my case I just want this for a quick temporary staging environment (like production, but with a different DB), but I could see this working for multiple developers (who use RAILS_ENV=development, but have separate databases). In the meantime, I'm disable algoliasearch index_name: "Article_#{ENV.fetch('ALGOLIA_ENV', Rails.env)}", per_environment: false, ... |
We have
per_environment
option that allows us to add environment-based suffix to indices names. However, in a typical scenario, several developers work in the same 'development' environment, but have different local databases, and probably would want different indices. Or we may have several review apps, that have same 'staging' environment, but do not share the same database.Probably it would be great to have something like
global_index_name_prefix
configuration option, that could be defined inENV
variable (per developer/per review app). Then use this option as a prefix inalgolia_index_name
method.Looks like django version have something like this.
If that sounds okay, I may actually create pr for this.
The text was updated successfully, but these errors were encountered: