Hui v0.4.1 Hui.URL View Source
Struct and utilities for working with Solr URLs and parameters.
Use the module Hui.URL.t/0
struct to specify
Solr core or collection URLs with request handlers.
Link to this section Summary
Functions
Retrieve url configuration as Hui.URL.t/0
struct
Returns a configured default Solr endpoint as Hui.URL.t/0
struct
Encodes list (keywords) of Solr parameters into a query string
Returns the string representation (URL path) of the given Hui.URL.t/0
struct
Link to this section Types
Link to this section Functions
Retrieve url configuration as Hui.URL.t/0
struct.
Example
iex> Hui.URL.configured_url(:suggester)
{:ok, %Hui.URL{handler: "suggest", url: "http://localhost:8983/solr/collection"}}
The above retrieves the following endpoint configuration e.g. from config.exs
:
config :hui, :suggester,
url: "http://localhost:8983/solr/collection",
handler: "suggest"
Returns a configured default Solr endpoint as Hui.URL.t/0
struct.
iex> Hui.URL.default_url!
%Hui.URL{handler: "select", url: "http://localhost:8983/solr/gettingstarted"}
The default endpoint can be specified in application configuration as below:
config :hui, :default,
url: "http://localhost:8983/solr/gettingstarted",
handler: "select" # optional
url
: typical endpoint including the core or collection name. This may also be a load balancer endpoint fronting several Solr upstreams.handler
: name of a request handler that processes requests.
Encodes list (keywords) of Solr parameters into a query string.
Some Solr parameters such as the filter query fq
, facet.field
can be set multiple times.
These can be specified in a list (e.g. fq: [filter1, filter]
). Dot-notated
parameters (facet.field, hl.fl) can be specified with string keys,
e.g. "facet.field": "type"
, "hl.fl": "words"
.
Example
iex> Hui.URL.encode_query(q: "loch", start: 10, rows: 10)
"q=loch&start=10&rows=10"
iex> Hui.URL.encode_query(q: "loch", fq: ["type:image", "year:[2001 TO 2007]"])
"q=loch&fq=type%3Aimage&fq=year%3A%5B2001+TO+2007%5D"
iex> Hui.URL.encode_query(q: "loch", facet: true, "facet.field": ["type", "year"])
"q=loch&facet=true&facet.field=type&facet.field=year"
iex> Hui.URL.encode_query("not a valid parameter")
""
Returns the string representation (URL path) of the given Hui.URL.t/0
struct.