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

Types

t()

Struct for a Solr endpoint with a request handler and any associated HTTP headers and options

Solr parameters as keyword list or structs

Functions

Retrieve url configuration as Hui.URL.t/0 struct

Returns a configured default Solr endpoint as Hui.URL.t/0 struct

Encodes keyword list or structs 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 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: HTTPoison options.

Solr parameters as keyword list or structs.

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.

iex> 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 encode_query(url_params) View Source
encode_query(url_params()) :: binary()

Encodes keyword list or structs of Solr parameters into a query string.

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 - keyword list

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")
""

Example - t:Hui.Q.t/0 query struct

iex> x = %Hui.Q{q: "edinburgh", fl: "id,title", fq: ["type:image"], rows: 15}
%Hui.Q{
  cache: nil,
  debug: nil,
  debugQuery: nil,
  defType: nil,
  df: nil,
  echoParams: nil,
  explainOther: nil,
  fl: "id,title",
  fq: ["type:image"],
  "json.nl": nil,
  "json.wrf": nil,
  logParamsList: nil,
  omitHeader: nil,
  q: "edinburgh",
  "q.op": nil,
  rows: 15,
  segmentTerminateEarly: nil,
  sort: nil,
  sow: nil,
  start: nil,
  timeAllowed: nil,
  tr: nil,
  wt: nil
}
iex> x |> Hui.URL.encode_query
"fl=id%2Ctitle&fq=type%3Aimage&q=edinburgh&rows=15"

Other Examples - faceting, highlighting structs

iex> x = %Hui.F{field: ["year", "type"]}
%Hui.F{
  contains: nil,
  "contains.ignoreCase": nil,
  "enum.cache.minDf": nil,
  excludeTerms: nil,
  exists: nil,
  facet: true,
  field: ["year", "type"],
  interval: nil,
  limit: nil,
  matches: nil,
  method: nil,
  mincount: nil,
  missing: nil,
  offset: nil,
  "overrequest.count": nil,
  "overrequest.ratio": nil,
  pivot: [],
  "pivot.mincount": nil,
  prefix: nil,
  query: [],
  range: nil,
  sort: nil,
  threads: nil
}
iex> x |> Hui.URL.encode_query
"facet=true&facet.field=year&facet.field=type"

iex> %Hui.H{fl: "title,words", usePhraseHighlighter: true, fragsize: 250, snippets: 3 } |> Hui.URL.encode_query
"hl.fl=title%2Cwords&hl.fragsize=250&hl=true&hl.snippets=3&hl.usePhraseHighlighter=true"

See Hui.Q, Hui.F, Hui.F.Range, Hui.F.Interval for more examples

Link to this function encode_query(list, prefix, field, per_field) View Source
Link to this function to_string(url) View Source
to_string(t()) :: binary()

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