Skip to main content
This page demonstrates real-world filtering scenarios using the oper parameter and relation filtering capabilities.

Overview

The Rest Generic Class package provides powerful filtering through the oper parameter, supporting:
  • Simple equality and comparison operators
  • Complex AND/OR logic trees
  • Relation-based filtering
  • Date range queries
  • Full-text search patterns

Scenario 1: Basic Product Catalog Filter

Goal: Show active products in stock within a price range.

Scenario 2: Search by Name with Category Filter

Goal: Search for “keyboard” products in the Electronics category.
The like operator uses SQL LIKE syntax. Use % as a wildcard for partial matches. For case-insensitive searches, your database collation determines behavior.

Scenario 3: Complex OR Logic - Clearance or New Arrivals

Goal: Show products that are either on clearance (low stock) or newly added.

Scenario 4: Multi-Category Filter

Goal: Show products from multiple categories using IN operator.

Date Range Queries

Scenario 5: Products Created This Month

Goal: List all products added in the current month.

Scenario 6: Recently Updated Products

Goal: Find products updated in the last 7 days.

Scenario 7: Seasonal Product Filter

Goal: Show products relevant to a specific season with date-based logic.

Relation-Based Filtering

Scenario 8: Filter by Nested Relation

Goal: Find products with highly-rated reviews (rating >= 4).
Set _nested: true to apply relation filters to both the query and the eager-loaded relations. Without this flag, relation filters only affect the main query (existence check).

Scenario 9: Filter by Category and Subcategory

Goal: Show products from Electronics category where subcategory is “Accessories”.

Scenario 10: Products with Tags

Goal: Find products tagged with specific keywords (many-to-many relation).

Multi-Condition Complex Filters

Scenario 11: Advanced Search with All Features

Goal: Comprehensive search combining text, price, date, stock, and relations.

Scenario 12: Exclude Specific Items

Goal: Show all products except specific excluded IDs and categories.

Scenario 13: Null/Not Null Checks

Goal: Find products with or without a description.

Performance Optimization Tips

1

Use Select to Limit Columns

Only fetch the columns you need:
2

Add Database Indexes

Index frequently filtered columns:
3

Enable Caching for Repeated Queries

4

Limit Relation Depth

Avoid loading too many nested relations:

Supported Operators

All operators are validated against the package’s allowlist. Custom operators can be added via configuration if needed.

Common Mistakes

Forgetting to add relations to RELATIONS constant
Unlisted relations will return a 400 error.
Exceeding filter limitsThe package enforces filtering.max_conditions (default: 100) to prevent database overload. Split large filters into multiple requests.
Invalid operator syntaxUse pipe separators: field|operator|value❌ Wrong: "price > 100"✅ Correct: "price|>|100"

Next Steps