WeaviateEx.Filter.RefPath (WeaviateEx v0.7.4)

View Source

Fluent API for building deep reference path filters.

Allows filtering through chains of references to reach nested properties. This enables complex filtering scenarios where you need to filter based on properties of objects that are multiple reference hops away.

Examples

# Filter articles where the author's company is in technology
RefPath.through("hasAuthor", "Author")
|> RefPath.through("worksAt", "Company")
|> RefPath.property("industry", :equal, "Technology")

# Filter by author name
RefPath.through("hasAuthor", "Author")
|> RefPath.property("name", :like, "John*")

# Use with Filter combinators
Filter.all_of([
  RefPath.through("hasAuthor", "Author")
  |> RefPath.property("verified", :equal, true),
  Filter.equal("status", "published")
])

Summary

Functions

Build the full path list from segments.

Get the number of hops in the reference path.

Terminate the path with a property filter.

Start a reference path with the first reference.

Continue a reference path with another reference hop.

Get the path without a final property.

Types

segment()

@type segment() :: {String.t(), String.t()}

t()

@type t() :: %WeaviateEx.Filter.RefPath{segments: [segment()]}

Functions

build_path(segments, final_property)

@spec build_path([segment()], String.t()) :: [String.t()]

Build the full path list from segments.

Examples

segments = [{"hasAuthor", "Author"}, {"worksAt", "Company"}]
RefPath.build_path(segments, "name")
#=> ["hasAuthor", "Author", "worksAt", "Company", "name"]

depth(ref_path)

@spec depth(t()) :: non_neg_integer()

Get the number of hops in the reference path.

Examples

RefPath.through("hasAuthor", "Author")
|> RefPath.through("worksAt", "Company")
|> RefPath.depth()
#=> 2

property(ref_path, property, operator, value)

@spec property(t(), String.t(), atom(), term()) :: map()

Terminate the path with a property filter.

Creates a filter that can be used with WeaviateEx.Filter combinators.

Arguments

  • ref_path - The reference path built with through/2
  • property - Final property name to filter on
  • operator - Filter operator (:equal, :greater_than, etc.)
  • value - Filter value

Examples

RefPath.through("hasAuthor", "Author")
|> RefPath.property("name", :equal, "John")

RefPath.through("hasAuthor", "Author")
|> RefPath.through("worksAt", "Company")
|> RefPath.property("industry", :equal, "Technology")

through(property, target_collection)

@spec through(String.t(), String.t()) :: t()

Start a reference path with the first reference.

Arguments

  • property - Reference property name
  • target_collection - Target collection name

Examples

RefPath.through("hasAuthor", "Author")

through(ref_path, property, target_collection)

@spec through(t(), String.t(), String.t()) :: t()

Continue a reference path with another reference hop.

Arguments

  • ref_path - Existing reference path
  • property - Reference property name
  • target_collection - Target collection name

Examples

RefPath.through("hasAuthor", "Author")
|> RefPath.through("worksAt", "Company")

to_path(ref_path)

@spec to_path(t()) :: [String.t()]

Get the path without a final property.

Useful for reference count filters or other operations that don't need a final property.

Examples

path = RefPath.through("hasAuthor", "Author")
RefPath.to_path(path)
#=> ["hasAuthor", "Author"]