Search and Faceting Optimization Summary
This document summarizes the comprehensive search and faceting optimizations implemented for the OpenRegister application. These optimizations significantly improve search performance by leveraging database indexes, implementing intelligent caching strategies, and optimizing query execution paths.
Key Optimizations Implemented
1. Database Index Optimization
Migration: lib/Migration/Version1Date20250102120000.php
Added critical indexes for search performance:
Single-Column Search Indexes
objects_name_search_idx- Index onnamecolumnobjects_summary_search_idx- Index onsummarycolumnobjects_description_search_idx- Index ondescriptioncolumn
Composite Search Indexes
objects_name_deleted_published_idx- Combined search + lifecycle filteringobjects_summary_deleted_published_idx- Summary search + lifecycle filteringobjects_description_deleted_published_idx- Description search + lifecycle filteringobjects_name_register_schema_idx- Name search + register/schema filteringobjects_summary_register_schema_idx- Summary search + register/schema filteringobjects_name_organisation_deleted_idx- Name search + multi-tenancy filteringobjects_summary_organisation_deleted_idx- Summary search + multi-tenancy filtering
Performance Impact: These indexes enable fast lookup on frequently searched metadata columns, reducing query times from seconds to milliseconds.
2. Schema Caching System
Handler: lib/Service/Schemas/SchemaCacheHandler.php
Implemented comprehensive schema caching with:
Features
- In-memory caching for frequently accessed schemas
- Database-backed cache with configurable TTL
- Batch schema loading for multiple schemas
- Automatic cache invalidation when schemas are updated
- Cache statistics and monitoring
Performance Benefits
- Eliminates repeated database queries for schema loading
- Reduces schema processing overhead
- Enables predictable performance for schema-dependent operations
- Supports high-concurrency scenarios
3. Schema-Based Facet Caching
Service: lib/Service/SchemaFacetCacheService.php
Implemented predictable facet caching based on schema definitions:
Key Concepts
- Predictable facets: Facets are determined by schema properties
- Schema-based invalidation: Cache invalidated when schemas change
- Multiple facet types: Support for terms, date_histogram, and range facets
- Facetable field discovery: Automatic detection of facetable properties
Caching Strategy
- Facet configurations cached per schema
- Facet results cached with configurable TTL
- Automatic cleanup of expired cache entries
- Memory + database dual-layer caching
4. Optimized Search Query Execution
Handler: lib/Db/ObjectHandlers/MariaDbSearchHandler.php
Enhanced search performance with prioritized search strategy:
Search Priority Order
-
PRIORITY 1: Indexed metadata columns (name, summary, description)
- Fastest performance using database indexes
- Direct column access with LOWER() function
-
PRIORITY 2: Other metadata fields (image, etc.)
- Moderate performance with direct column access
- No indexes but faster than JSON search
-
PRIORITY 3: JSON object search
- Comprehensive fallback using JSON_SEARCH()
- Slowest but ensures complete search coverage
Performance Impact
- Dramatic improvement in search response times
- Leverages database indexes for common searches
- Maintains comprehensive search coverage
5. Cache Table Structure
Added two new cache tables:
openregister_schema_cache
- Stores cached schema objects and computed properties
- Supports TTL-based expiration
- Indexed for fast schema lookup
openregister_schema_facet_cache
- Stores cached facet configurations and results
- Supports different facet types
- Indexed by schema and facet configuration
Integration Points
Service Registration
Updated lib/AppInfo/Application.php to register new cache handlers:
SchemaCacheHandler- Schema caching and managementFacetCacheHandler- Facet caching and discovery
Event-Driven Cache Invalidation
The cache services are designed to integrate with existing event systems:
- Schema update events trigger cache invalidation
- Automatic cleanup of expired cache entries
- Statistics and monitoring support