Hui.URL (Hui v0.10.4) 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.
Hui URL endpoints
# binary
url = "http://localhost:8983/solr/collection"
Hui.search(url, q: "loch")
# key referring to config setting
url = :library
Hui.search(url, q: "edinburgh", rows: 10)
# Hui.URL struct
url = %Hui.URL{url: "http://localhost:8983/solr/collection", handler: "suggest"}
Hui.search(url, suggest: true, "suggest.dictionary": "mySuggester", "suggest.q": "el")
Hui.URL.t/0
struct also enables HTTP headers and options to be specified.
HTTP options availability depends on the underpinning client used:
- built-in Erlang httpc options
- if configured, HTTPoison options
# setting up a header and a 10s timeout
url = %Hui.URL{url: "..", headers: [{"accept", "application/json"}], options: [timeout: 10000]}
Hui.search(url, q: "solr rocks")
Link to this section Summary
Types
Struct for a Solr endpoint with a request handler and any associated HTTP headers and options.
Functions
Retrieve url configuration as Hui.URL.t/0
struct.
Returns a configured default Solr endpoint as Hui.URL.t/0
struct.
Returns the string representation (URL path) of the given Hui.URL.t/0
struct.
Link to this section Types
Specs
Specs
options() :: Keyword.t()
Specs
t() :: %Hui.URL{ handler: nil | binary(), headers: nil | headers(), options: nil | options(), url: nil | binary() }
Struct for a Solr endpoint with a request handler and any associated HTTP headers and options.
Example
%Hui.URL{handler: "suggest", url: "http://localhost:8983/solr/collection"}
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 Solr request handler that processes requests.headers
: HTTP headers.options
: Erlang httpc options or HTTPoison options if configured
Link to this section Functions
Specs
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"
Specs
default_url!() :: t() | nil
Returns a configured default Solr endpoint as Hui.URL.t/0
struct.
Hui.URL.default_url!
%Hui.URL{handler: "select", url: "http://localhost:8983/solr/gettingstarted", headers: [{"accept", "application/json"}], options: [timeout: 10000]}
The default endpoint can be specified in application configuration as below:
config :hui, :default,
url: "http://localhost:8983/solr/gettingstarted",
handler: "select", # optional
headers: [{"accept", "application/json"}],
options: [timeout: 10000]
Specs
Returns the string representation (URL path) of the given Hui.URL.t/0
struct.