{"id":18029083,"url":"https://github.com/0b01/autocompletex","last_synced_at":"2025-12-11T23:33:49.311Z","repository":{"id":57479116,"uuid":"91943049","full_name":"0b01/autocompletex","owner":"0b01","description":"redis autocomplete for elixir","archived":false,"fork":false,"pushed_at":"2023-04-16T06:44:04.000Z","size":49,"stargazers_count":23,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-23T00:23:14.324Z","etag":null,"topics":["autocomplete","completion","elixir","redis","typeahead"],"latest_commit_sha":null,"homepage":"","language":"Elixir","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/0b01.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"license.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-05-21T08:28:04.000Z","updated_at":"2023-12-01T07:19:04.000Z","dependencies_parsed_at":"2022-09-17T04:41:53.990Z","dependency_job_id":null,"html_url":"https://github.com/0b01/autocompletex","commit_stats":null,"previous_names":["rickyhan/autocompletex"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/0b01%2Fautocompletex","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/0b01%2Fautocompletex/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/0b01%2Fautocompletex/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/0b01%2Fautocompletex/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/0b01","download_url":"https://codeload.github.com/0b01/autocompletex/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246135699,"owners_count":20729055,"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":["autocomplete","completion","elixir","redis","typeahead"],"created_at":"2024-10-30T09:07:54.779Z","updated_at":"2025-12-11T23:33:44.291Z","avatar_url":"https://github.com/0b01.png","language":"Elixir","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Autocompletex\n\n[![Coverage Status](https://coveralls.io/repos/github/rickyhan/autocompletex/badge.svg?branch=master)](https://coveralls.io/github/rickyhan/autocompletex?branch=master)\n[![Build Status](https://travis-ci.org/rickyhan/autocompletex.svg?branch=master)](https://travis-ci.org/rickyhan/autocompletex)\n![hex.pm](https://img.shields.io/hexpm/v/autocompletex.svg)\n\nAutocompletex is a low-latency plug-and-play autocomplete tool using Redis sorted set. Written in pure Elixir, it focuses on rapid prototyping using your existing stack: simply start a redis instance, and start_link a GenServer.\n\nCurrently, it provides these implementation:\n\n* Google-like query prediction based on popularity. E.G. ne -\u003e netflix, new york times \n* Lexicographic. Sorted in alphabetical order (faster)\n\nThere are two ways to run it:\n\n* Use it as a standalone microservice with HTTP connection.\n* GenServer\n\n## Installation\n\nAdd the `:autocompletex` to your `mix.exs` file:\n\n```elixir\ndef deps do\n  [{:autocompletex, \"~\u003e 0.1.0\"}]\nend\n```\n\nThen add it to `applications`:\n\n```elixir\ndefp application() do\n  [applications: [:logger, :autocompletex]]\nend\n```\n\nThen, run `mix deps.get` in your shell to fetch the new dependency.\n\n\n## Usage\n\n### Overview\n\nCurrently, two types of autocompletion are supported:\n\n* Lexicographic\n* Predictive\n\nIf you want to suggest another scheme, please post an issue.\n\nThere are 3 ways to run it.\n\n1. Standalone HTTP service\n2. Using a GenServer\n3. Supervision tree\n\n### Manual\n\nTo start a GenServer manually:\n\n```elixir\n# For Lexicographic:\n{:ok, conn} = Redix.start_link\ndb = \"testdb\"\n{:ok, worker} = Autocompletex.Lexicographic.start_link(conn, db, Autocompletex.Lexicographic)\n\n# For Predictive:\n{:ok, conn} = Redix.start_link\ndb_prefix = \"autocompletex\"\n{:ok, worker} = Autocompletex.Predictive.start_link(conn, db_prefix, Autocompletex.Predictive)\n```\n\nAlternatively, you can use it in a supervision tree.\n\nAdd this to `config.exs`:\n\n```elixir\nconfig :autocompletex,\n  redis_host: \"localhost\",\n  redis_port: 6379,\n  redis_string: nil,\n  http_server: true,\n  http_port: 3000,\n  debug: false, # runs :observer.start if true\n  type: :lexicographic #:predictive\n```\n\nThen call\n\n```elixir\nAutocompletex.Lexicographic.upsert(Autocompletex.Lexicographic, [\"test\", \"example\"])\n```\n\nIf `http_server` is set to `true`, two http endpoints will be accessible at the designated `http_port`(default: 3000).\n\n```\nupsert   -\u003e /add?term=Elixir\ncomplete -\u003e /complete?term=te\n```\n\n## API\n\nThere are two functions: `upsert` and `complete`.\n\n`upsert/2` means insert or update. For Lexicographic, if a query is already inserted, it will do nothing. For Predictive, it will increment the score of the query.\n\n`complete/3` returns a list of matched results. It takes 3 parameters: `pid`, `prefix`, `rangelen`. rangelen is the number of results to be returned. Defaults to 50.\n\n\n```elixir\n:ok = Autocompletex.Lexicographic.upsert(worker, [\"test\", \"example\"])\n{:ok, val} == complete(worker, \"te\") # assert val == [\"test\"]\n```\n\n## Misc\n\n### Import file into Redis\n\nIf you have a list of user-generated search queries, you can use a mix task to index and provision the redis instance.\n\nSimply do:\n\n```bash\nmix autocompletex.import --filename [path/to/file] [--predictive]\n```\n\n### Internals\n\nFor predictive autocompletion, this tool will create keys `[dbname]:[prefixes]` as sorted sets. For example, for dbname `autocompletex`, word `test`:\n\n```\nautocompletex:t\nautocompletex:te\nautocompletex:tes\n```\n\nFor lexicographic autocompletion, under sorted set `[dbname]`.\n\n## Docs\n\nTo be updated. In the meantime, I'm happy to answer questions in issues.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F0b01%2Fautocompletex","html_url":"https://awesome.ecosyste.ms/projects/github.com%2F0b01%2Fautocompletex","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F0b01%2Fautocompletex/lists"}