LiveFilter.Filter (LiveFilter v0.1.0)
View SourceRepresents an individual filter with field, operator, value, and type.
A Filter defines a single filtering condition that can be applied to data queries. Filters are typically collected into FilterGroups for complex filtering logic.
Fields
:field
- The field name to filter on (atom, e.g.,:title
,:status
):operator
- The comparison operator (atom, e.g.,:equals
,:contains
,:greater_than
):value
- The value to compare against (any type, depends on operator and field type):type
- The field type for proper value handling (atom, e.g.,:string
,:integer
,:date
)
Examples
# String contains filter
%Filter{
field: :title,
operator: :contains,
value: "elixir",
type: :string
}
# Integer comparison filter
%Filter{
field: :price,
operator: :greater_than,
value: 100,
type: :integer
}
# Date range filter
%Filter{
field: :created_at,
operator: :between,
value: {~D[2024-01-01], ~D[2024-12-31]},
type: :date
}
# Array membership filter
%Filter{
field: :tags,
operator: :contains_any,
value: ["urgent", "bug"],
type: :array
}
# Boolean filter
%Filter{
field: :is_active,
operator: :is_true,
value: nil, # Value ignored for boolean operators
type: :boolean
}
Supported Operators by Type
String Types (:string
, :text
)
:equals
,:not_equals
- Exact matching:contains
,:not_contains
- Substring search:starts_with
,:ends_with
- Prefix/suffix matching:is_empty
,:is_not_empty
- Null/empty checks
Numeric Types (:integer
, :float
)
:equals
,:not_equals
- Exact comparison:greater_than
,:less_than
- Numeric comparison:greater_than_or_equal
,:less_than_or_equal
- Inclusive comparison:between
- Range comparison (value should be{min, max}
tuple)
Date/Time Types (:date
, :datetime
, :utc_datetime
)
:equals
,:not_equals
- Exact date comparison:before
,:after
- Date comparison:on_or_before
,:on_or_after
- Inclusive date comparison:between
- Date range (value should be{start_date, end_date}
tuple)
Boolean Type (:boolean
)
:is_true
,:is_false
- Boolean value checks:is_empty
,:is_not_empty
- Null checks
Array Types (:array
, :multi_select
)
:contains_any
- Array overlap (PostgreSQL:&&
operator):contains_all
- Array contains (PostgreSQL:@>
operator):not_contains_any
- No array overlap:in
,:not_in
- Membership checks
Enum Types (:enum
)
:equals
,:not_equals
- Exact matching:in
,:not_in
- Multiple choice selection
Summary
Functions
Creates a new filter struct.
Types
Functions
Creates a new filter struct.
Parameters
attrs
- A map or keyword list of filter attributes
Examples
iex> Filter.new(%{field: :title, operator: :contains, value: "test", type: :string})
%Filter{field: :title, operator: :contains, value: "test", type: :string}
iex> Filter.new(field: :status, operator: :equals, value: "active", type: :enum)
%Filter{field: :status, operator: :equals, value: "active", type: :enum}