# Scrivener.ESx
[![Build Status](http://img.shields.io/travis/ikeikeikeike/scrivener_esx.svg?style=flat-square)](http://travis-ci.org/ikeikeikeike/scrivener_esx)
[![Hex version](https://img.shields.io/hexpm/v/scrivener_esx.svg "Hex version")](https://hex.pm/packages/scrivener_esx)
[![Inline docs](https://inch-ci.org/github/ikeikeikeike/scrivener_esx.svg)](http://inch-ci.org/github/ikeikeikeike/scrivener_esx)
[![Lisence](https://img.shields.io/hexpm/l/ltsv.svg)](https://github.com/ikeikeikeike/scrivener_esx/blob/master/LICENSE)
## Installation
If [available in Hex](https://hex.pm/docs/publish), the package can be installed as:
1. Add `scrivener_esx` to your list of dependencies in `mix.exs`:
```elixir
def deps do
[{:scrivener_esx, "~> 0.1.0"}]
end
```
2. Ensure `scrivener_esx` is started before your application:
```elixir
def application do
[applications: [:scrivener_esx]]
end
```
## Usage
```elixir
defmodule MyApp.ESx do
use ESx.Model.Base, app: :my_app
use Scrivener, page_size: 10
end
```
```elixir
defmodule MyApp.Blog do
use MyApp.Web, :model
use ESx.Schema
schema "blogs" do
field :title, :string
field :content, :string
field :publish, :boolean
timestamps
end
mapping do
indexes :title, type: "string"
indexes :content, type: "string"
indexes :publish, type: "boolean"
end
```
```elixir
def index(conn, params) do
page =
MyApp.Blog
|> MyApp.ESx.search(%{query: %{match: %{title: "foo"}}})
|> MyApp.ESx.paginate(params)
render conn, :index,
people: page.entries,
page_number: page.page_number,
page_size: page.page_size,
total_pages: page.total_pages,
total_entries: page.total_entries
end
```
```elixir
page =
MyApp.Blog
|> MyApp.ESx.search(%{query: %{match: %{title: "foo"}}})
|> MyApp.ESx.paginate(page: 2, page_size: 5)
```