{"id":20072220,"url":"https://github.com/elixir-haystack/haystack","last_synced_at":"2025-04-08T10:14:15.959Z","repository":{"id":144600497,"uuid":"608821024","full_name":"elixir-haystack/haystack","owner":"elixir-haystack","description":"Simple, extendable full-text search engine written in Elixir","archived":false,"fork":false,"pushed_at":"2025-01-07T09:54:35.000Z","size":93,"stargazers_count":215,"open_issues_count":5,"forks_count":4,"subscribers_count":5,"default_branch":"main","last_synced_at":"2025-04-01T09:19:49.854Z","etag":null,"topics":["elixir"],"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/elixir-haystack.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-03-02T20:03:57.000Z","updated_at":"2025-03-30T13:16:41.000Z","dependencies_parsed_at":null,"dependency_job_id":"bae6bf84-35c7-458f-a046-f2448e53a238","html_url":"https://github.com/elixir-haystack/haystack","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elixir-haystack%2Fhaystack","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elixir-haystack%2Fhaystack/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elixir-haystack%2Fhaystack/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elixir-haystack%2Fhaystack/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/elixir-haystack","download_url":"https://codeload.github.com/elixir-haystack/haystack/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247819933,"owners_count":21001394,"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":["elixir"],"created_at":"2024-11-13T14:39:00.205Z","updated_at":"2025-04-08T10:14:15.935Z","avatar_url":"https://github.com/elixir-haystack.png","language":"Elixir","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Haystack\n\n\u003c!-- MDOC !--\u003e\n\n[![Build Status](https://github.com/elixir-haystack/haystack/actions/workflows/ci.yml/badge.svg)](https://github.com/elixir-haystack/haystack/actions) [![Coverage Status](https://coveralls.io/repos/github/elixir-haystack/haystack/badge.svg?branch=main)](https://coveralls.io/github/elixir-haystack/haystack?branch=main)\n\n**Haystack is a simple, extendable search engine written in Elixir.**\n\n## Installation\n\nHaystack can be installed by adding `haystack` to your list of dependencies in `mix.exs`:\n\n```elixir\ndef deps do\n  [\n    {:haystack, \"~\u003e 0.1.0\"}\n  ]\nend\n```\n\nThe entry point to Haystack is the `Haystack` module. This module is responsible for managing the various indexes you have as part of the project as well as any future configuration or high level concerns.\n\nThese concerns are encapsulated in the `%Haystack{}` struct:\n\n```elixir\nhaystack = Haystack.new()\n```\n\nCurrently, the `Haystack` module has a single `index/3` function that accepts the name of the index as an atom and a callback function to apply changes to the index. If the index does not already exist, Haystack will create one and pass it into the callback so you can configure or use it:\n\n```elixir\nHaystack.index(haystack, :animals, fn index -\u003e\n  index\nend)\n```\n\nOnce you have an `index`, the first thing you need to do is specify the fields of the index:\n\n```elixir\nalias Haystack.Index\n\nHaystack.index(haystack, :animals, fn index -\u003e\n  index\n  |\u003e Index.ref(Index.Field.term(\"id\"))\n  |\u003e Index.field(Index.Field.new(\"name\"))\n  |\u003e Index.field(Index.Field.new(\"description\"))\nend)\n```\n\nThe `ref` is the identifier of the document. You can create as many fields on the document as you want. When you add documents to the index, Haystack will automatically extract the fields you have configured.\n\nYou can also provide nested fields using dot syntax:\n\n```elixir\nalias Haystack.Index\n\nHaystack.index(haystack, :people, fn index -\u003e\n  index\n  |\u003e Index.ref(Index.Field.term(\"id\"))\n  |\u003e Index.field(Index.Field.new(\"name\"))\n  |\u003e Index.field(Index.Field.new(\"address.postcode\"))\nend)\n```\n\nEach Haystack index has a configurable storage implementation. By default the storage implementation is essentially a map, which is great for testing and prototyping, but probably not a good solution if you want to use Haystack as part of a real application. You can configure a custom storage implementation on the index:\n\n```elixir\nalias Haystack.{Index, Storage}\n\nHaystack.index(haystack, :animals, fn index -\u003e\n  index\n  |\u003e Index.ref(Index.Field.term(\"id\"))\n  |\u003e Index.field(Index.Field.new(\"name\"))\n  |\u003e Index.field(Index.Field.new(\"description\"))\n  |\u003e Index.storage(Storage.ETS.new())\nend)\n```\n\nThe ETS storage implementation is provided as one of the default implementations that ships with Haystack out of the box. If you would like to extend Haystack with your own storage implementation, it's very easy to do so.\n\nFinally, the most important part of a library that provides full-text search is the ability to query the indexes. Here is the most basic version of applying queries:\n\n```elixir\nHaystack.index(haystack, :animals, \u0026Index.search(\u00261, \"Red Panda\"))\n```\n\nThis would search the `:animals` index for the phrase `\"Red Panda\"`. Haystack also offers a powerful way to build and run search queries.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felixir-haystack%2Fhaystack","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Felixir-haystack%2Fhaystack","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felixir-haystack%2Fhaystack/lists"}