Skip to content

Conversation

@ginkelsoft-development
Copy link
Owner

This feature enables efficient searching across multiple fields in a single database query, significantly improving performance for complex search scenarios.

New Scopes Added:

  1. encryptedSearchAny() - OR logic across multiple fields

    • Searches same term in multiple fields
    • Returns models where ANY field matches
    • Example: Client::encryptedSearchAny(['first_names', 'last_names'], 'John', 'exact')
  2. encryptedSearchAll() - AND logic with field-specific terms

    • Searches different terms in different fields
    • Returns models where ALL fields match their respective terms
    • Example: Client::encryptedSearchAll(['first_names' => 'John', 'last_names' => 'Doe'], 'exact')

Benefits:

  • Single database query instead of multiple individual queries
  • Reduced database round-trips
  • Lower memory footprint
  • Better performance at scale
  • Supports both exact and prefix search types
  • Works with both database and Elasticsearch backends

Test Coverage:

  • Added 13 comprehensive tests (BatchQueryTest.php)
  • Tests cover OR/AND logic, edge cases, empty inputs
  • Performance comparison test validates optimization
  • Tests confirm minimum prefix length compliance
  • All 89 tests passing (161 assertions)

This addresses performance optimization requirement #1: batch queries for multiple fields in complex search scenarios.

This feature enables efficient searching across multiple fields in a
single database query, significantly improving performance for complex
search scenarios.

New Scopes Added:
1. encryptedSearchAny() - OR logic across multiple fields
   - Searches same term in multiple fields
   - Returns models where ANY field matches
   - Example: Client::encryptedSearchAny(['first_names', 'last_names'], 'John', 'exact')

2. encryptedSearchAll() - AND logic with field-specific terms
   - Searches different terms in different fields
   - Returns models where ALL fields match their respective terms
   - Example: Client::encryptedSearchAll(['first_names' => 'John', 'last_names' => 'Doe'], 'exact')

Benefits:
- Single database query instead of multiple individual queries
- Reduced database round-trips
- Lower memory footprint
- Better performance at scale
- Supports both exact and prefix search types
- Works with both database and Elasticsearch backends

Test Coverage:
- Added 13 comprehensive tests (BatchQueryTest.php)
- Tests cover OR/AND logic, edge cases, empty inputs
- Performance comparison test validates optimization
- Tests confirm minimum prefix length compliance
- All 89 tests passing (161 assertions)

This addresses performance optimization requirement #1:
batch queries for multiple fields in complex search scenarios.
@ginkelsoft-development ginkelsoft-development merged commit d60fb22 into develop Oct 13, 2025
4 of 8 checks passed
ginkelsoft-development added a commit that referenced this pull request Oct 14, 2025
…y-optimization

add batch query optimization for multiple fields
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants