{"id":16487532,"url":"https://github.com/sikanhe/algolia-elixir","last_synced_at":"2025-04-05T08:09:22.781Z","repository":{"id":6079392,"uuid":"54617502","full_name":"sikanhe/algolia-elixir","owner":"sikanhe","description":"Elixir implementation of Algolia search API","archived":false,"fork":false,"pushed_at":"2022-10-12T22:24:43.000Z","size":211,"stargazers_count":91,"open_issues_count":9,"forks_count":49,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-02T02:48:40.931Z","etag":null,"topics":["algolia","algolia-search","elixir"],"latest_commit_sha":null,"homepage":"","language":"Elixir","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sikanhe.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-03-24T05:42:13.000Z","updated_at":"2023-05-27T05:16:35.000Z","dependencies_parsed_at":"2022-09-05T21:51:27.969Z","dependency_job_id":null,"html_url":"https://github.com/sikanhe/algolia-elixir","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sikanhe%2Falgolia-elixir","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sikanhe%2Falgolia-elixir/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sikanhe%2Falgolia-elixir/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sikanhe%2Falgolia-elixir/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sikanhe","download_url":"https://codeload.github.com/sikanhe/algolia-elixir/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247305935,"owners_count":20917208,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["algolia","algolia-search","elixir"],"created_at":"2024-10-11T13:35:10.037Z","updated_at":"2025-04-05T08:09:22.760Z","avatar_url":"https://github.com/sikanhe.png","language":"Elixir","funding_links":[],"categories":["Community API Clients"],"sub_categories":[],"readme":"## Algolia\n\n[![Build Status](https://semaphoreci.com/api/v1/sikanhe/algolia-elixir/branches/master/badge.svg)](https://semaphoreci.com/sikanhe/algolia-elixir)\n[![Inline docs](http://inch-ci.org/github/sikanhe/algolia-elixir.svg?branch=master)](http://inch-ci.org/github/sikanhe/algolia-elixir)\n\nThis is the elixir implementation of Algolia search API, it is purely functional\n\nAdd to your dependencies\n\n\n```elixir\n  defp deps do\n    [{:algolia, \"~\u003e 0.8.0\"}]\n  end\n```\n\n(Pre-Elixir-1.4) Add :algolia to your applications\n\n```elixir\n  def application do\n    [applications: [:algolia]]\n  end\n```\n\n## Configuration\n\n#### Using environment variables:\n\n    ALGOLIA_APPLICATION_ID=YOUR_APPLICATION_ID\n    ALGOLIA_API_KEY=YOUR_API_KEY\n\n#### Using config:\n\n    config :algolia,\n      application_id: YOUR_APPLICATION_ID,\n      api_key: YOUR_API_KEY\n\n*NOTE: You must use ADMIN API_KEY instead of SEARCH API_KEY to enable write access*\n\n## The Client\n\nYou don't need to initiate an index with this client unlike other OO Algolia clients.\nHowever, Most of the client search/write functions all use the syntax\n\n    operation(index, args....)\n\nSo you can easy emulate the index.function() syntax using piping\n\n   \"my_index\" |\u003e operation(args)\n\n\n### Return values\n\nAll functions are serialized into maps before returning these responses\n\n  - `{:ok, response}`\n  - `{:error, error_code, response}`\n  - `{:error, \"Cannot connect to Algolia\"}`: The client implements retry\n      strategy on all Algolia hosts with increasing timeout, It should only\n      return this error when it has tried all 4 hosts.\n      [**More Details here**](https://www.algolia.com/doc/rest#quick-reference).\n\n## Examples\n\n### Searching\n\n#### Searching an index\n\n```elixir\n    \"my_index\" |\u003e search(\"some query\")\n```\n\nWith Options\n\n```elixir\n    \"my_index\" |\u003e search(\"some query\", [attributesToRetrieve: \"firstname\", hitsPerPage: 20])\n```\n\nSee all available search options [**here**](https://www.algolia.com/doc/rest#full-text-search-parameters)\n\n#### Multiple queries at once\n\n```elixir\n    multi([%{index_name =\u003e \"my_index1\", query: \"search query\"},\n            %{index_name =\u003e \"my_index2\", query: \"another query\", hitsPerPage: 3,},\n            %{index_name =\u003e \"my_index3\", query: \"3rd query\", tagFilters: \"promotion\"}])\n```\n\nYou can specify a strategy to optimize your multiple queries\n- `:none`: Execute the sequence of queries until the end.\n- `stop_if_enough_matches`: Execute the sequence of queries until the number of hits is reached by the sum of hits.\n\n```elixir\n    multi([query1, query2], strategy: :stop_if_enough_matches)\n```\n\n### Saving\n\nAll `save_*` operations will overrides the object at the objectID\n\nSave a single object to index without specifying objectID, must have objectID\ninside object, or use the `id_attribute` option (see below)\n\n```elixir\n    \"my_index\" |\u003e save_object(%{objectID: \"1\"})\n```\n\nSave a single object with a given objectID\n\n```elixir\n    \"my_index\" |\u003e save_object(%{title: \"hello\"}, \"12345\")\n```\n\nSave multiple objects to an index\n\n```elixir\n    \"my_index\" |\u003e save_objects([%{objectID: \"1\"}, %{objectID: \"2\"}])\n```\n\n### Updating\n\nPartially updates a single object\n\n```elixir\n    \"my_index\" |\u003e partial_update_object(%{title: \"hello\"}, \"12345\")\n```\n\nUpdate multiple objects, must have objectID in each object, or use the `id_attribute` option (see below)\n\n\n```elixir\n    \"my_index\" |\u003e partial_update_objects([%{objectID: \"1\"}, %{objectID: \"2\"}])\n```\n\nPartial update by default creates a new object if an object does not exist at the\nobjectID, you can turn this off by passing `false` to the `:upsert?` option\n\n```elixir\n    \"my_index\" |\u003e partial_update_object(%{title: \"hello\"}, \"12345\", upsert?: false)\n    \"my_index\" |\u003e partial_update_objects([%{id: \"1\"}, %{id: \"2\"}], id_attribute: :id, upsert?: false)\n```\n\n\n### Bonus for this Elixir client only: `id_attribute` option\n\nAll write functions such as `save_object` and `partial_update_object` comes with an `id_attribute` option that lets the you specifying an objectID from an existing field in the object, so you do not\nhave to generate it yourself\n\n```elixir\n    \"my_index\" |\u003e save_object(%{id: \"2\"}, id_attribute: :id)\n```\n\nIt also works for batch operations, such as `save_objects` and `partial_update_objects`\n\n```elixir\n    \"my_index\" |\u003e save_objects([%{id: \"1\"}, %{id: \"2\"}], id_attribute: :id)\n```\n\nHowever, this cannot be used together with an ID specifying argument together\n\n```elixir\n    \"my_index\" |\u003e save_object(%{id: \"1234\"}, \"1234\", id_attribute: :id)\n    \u003e Error\n```\n\n### Wait for task\n\nAll write operations can be waited on by simply piping the response into wait/1\n\n```elixir\n    \"my_index\" |\u003e save_object(%{id: \"123\"}) |\u003e wait\n```\n\n\nSince the client polls the server to check for publishing status,\nYou can specify a time between each tick of the poll, the default is 1000 ms\n\n```elixir\n    \"my_index\" |\u003e save_object(%{id: \"123\"}) |\u003e wait(2_000)\n```\n\nYou can also use the underlying wait_task function explicitly\n\n\n```elixir\n    {:ok, %{\"taskID\" =\u003e task_id, \"indexName\" =\u003e index}}\n      = \"my_index\" |\u003e save_object(%{id: \"123\"}\n\n    wait(index, task_id)\n```\n\nor with option\n\n```elixir\n    wait(index, task_id, 2_000)\n```\n\n### Index related operations\n\n#### Listing all indexes\n\n ```elixir\n    list_indexes()\n ```\n\n#### move_index/2\n\nMoves an index to a new one\n\n```elixir\n   move_index(source_index, destination_index)\n```\n\n#### copy_index/2\n\nCopies an index to a new one\n\n```elixir\n    copy_index(source_index, destination_index)\n```\n\n#### Clear an index\n\n```elixir\n    clear_index(index)\n```\n\n### Settings\n\n#### get_settings/1\n\n```elixir\n    get_settings(index)\n```\n\nExample response\n\n```elixir\n{:ok,\n  %{\"minWordSizefor1Typo\" =\u003e 4,\n    \"minWordSizefor2Typos\" =\u003e 8,\n    \"hitsPerPage\" =\u003e 20,\n    \"attributesToIndex\" =\u003e nil,\n    \"attributesToRetrieve\" =\u003e nil,\n    \"attributesToSnippet\" =\u003e nil,\n    \"attributesToHighlight\" =\u003e nil,\n    \"ranking\" =\u003e [\n        \"typo\",\n        \"geo\",\n        \"words\",\n        \"proximity\",\n        \"attribute\",\n        \"exact\",\n        \"custom\"\n    ],\n    \"customRanking\" =\u003e nil,\n    \"separatorsToIndex\" =\u003e \"\",\n    \"queryType\" =\u003e \"prefixAll\"}\n}\n```\n\n#### set_settings/2\n\n```elixir\n    set_settings(index, %{\"hitsPerPage\" =\u003e 20})\n\n     \u003e %{\"updatedAt\" =\u003e \"2013-08-21T13:20:18.960Z\",\n        \"taskID\" =\u003e 10210332.\n        \"indexName\" =\u003e \"my_index\"}\n```\n### TODOS:\n\n- [x] get_object\n- [x] save_object\n- [x] save_objects\n- [x] update_object\n- [x] partial_update_object\n- [x] partial_update_objects\n- [x] delete_object\n- [x] delete_objects\n- [x] list_indexes\n- [x] clear_index\n- [x] wait_task\n- [x] wait (convenience function for piping response into wait_task)\n- [x] set_settings\n- [x] get_settings\n- [ ] list_user_keys\n- [ ] get_user_key\n- [ ] add_user_key\n- [ ] update_user_key\n- [ ] delete_user_key\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsikanhe%2Falgolia-elixir","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsikanhe%2Falgolia-elixir","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsikanhe%2Falgolia-elixir/lists"}