WeaviateEx.Query.Sort (WeaviateEx v0.7.4)

View Source

Sort builder for Weaviate queries.

Provides a fluent API for building sort criteria.

Examples

# Single sort
Sort.by_property("title")

# Multiple sorts (chained)
Sort.by_property("category")
|> Sort.then_by_property("title", :desc)

# Sort by timestamps
Sort.by_creation_time(:desc)

Summary

Functions

Create a sort by creation timestamp.

Create a sort by object ID.

Create a sort by property name.

Create a sort by last update timestamp.

Add a secondary sort by creation time.

Add a secondary sort by ID.

Add a secondary sort by property.

Add a secondary sort by update time.

Convert sort criteria to GraphQL format.

Types

order()

@type order() :: :asc | :desc

sort_criterion()

@type sort_criterion() :: %{path: [String.t()], order: String.t()}

t()

@type t() :: [sort_criterion()]

Functions

by_creation_time(order \\ :asc)

@spec by_creation_time(order()) :: t()

Create a sort by creation timestamp.

Examples

Sort.by_creation_time()
Sort.by_creation_time(:desc)

by_id(order \\ :asc)

@spec by_id(order()) :: t()

Create a sort by object ID.

Examples

Sort.by_id()
Sort.by_id(:desc)

by_property(property, order \\ :asc)

@spec by_property(String.t(), order()) :: t()

Create a sort by property name.

Examples

Sort.by_property("title")
Sort.by_property("title", :desc)

by_update_time(order \\ :asc)

@spec by_update_time(order()) :: t()

Create a sort by last update timestamp.

Examples

Sort.by_update_time()
Sort.by_update_time(:desc)

then_by_creation_time(sorts, order \\ :asc)

@spec then_by_creation_time(t(), order()) :: t()

Add a secondary sort by creation time.

Examples

Sort.by_property("category")
|> Sort.then_by_creation_time(:desc)

then_by_id(sorts, order \\ :asc)

@spec then_by_id(t(), order()) :: t()

Add a secondary sort by ID.

then_by_property(sorts, property, order \\ :asc)

@spec then_by_property(t(), String.t(), order()) :: t()

Add a secondary sort by property.

Examples

Sort.by_property("category")
|> Sort.then_by_property("title", :desc)

then_by_update_time(sorts, order \\ :asc)

@spec then_by_update_time(t(), order()) :: t()

Add a secondary sort by update time.

to_graphql(sorts)

@spec to_graphql(t()) :: String.t()

Convert sort criteria to GraphQL format.

Examples

Sort.by_property("title", :desc)
|> Sort.to_graphql()
# => "[{path: ["title"], order: desc}]"