Hui v0.8.2 Hui.U View Source
Struct and functions related to Solr updating.
Link to this section Summary
Link to this section Types
Struct and functions related to Solr updating.
Link to this section Functions
Encodes the Hui.U.t
module struct into Solr binary commands for JSON-formatted update.
Example
# Update / index 2 documents, commit them within 1s
iex> doc1 = %{"name" => "The Turin Horse", "directed_by" => ["Béla Tarr"], "genre" => ["Drama"], "id" => "tt1316540"}
%{
"directed_by" => ["Béla Tarr"],
"genre" => ["Drama"],
"id" => "tt1316540",
"name" => "The Turin Horse"
}
iex> doc2 = %{"name" => "I Wish", "directed_by" => ["Hirokazu Koreeda"], "genre" => ["Drama"], "id" => "tt1650453"}
%{
"directed_by" => ["Hirokazu Koreeda"],
"genre" => ["Drama"],
"id" => "tt1650453",
"name" => "I Wish"
}
iex> x = %Hui.U{doc: [doc1, doc2], commit: true, commitWithin: 1000}
%Hui.U{
commit: true,
commitWithin: 1000,
delete_id: nil,
delete_query: nil,
doc: [
%{
"directed_by" => ["Béla Tarr"],
"genre" => ["Drama"],
"id" => "tt1316540",
"name" => "The Turin Horse"
},
%{
"directed_by" => ["Hirokazu Koreeda"],
"genre" => ["Drama"],
"id" => "tt1650453",
"name" => "I Wish"
}
],
expungeDeletes: nil,
maxSegments: nil,
optimize: nil,
overwrite: nil,
rollback: nil,
waitSearcher: nil
}
iex> x |> Hui.U.encode
"{\"add\":{\"commitWithin\":1000,\"doc\":{\"name\":\"The Turin Horse\",\"id\":\"tt1316540\",\"genre\":[\"Drama\"],\"directed_by\":[\"Béla Tarr\"]}},\"add\":{\"commitWithin\":1000,\"doc\":{\"name\":\"I Wish\",\"id\":\"tt1650453\",\"genre\":[\"Drama\"],\"directed_by\":[\"Hirokazu Koreeda\"]}},\"commit\":{}}"
# Delete the documents by ID
iex> %Hui.U{delete_id: ["tt1316540", "tt1650453"]} |> Hui.U.encode
"{\"delete\":{\"id\":\"tt1316540\"},\"delete\":{\"id\":\"tt1650453\"}}"
# Delete the documents by filter query
iex> %Hui.U{delete_query: "id:tt*"} |> Hui.U.encode
"{\"delete\":{\"query\":\"id:tt*\"}}"
# Commits the docs, make them visible and remove previously deleted docs from the index
iex> %Hui.U{commit: true, waitSearcher: true, expungeDeletes: true} |> Hui.U.encode
"{\"commit\":{\"waitSearcher\":true,\"expungeDeletes\":true}}"
# Optimise the index, and keep the number of index segments 10 max
iex> %Hui.U{optimize: true, maxSegments: 10} |> Hui.U.encode
"{\"optimize\":{\"maxSegments\":10}}"