# How to contribute

## Report a bug or a problem

Report in the issue tracker at https://codeberg.org/ArthurClemens/refine/issues

## Suggest a code improvement

- Set up your development environment - see below.
- Create a branch with your code changes.
- Make sure to run tests to ensure new code won't break them. When adding code, fix current tests when needed, or add new tests.
- Run `mix qa` to perform formatting and checks.
- Open a new pull request at https://codeberg.org/ArthurClemens/refine/pulls.

## Development environment

### Setup

Clone this repository.

```bash
mix deps.get
mix destroy_dev_repo
mix init_dev_repo
iex -S mix
```

### Add test data

Add data that is also used in the unit tests.

```elixir
alias Refine.Test.{Database, Factory}
alias Refine.Dev.Repo

Database.init()
Factory.init_resources(article_count: 10)
```

Create a facets table. Below is a simple example; see the tests for more examples.

```elixir
alias Refine.Dev.Repo

config = %{
  facets_table: "articles_facets",
  source_table: "articles",
  add_identity_column_if_not_exists: true,
  identity_column: "identity",
  facets: [
    %{facet_name: "draft"}
  ]
}

Refine.create_facets_table(config, repo: Repo)
```

### Faceted search

When starting an `iex` session from here, first start the database:

```elixir
alias Refine.Test.Database

Database.start()
```

Minimal example:

```elixir
alias Refine.Dev.Repo

Refine.search(config, repo: Repo)
```

Search with options:

```elixir
import Ecto.Query
alias Refine.Dev.Repo

term = "%memory%"
query = from a in Refine.Test.EctoSchemas.Article,
  where: ilike(a.title, ^term) or ilike(a.summary, ^term),
  select: %{id: a.id, title: a.title, summary: a.summary, draft: a.draft}
facets = %{"draft" => ["true"]}

Refine.search(config, query: query, facets: facets, repo: Repo)
```