Leveraging Search APIs
Liferay's search APIs empower developers to create robust and intuitive search experiences. Leveraging Liferay’s advanced search framework, these APIs enable comprehensive querying, filtering, and dynamic content suggestions. This article explores how to leverage these APIs effectively for data retrieval.
Understanding Search and Search Suggestions APIs
Search APIs provide powerful tools to query and manage content programmatically, enabling precise and scalable search experiences. Its parameters filter, sort, and structure search results effectively. In addition to the generic parameters described previously in Querying Liferay Data Efficiently, search APIs also include these parameters:
entryClassNames
: A comma-separated list of entry class names to search. This defaults to all searchable types.scope
: A list of sites (by ID or ERC) to search. You can mix IDs and ERCs in the same request.
Unlike GET methods, search APIs use HTTP POST and support additional configurations and attributes within request bodies:
attributes
: Configure search blueprints or enable empty searches. See Available Search Request Attributes for available options.facetConfiguration
: Customize facet aggregations for grouping results dynamically. See Adding Facet Configurations to the Request for more information.
The suggestions API enhances search API requests by providing real-time predictions based on user input. These suggestions enhance user experiences, dynamically guiding users toward relevant content. Both basic and sxpBlueprint contributors create suggestions, integral for intuitive search bars and improved content discoverability.
See Search Suggestions API for query parameters, request body configuration options, and other information.
Using Search APIs Effectively
Search APIs provide powerful mechanisms for consuming data. These are some strategies for crafting effective queries:
- Enable Facets for Navigation: Facilitate better UX by grouping results into logical categories using search API facets.
- Leverage Pagination: Use
page
andpageSize
to handle large datasets in smaller chunks, improving performance. - Optimize Payload Size: Use
fields
orrestrictFields
to fetch only the necessary data, reducing response time and bandwidth usage. - Prioritize Performance: Combine
page
,fields
, andrestrictFields
with query parameters to ensure efficient payloads and responsive interactions. - Leverage Blueprints: Apply search blueprints across both APIs to maintain consistent logic and result rankings.
- Combine Search and Filter: Use both
search
andfilter
parameters to return relevant data while minimizing client-side processing, leveragingsearch
overfilter
when possible to improve performance. - Strategically Implement Suggestions Contributors: Use
basic
for simple suggestions aligning with Liferay’s default search indexer. UsesxpBlueprint
for advanced customization such as ranking or boosting specific terms. - Optimize Query Parameters: Always provide
currentURL
anddestinationFriendlyURL
for context-aware suggestions. Limit suggestions withsize
to avoid overwhelming the user with too many results.
Ideally, pair search suggestions API usage with the search API. This creates cohesive experiences with real-time suggestions reinforced by comprehensive search API query results. Following these best practices, you can create seamless integrations that enhance both usability and performance.
Search or GET: Which One To Use and When
Both the search APIs and GET methods serve the same purpose: retrieving data. Each approach shares common functionalities including filtering results, specifying returned fields, and performing keyword searches. Though you can use both methods together, understanding the key differences between GET and search API requests is crucial.
When choosing between a GET or search API approach, consider these factors:
- Underlying System: GET requests query either the database or search engine depending on the component implementation, while search APIs ensure optimized performance for heavy queries by always using the search engine.
- Data Scope: GET requests retrieve single entity types, such as a specific object or blog entry, while search APIs support multi-entity searches with mixed content types.
- Advanced Search Features: GET requests are designed for straightforward data retrieval, while search APIs provide access to search-specific features such as synonyms and result ranking.
Using a GET Approach
GET methods are particularly useful for cases where data retrieval aligns closely with the entity's structure and no complex ranking or aggregation is needed. Use GET methods when you’re only retrieving a single entity type, advanced search features are not required, or if the data required is not present in fields indexed on the search engine.
Using a Search API Approach
Search APIs excel in scenarios requiring complex filtering, ranking, or aggregation, and pairs well with search blueprints. Use these APIs if querying multiple entity types, leveraging advanced search-related features, or ensuring high performance.
Applying Search APIs to Clarity’s Use Case
Clarity plans to leverage Liferay's search and search suggestions APIs with GET requests to enhance their dashboards. Search API requests enable users to rapidly filter and sort through extensive data, ensuring quick access to essential information.
For example, support agents can quickly retrieve high-priority tickets from specific regions within consolidated views, with paginated data delivery maintaining high performance. The search API also facilitates unified searches for tickets, applications, and articles. It leverages synonyms for accuracy, queries multiple entities, and ranks results by relevance. GET methods can efficiently retrieve open customer tickets by filtering with status=open
, due to the single entity type (tickets).
Furthermore, Clarity can integrate search blueprints to implement advanced search suggestions, such as role-based suggestions and term boosting (e.g., 'urgent', ‘critical’). These capabilities ensure relevant results and suggestions, optimizing both efficiency and user satisfaction.
Conclusion
Liferay’s search APIs provide flexibility and scalability to build modern, intuitive search experiences. These capabilities enable refined searches tailored to diverse business needs using a low-code approach. Choosing the right data retrieval approach, whether with GET or search APIs, significantly impacts efficiency and effectiveness.
Next, you’ll practice retrieving product information using search APIs.
Capabilities
Product
Education
Contact Us