Hui v0.10.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.

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, e.g. HTTPoison options to be specified in keyword lists. HTTPoison options provide further controls for a request, e.g. timeout, recv_timeout, max_redirect, params etc.

  # setting up a header and a 10s receiving connection timeout
  url = %Hui.URL{url: "..", headers: [{"accept", "application/json"}], options: [recv_timeout: 10000]}
  Hui.search(url, q: "solr rocks")

Link to this section Summary

Types

t()

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

Link to this type headers() View Source
headers() :: [{binary(), binary()}]
Link to this type t() View Source
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: e.g. HTTPoison options.

Link to this section Functions

Link to this function configured_url(config_key) View Source
configured_url(atom()) :: {:ok, t()} | {:error, binary()} | nil

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"
Link to this function default_url!() View Source
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: [recv_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: [recv_timeout: 10000]
Link to this function to_string(uri) View Source
to_string(t()) :: binary()

Returns the string representation (URL path) of the given Hui.URL.t/0 struct.