WeaviateEx.Filter (WeaviateEx v0.7.4)

View Source

Filter system for building complex query filters.

Provides a fluent API for constructing filters with operators and combinators that can be converted to GraphQL format for Weaviate queries.

Examples

# Simple equality filter
Filter.equal("status", "published")

# Numeric comparison
Filter.greater_than("views", 100)

# Combining filters with AND
Filter.all_of([
  Filter.equal("status", "published"),
  Filter.greater_than("views", 100)
])

# Complex nested filters
Filter.all_of([
  Filter.any_of([
    Filter.equal("type", "article"),
    Filter.equal("type", "post")
  ]),
  Filter.greater_than("createdAt", "2024-01-01")
])

Summary

Functions

Combine filters with AND logic.

Combine filters with OR logic.

Filter by object creation time.

Create a filter by ID.

Create a filter by property with an operator.

Filter by property string or array length.

Create a filter by reference property.

Filter by reference count.

Create a filter for a multi-target reference property.

Create a filter using a reference path.

Filter by object update time.

Contains all operator (array subset)

Contains any operator (array intersection)

Contains none operator (array contains none of the values).

Equal operator

Greater than or equal operator

Greater than operator

Create a length path for a property.

Less than or equal operator

Less than operator

Like operator (wildcard matching)

Negate a filter.

Not equal operator

Null check operator

Convert a filter to GraphQL format.

Within geo range operator.

Types

filter()

@type filter() :: map()

operator()

@type operator() :: atom()

path()

@type path() :: String.t() | [String.t()]

value()

@type value() :: any()

Functions

all_of(filters)

@spec all_of([filter()]) :: filter()

Combine filters with AND logic.

All filters must match for the result to be included.

Examples

Filter.all_of([
  Filter.equal("status", "published"),
  Filter.greater_than("views", 100)
])

any_of(filters)

@spec any_of([filter()]) :: filter()

Combine filters with OR logic.

At least one filter must match for the result to be included.

Examples

Filter.any_of([
  Filter.equal("status", "draft"),
  Filter.equal("status", "published")
])

by_creation_time(operator, datetime)

@spec by_creation_time(operator(), String.t()) :: filter()

Filter by object creation time.

Examples

Filter.by_creation_time(:greater_than, "2024-01-01T00:00:00Z")

by_id(operator, uuid)

@spec by_id(operator(), String.t()) :: filter()

Create a filter by ID.

Examples

Filter.by_id(:equal, "00000000-0000-0000-0000-000000000001")

by_property(property, operator, value)

@spec by_property(String.t(), operator(), value()) :: filter()

Create a filter by property with an operator.

Examples

Filter.by_property("status", :equal, "published")
Filter.by_property("views", :greater_than, 1000)

by_property_length(property, operator, value)

@spec by_property_length(String.t(), operator(), non_neg_integer()) :: filter()

Filter by property string or array length.

Use this to filter based on the length of text properties or the number of elements in array properties.

Arguments

  • property - Property name
  • operator - Comparison operator: :equal, :not_equal, :greater_than, :greater_or_equal, :less_than, :less_or_equal
  • value - Length value (non-negative integer)

Examples

# Title must be at least 10 characters
Filter.by_property_length("title", :greater_or_equal, 10)

# Tags array must have exactly 3 elements
Filter.by_property_length("tags", :equal, 3)

# Content must be less than 5000 characters
Filter.by_property_length("content", :less_than, 5000)

by_ref(ref_property, target_class, operator, value)

@spec by_ref(String.t(), String.t(), operator(), value()) :: filter()

Create a filter by reference property.

Examples

Filter.by_ref("hasAuthor", "Author", :equal, "John Doe")

by_ref_count(property, operator, count)

@spec by_ref_count(String.t(), operator(), integer()) :: filter()

Filter by reference count.

Examples

Filter.by_ref_count("hasAuthor", :greater_than, 0)

by_ref_multi_target(property, target_collection, target_property, operator, value)

@spec by_ref_multi_target(String.t(), String.t(), String.t(), operator(), value()) ::
  filter()

Create a filter for a multi-target reference property.

For reference properties that can point to multiple collections, this allows filtering by a specific target collection.

Arguments

  • property - Multi-target reference property name
  • target_collection - Specific target collection to filter
  • target_property - Property in the target collection
  • operator - Filter operator
  • value - Filter value

Examples

Filter.by_ref_multi_target("relatedTo", "Article", "title", :equal, "Test")
Filter.by_ref_multi_target("mentions", "Person", "verified", :equal, true)

by_ref_path(ref_path, property, operator, value)

@spec by_ref_path(WeaviateEx.Filter.RefPath.t(), String.t(), operator(), value()) ::
  filter()

Create a filter using a reference path.

This is a convenience wrapper around WeaviateEx.Filter.RefPath.

Examples

alias WeaviateEx.Filter.RefPath

path = RefPath.through("hasAuthor", "Author")
Filter.by_ref_path(path, "name", :equal, "John")

by_update_time(operator, datetime)

@spec by_update_time(operator(), String.t()) :: filter()

Filter by object update time.

Examples

Filter.by_update_time(:greater_than, "2024-01-01T00:00:00Z")

contains_all(property, values)

@spec contains_all(String.t(), [String.t()]) :: filter()

Contains all operator (array subset)

contains_any(property, values)

@spec contains_any(String.t(), [String.t()]) :: filter()

Contains any operator (array intersection)

contains_none(property, values)

@spec contains_none(String.t(), [String.t()]) :: filter()

Contains none operator (array contains none of the values).

Examples

Filter.contains_none("tags", ["draft", "archived"])

equal(property, value)

@spec equal(String.t(), value()) :: filter()

Equal operator

greater_or_equal(property, value)

@spec greater_or_equal(String.t(), number()) :: filter()

Greater than or equal operator

greater_than(property, value)

@spec greater_than(String.t(), number()) :: filter()

Greater than operator

len(property)

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

Create a length path for a property.

This wraps the property name in the len() function for length-based filtering.

Examples

Filter.len("description")
#=> "len(description)"

less_or_equal(property, value)

@spec less_or_equal(String.t(), number()) :: filter()

Less than or equal operator

less_than(property, value)

@spec less_than(String.t(), number()) :: filter()

Less than operator

like(property, pattern)

@spec like(String.t(), String.t()) :: filter()

Like operator (wildcard matching)

not_(filter)

@spec not_(filter()) :: filter()

Negate a filter.

Examples

Filter.not_(Filter.equal("archived", true))

not_equal(property, value)

@spec not_equal(String.t(), value()) :: filter()

Not equal operator

null?(property)

@spec null?(String.t()) :: filter()

Null check operator

to_graphql(filter)

@spec to_graphql(filter()) :: map()

Convert a filter to GraphQL format.

Examples

filter = Filter.equal("status", "published")
Filter.to_graphql(filter)
# => %{path: ["status"], operator: "Equal", valueText: "published"}

within_geo_range(property, arg, distance)

@spec within_geo_range(String.t(), {float(), float()}, float()) :: filter()

Within geo range operator.

Examples

Filter.within_geo_range("location", {40.7128, -74.0060}, 5000.0)