Search
search framework for custom routines and generated codeA comprehensive search system that provides full-text search capabilities across your application’s data. The search component includes a user-friendly search bar interface and a powerful backend search engine that can index and search through various data types.
- Programmable Search: Search across multiple fields and data types using your own code
- Configurable: Enable/disable search on specific pages
- Performance Optimized: Efficient indexing and querying
- Type-Safe: Go-based search definitions with proper typing
- Export Integration: Automatic search generation for exported models
Prerequisites
The search functionality requires the search module to be enabled in your Project Forge application. If you’re using model exports, the export module should also be enabled for automatic search function generation.
Basic Usage
Enabling Search
Search is automatically included in your pages when the search module is enabled. The search bar appears in the standard page layout.
Disabling Search on Specific Pages
To disable the search bar on specific pages, set the SearchPath to "-" in your controller action:
1 | |
Custom Search Path
You can customize where search results are handled by setting a custom search path:
1 | |
Search Engine Architecture
The search system is built around the components in /app/lib/search:
Core Components
- Search Interface: Defines the contract for search operations
- Result Types: Structured result objects for different content types
- Indexing: Content indexing for efficient searching
- Query Processing: Search query parsing and execution
Search Types
The search system defines several types for handling search operations:
1 | |
Model-Based Search
Automatic Search Generation
When the export module is enabled and models have search = true configured, search functions are automatically generated in app/lib/search/generated.go.
Model Configuration
1 | |
Generated Search Functions
The system automatically generates search functions like:
1 | |
Custom Search Implementation
You can also implement custom search functions for specific needs:
1 | |
Search Interface Implementation
Search Handler
1 | |
Search Results Template
1 | |
Advanced Search Features
Filtered Search
1 | |
Search with Autocomplete
1 | |
Search Analytics
1 | |
Best Practices
Performance Optimization
- Indexing: Create appropriate database indexes for searchable fields
- Caching: Cache frequent search results
- Pagination: Implement pagination for large result sets
- Query Optimization: Use efficient SQL queries with proper LIMIT/OFFSET
User Experience
- Fast Response: Keep search response times under 200ms when possible
- Relevant Results: Order results by relevance and recency
- Clear Feedback: Show search progress and result counts
- Error Handling: Provide helpful messages for failed searches
Search Quality
- Fuzzy Matching: Handle typos and similar terms
- Stemming: Match word variations (run, running, ran)
- Synonyms: Include related terms in search results
- Stop Words: Filter out common words that don’t add value
Security
- Input Sanitization: Clean search queries to prevent injection attacks
- Rate Limiting: Prevent search abuse with rate limiting
- Access Control: Respect user permissions in search results
- Logging: Log search activities for security monitoring
Common Use Cases
Content Management
- Search through articles, pages, and media
- Find content by title, tags, or full text
- Filter by publication status or date
E-commerce
- Product search by name, description, or SKU
- Filter by category, price range, or availability
- Search customer orders and information
User Management
- Find users by name, email, or role
- Search user-generated content
- Administrative user lookup
Documentation
- Search help articles and documentation
- Find API endpoints or code examples
- Search through comments and discussions
Troubleshooting
Search Not Appearing
- Verify the
searchmodule is enabled - Check that
ps.SearchPathis not set to"-" - Ensure search templates are properly included
Poor Search Results
- Review database indexes on searchable fields
- Check search query logic and scoring
- Verify data is properly indexed
Performance Issues
- Add database indexes for search queries
- Implement result caching
- Consider using dedicated search engines (Elasticsearch, etc.)
Integration Problems
- Ensure
exportmodule is enabled for model search - Check that models have
search = trueconfigured - Verify generated search functions are properly wired