This is the official documentation of Forest Admin Cloud.
To improve your admin panel's search functionality, consider overriding the default search system with more efficient technologies. Options like PostgreSQL's tsquery and tsvector, Algolia, or Elasticsearch provide advanced search capabilities and faster query responses. These tools can significantly improve your app's search results and performance.
The following sections assume that you have correctly followed all the steps in the guide.
To make the code easier to read, all the code snippets below should be wrapped in the following code. Ensure you update the collection name as needed.
import type { Agent } from '@forestadmin/forest-cloud';
import { Schema } from '../typings';
export default function customizeAgent(agent: Agent<Schema>) {
agent.customizeCollection('users', collection =>
// Insert the code snippet here.
);
}
Extending the default search engine
To modify your collection's default search behavior, use the replaceSearch() function. This function provides access to the default search logic through the context argument.
excludedFields*[String]: Remove the fields to the default search engine.
extended*Boolean: When activated, extended search also includes direct relationships.
includeFields*[String]: Add the fields to the default search engine.
The generateSearchFilter() function returns an object containing the set of rules for searching. You can adjust these rules to better fit your needs or to make your searches more efficient.
Searching on specific columns based on user input format
To improve the default search functionality, this example below differentiates between a product reference (e.g., bcdaefCFABDEdfEF) and a barcode value (e.g., 9876543210) using regex. This enables the search to target the appropriate field based on the input type.
When your data is stored and organized in a cloud-based service, another storage system, or a service specifically for searching through text, you can opt to use these instead of the default search engine.