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: allow :algolia settings to be either static or dynamic #95

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

Jordan-Kowal
Copy link
Contributor

New

The Algoliax.Indexer now supports dynamic definition for the :algolia settings. It can supports 2 types of configurations:

  • (Existing) Keyword list
  • (New) Name of a 0-arity function that returns a keyword list
defmodule People do
  use Algoliax.Indexer,
    index_name: :people,
    object_id: :reference,
    schemas: [People],
    algolia: :runtime_algolia

  def runtime_algolia do
    [
      attribute_for_faceting: ["age"],
      custom_ranking: ["desc(updated_at)"]
    ]
  end
end

Also added 2 new exceptions for the :algolia configuration: InvalidAlgoliaSettingsFunctionError and InvalidAlgoliaSettingsConfigurationError

Other changes

Existing direct calls to Algoliax.Settings.replica_settings/2 will still work but will not benefit from
the dynamic :algolia configuration. Please use Algoliax.Settings.replica_settings/3 instead.

Comment on lines +63 to 71
def replica_settings(settings, replica_settings),
do: replica_settings(%{}, settings, replica_settings)

def replica_settings(module, settings, replica_settings) do
replica_settings =
case Keyword.get(replica_settings, :inherit, true) do
true -> replica_settings ++ algolia_settings(settings)
true -> replica_settings ++ algolia_settings(module, settings)
false -> replica_settings
end
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This code is not used anywhere (except in test) but it is public, so I'm not sure if I can just delete it 💀

Comment on lines +7 to +11
algolia: [
attributes_for_faceting: ["age"],
searchable_attributes: ["full_name"],
custom_ranking: ["desc(updated_at)"]
],
Copy link
Contributor Author

Choose a reason for hiding this comment

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

(nit) I simply fixed the settings configuration, but it has 0 impact since those keys are not used by the functions tested in this module

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant