https://github.com/ikeikeikeike/scrivener_esx
pagination
https://github.com/ikeikeikeike/scrivener_esx
elixir elixir-library scrivener
Last synced: about 1 month ago
JSON representation
pagination
- Host: GitHub
- URL: https://github.com/ikeikeikeike/scrivener_esx
- Owner: ikeikeikeike
- License: mit
- Created: 2016-11-22T03:28:53.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2019-05-28T21:25:07.000Z (about 6 years ago)
- Last Synced: 2025-04-28T06:43:36.675Z (about 2 months ago)
- Topics: elixir, elixir-library, scrivener
- Language: Elixir
- Size: 10.7 KB
- Stars: 3
- Watchers: 1
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Scrivener.ESx
[](http://travis-ci.org/ikeikeikeike/scrivener_esx)
[](https://hex.pm/packages/scrivener_esx)
[](http://inch-ci.org/github/ikeikeikeike/scrivener_esx)
[](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.Schemaschema "blogs" do
field :title, :string
field :content, :string
field :publish, :booleantimestamps
endmapping 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)
```