# `Milvex.OrderBy`

Translates the `:order_by` option for `Milvex.query/4` into the Milvus
`order_by_fields` query parameter.

Milvus encodes result ordering as a single `KeyValuePair` whose value is a
comma-joined list of `"field:direction"` segments, e.g.
`"price:desc,rating:asc"`.

## Accepted forms

  - `:price` / `"price"` -> `"price:asc"`
  - `[:price, :rating]` -> `"price:asc,rating:asc"`
  - `[desc: :price]` -> `"price:desc"`
  - `[desc: :price, asc: :rating]` -> `"price:desc,rating:asc"`
  - `[:price, desc: :rating]` -> `"price:asc,rating:desc"`
  - `nil` / `[]` -> no parameter

Directions are `:asc` or `:desc`. Field names may be atoms or strings.

# `to_param`

```elixir
@spec to_param(term()) ::
  {:ok, Milvex.Milvus.Proto.Common.KeyValuePair.t() | nil}
  | {:error, Milvex.Errors.Invalid.t()}
```

Converts an `:order_by` option value into an `order_by_fields` `KeyValuePair`.

Returns `{:ok, nil}` when there is nothing to order by, `{:ok, kv}` with the
built `KeyValuePair`, or `{:error, %Milvex.Errors.Invalid{}}` on bad input.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
