AmberDB

 view release on metacpan or  search on metacpan

docs/EN.AmberDB_User-Guide.md  view on Meta::CPAN

        { blk => 4, id => "price",    label => "Price Range" },
        
        # Free-Text Attributes (Color, Size, etc.):
        { blk => 6, id => "color",    label => "Color" },
    ],
}
```

### 16.3 Usage & Practical Examples

#### A. Building Category Sidebar Menus
Generate complete filter groups and matching product counts in a single method call:

```perl
# User selections from URL query string: Category 5, Brand 12 or 14 selected
my %selected_filters = ( 1 => "5", 2 => ["12", "14"] );

my $menu = $adb->facet_menu(
    "catalog_attributes",
    \%selected_filters,
    $table_info->{facet_block},

lib/AmberDB/Base/Facet.pm  view on Meta::CPAN

    # 1. Active Filtering (Filtered IDs)
    my ( $total_count, $filtered_ids, $all_filtered_ids ) = $self->_facet_filter_ids(
        $tableid, $active_filter, $base_scope, $opts->{offset} // 0, $opts->{limit} // 0, $fac_path, $index_path
    );

    # 2. Compute Facet Counts (Disjunctive / Multi-pass Optimized)
    my $all_counts = $self->_facet_calc_counts(
        $tableid, $facet_defs, $active_filter, $base_scope, $all_filtered_ids, $fac_path, $unq_path
    );

    # 3. Build Menu Groups, Whitelist & Batch Label Resolution (.unq / RDBM)
    my ( $groups, $groups_by_blk, $active_counts ) = $self->_facet_build_groups(
        $tableid, $table_info, $facet_defs, $all_counts, $active_filter, $table_path
    );

    my $res = {
        count         => $total_count,
        ids           => $filtered_ids,
        groups        => $groups,
        groups_by_blk => $groups_by_blk,
        active_counts => $active_counts,

t/amberdb_ecommerce_facet.t  view on Meta::CPAN

    [ 5, 2, 20, 100, 'Nutuk',                  'Ciltli', 1, 250.00 ],
    [ 6, 2, 20, 100, 'Geometri',               'Karton', 1, 75.00 ],
    [ 7, 3, 30, 300, 'Dune',                   'Ciltli', 1, 280.00 ],
    [ 8, 3, 30, 300, 'Dune Mesihi',            'Karton', 1, 160.00 ],
    [ 9, 3, 30, 300, 'Dune Çocukları (Pasif)', 'Karton', 0, 140.00 ], # JUNK / Inactive
);

$adb->insert_list( 'catalog_product', @products );

# ---------------------------------------------------------------------------
subtest '1. Initial Unfiltered Facet Menu & Label Resolution' => sub {
    plan tests => 8;

    my $menu = $adb->facet_menu(
        'catalog_product',
        {}, # No filter selected
        $adb->table_attr('catalog_product', 'facet_block'),
        { sort => 'count' }
    );

    ok( $menu, "Facet menu generated successfully" );



( run in 2.424 seconds using v1.01-cache-2.11-cpan-60884a8df76 )