Hui.Query.Update (Hui v0.10.4) View Source

Struct related to Solr updating.

Example

    alias Hui.Query
    alias Hui.Encoder

    # Update / index 2 documents, commit them within 1s
    iex> doc1 = %{"name" => "The Turin Horse", "directed_by" => ["Béla Tarr"], "genre" => ["Drama"], "id" => "tt1316540"}
    %{
      "directed_by" => ["Béla Tarr"],
      "genre" => ["Drama"],
      "id" => "tt1316540",
      "name" => "The Turin Horse"
    }
    iex> doc2 = %{"name" => "I Wish", "directed_by" => ["Hirokazu Koreeda"], "genre" => ["Drama"], "id" => "tt1650453"}
    %{
      "directed_by" => ["Hirokazu Koreeda"],
      "genre" => ["Drama"],
      "id" => "tt1650453",
      "name" => "I Wish"
    }
    iex> x = %Query.Update{doc: [doc1, doc2], commit: true, commitWithin: 1000}
    %Hui.Query.Update{
      commit: true,
      commitWithin: 1000,
      delete_id: nil,
      delete_query: nil,
      doc: [
        %{
          "directed_by" => ["Béla Tarr"],
          "genre" => ["Drama"],
          "id" => "tt1316540",
          "name" => "The Turin Horse"
        },
        %{
          "directed_by" => ["Hirokazu Koreeda"],
          "genre" => ["Drama"],
          "id" => "tt1650453",
          "name" => "I Wish"
        }
      ],
      expungeDeletes: nil,
      maxSegments: nil,
      optimize: nil,
      overwrite: nil,
      rollback: nil,
      waitSearcher: nil
    }
    iex> x |> Encoder.encode
    "{\"add\":{\"commitWithin\":1000,\"doc\":{\"name\":\"The Turin Horse\",\"id\":\"tt1316540\",\"genre\":[\"Drama\"],\"directed_by\":[\"Béla Tarr\"]}},\"add\":{\"commitWithin\":1000,\"doc\":{\"name\":\"I Wish\",\"id\":\"tt1650453\",\"genre\":[\"Drama\"],\"directed_by\":[\"Hirokazu Koreeda\"]}},\"commit\":{}}"

    # Delete the documents by ID
    iex> %Query.Update{delete_id: ["tt1316540", "tt1650453"]} |> Encoder.encode
    "{\"delete\":{\"id\":\"tt1316540\"},\"delete\":{\"id\":\"tt1650453\"}}"

    # Delete the documents by filter query
    iex> %Query.Update{delete_query: "id:tt*"} |> Encoder.encode
    "{\"delete\":{\"query\":\"id:tt*\"}}"

    # Commits the docs, make them visible and remove previously deleted docs from the index
    iex> %Query.Update{commit: true, waitSearcher: true, expungeDeletes: true} |> Encoder.encode
    "{\"commit\":{\"waitSearcher\":true,\"expungeDeletes\":true}}"

    # Optimise the index, and keep the number of index segments 10 max
    iex> %Query.Update{optimize: true, maxSegments: 10} |> Encoder.encode
    "{\"optimize\":{\"maxSegments\":10}}"

Link to this section Summary

Types

t()

Struct related to Solr updating.

Link to this section Types

Specs

t() :: %Hui.Query.Update{
  commit: boolean(),
  commitWithin: integer(),
  delete_id: binary() | [binary()],
  delete_query: binary() | [binary()],
  doc: map() | [map()],
  expungeDeletes: boolean(),
  maxSegments: integer(),
  optimize: boolean(),
  overwrite: boolean(),
  rollback: boolean(),
  waitSearcher: boolean()
}

Struct related to Solr updating.

Link to this section Functions