Skip to content

Commit

Permalink
documentation for delete_by_query; bump to v0.8.2
Browse files Browse the repository at this point in the history
  • Loading branch information
boonious committed Oct 9, 2018
1 parent 1df5c2d commit 1b69d28
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 6 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## 0.8.2 (2018-10-09)

* `update/3`, `update!/3` functions for adding and updating Solr docs
* `delete/3`, `delete!/3`, `delete_by_query/3`, `delete_by_query!/3` functions for deleting Solr docs
* `commit/2`, `commit!/2` functions for committing Solr docs to index

## 0.8.1 (2018-10-08)

* Documentation, README and doctests for Solr updating via `Hui.U` struct
Expand Down
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ Hui provides functions to add, update and delete Solr documents, as well as opti

Hui.delete(url, "tt0077711") # delete one doc
Hui.delete(url, ["tt0077711", "tt0060827"]) # delete a list of docs
Hui.delete_by_query(url, ["genre:Drama", "name:Persona"]) # delete via filter queries

```

Expand All @@ -148,9 +149,6 @@ any valid binary data encapsulating Solr documents and commands.
x = %Hui.U{doc: [doc1, doc2], commitWithin: 5000, overwrite: true}
Hui.Request.update(url, x)

# Delete docs by query
Hui.Request.update(url, %Hui.U{delete_query: "name:Persona"})

# Commit and optimise index
Hui.Request.update(url, %Hui.U{commit: true, waitSearcher: true, optimize: true, maxSegments: 10})

Expand Down Expand Up @@ -311,7 +309,7 @@ by adding `hui` to your list of dependencies in `mix.exs`:
```elixir
def deps do
[
{:hui, "~> 0.8.1"}
{:hui, "~> 0.8.2"}
]
end
```
Expand Down
25 changes: 24 additions & 1 deletion lib/hui.ex
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ defmodule Hui do
### Usage
- Searching Solr: `q/1`, `q/6`, `search/2`, `search/7`
- Updating: `update/3`, `delete/3`
- Updating: `update/3`, `delete/3`, `delete_by_query/3`, `commit/2`
- Other: `suggest/2`, `suggest/5`, `spellcheck/3`
- [README](https://hexdocs.pm/hui/readme.html#usage)
"""
Expand Down Expand Up @@ -438,10 +438,33 @@ defmodule Hui do
def delete!(url, ids, commit \\ true)
def delete!(url, ids, commit) when is_binary(ids) or is_list(ids), do: Request.update(url, true, %Hui.U{delete_id: ids, commit: commit})

@doc """
Deletes Solr documents by filter queries.
This function accepts a single or list of filter queries and immediately delete the corresponding
documents from the Solr index (commit by default).
An index/update handler endpoint should be specified through a `t:Hui.URL.t/0` struct
or a URL config key. A JSON content type header for the URL is required so that Solr knows the
incoming data format and can process data accordingly.
### Example
```
# Index handler for JSON-formatted update
headers = [{"Content-type", "application/json"}]
url = %Hui.URL{url: "http://localhost:8983/solr/collection", handler: "update", headers: headers}
Hui.delete_by_query(url, "name:Persona") # delete with a single filter
Hui.delete_by_query(url, ["genre:Drama", "name:Persona"]) # delete with a list of filters
```
"""
@spec delete_by_query(binary | Hui.URL.t, binary | list(binary), boolean) :: {:ok, HTTPoison.Response.t} | {:error, Hui.Error.t}
def delete_by_query(url, queries, commit \\ true)
def delete_by_query(url, queries, commit) when is_binary(queries) or is_list(queries), do: Request.update(url, %Hui.U{delete_query: queries, commit: commit})

@doc """
Deletes Solr documents by filter queries, raise an exception in case of failure.
"""
@spec delete_by_query!(binary | Hui.URL.t, binary | list(binary), boolean) :: HTTPoison.Response.t
def delete_by_query!(url, queries, commit \\ true)
def delete_by_query!(url, queries, commit) when is_binary(queries) or is_list(queries), do: Request.update(url, %Hui.U{delete_query: queries, commit: commit})
Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ defmodule Hui.MixProject do
def project do
[
app: :hui,
version: "0.8.1",
version: "0.8.2",
elixir: "~> 1.6",
start_permanent: Mix.env() == :prod,
deps: deps(),
Expand Down

0 comments on commit 1b69d28

Please sign in to comment.