Hui.Encoder protocol (Hui v0.10.4) View Source
A protocol that underpins Solr query encoding.
Link to this section Summary
Functions
Encode various Solr query types - Hui.query/0
into string.
Encode various Solr query types - Hui.query/0
into IO data.
Link to this section Types
Link to this section Functions
Encode various Solr query types - Hui.query/0
into string.
Example - encoding keyword list
iex> alias Hui.Encoder
iex> Encoder.encode(q: "loch", start: 10, rows: 10, fq: ["type:image", "year:[2001 TO 2007]"])
"q=loch&start=10&rows=10&fq=type%3Aimage&fq=year%3A%5B2001+TO+2007%5D"
Example - encoding query structs
iex> alias Hui.Query.{DisMax,Highlight,Update}
iex> %DisMax{q: "loch", qf: "description^2.3 title", mm: "2<-25% 9<-3"} |> Encoder.encode
"mm=2%3C-25%25+9%3C-3&q=loch&qf=description%5E2.3+title"
iex> %Highlight{fl: "title,words", usePhraseHighlighter: true, fragsize: 250} |> Encoder.encode
"hl.fl=title%2Cwords&hl.fragsize=250&hl=true&hl.usePhraseHighlighter=true"
iex> %Query.Update{delete_id: ["tt1316540", "tt1650453"]} |> Encoder.encode
"{"delete":{"id":"tt1316540"},"delete":{"id":"tt1650453"}}"
See Hui.Query.Facet
, Hui.Query.FacetRange
, Hui.Query.FacetInterval
, Hui.Query.Update
for more examples.
Encode various Solr query types - Hui.query/0
into IO data.
Examples
iex> Hui.Encoder.encode_to_iodata(q: "loch", facet: true, "facet.field": ["type", "year"])
[
"q",
61,
"loch",
38,
[
"facet",
61,
"true",
38,
["facet.field", 61, "type", 38, ["facet.field", 61, "year"]]
]
]
iex> %Hui.Query.Update{delete_id: ["tt1316540", "tt1650453"]} |> Hui.Encoder.encode_to_iodata
[
123,
[
[
[
34,
"delete",
34,
58,
[123, [[34, "id", 34], 58, [34, [[] | "tt1316540"], 34]], 125]
],
44,
[
34,
"delete",
34,
58,
[123, [[34, "id", 34], 58, [34, [[] | "tt1650453"], 34]], 125]
]
]
],
125
]
IO data encoding
encode_to_iodata/1
enables the built-in structs encoder to return
IO data which can be sent directly to
IO functions or over the socket, to leverage Erlang runtime and
some HTTP client features for lower memory usage and increased performance.