Retrieving Clarity's Product Data with Search APIs
Liferay’s search APIs provide tools enabling precise and scalable search experiences. Clarity’s team previously tested retrieving product data using GET requests and GraphQL queries. Next, they want to expand their toolset by testing with search APIs to filter, sort, and structure search results. In these exercises, you’ll execute search API requests to return results and suggestions.
Exercise: Retrieving Clarity’s Product Information with the Search API
Here, you'll use the search API to find, filter, and paginate product information.
-
Sign in as the Clarity Admin user.
-
Username:
admin@clarityvisionsolutions.com
-
Password:
learn
-
-
Navigate to the API Explorer at http://localhost:8080/o/api.
-
Click on the REST Application drop-down and select
search/v1.0
. -
Under the SearchResult section, expand the
postSearchPage
endpoint. -
Set
com.liferay.commerce.product.model.CPDefinition
for theentryClassNames
parameter. -
Replace the sample code in the Request body with this code snippet:
-
Click Execute.
-
Examine the response body to verify it retrieved 11 entries. At the bottom, you should see:
-
Scroll up, enter
sunglasses lenses
in thesearch
parameter. -
Click Execute.
The response body should now include six items: -
Set the following values for the respective parameters:
Parameter Value page 2 pageSize 5
-
Click Execute.
There should be six products matching the search, meaning the second page will contain only one item. Here’s what you’ll find in the response body:
This approach executes the search using the underlying search engine, optimizing performance by leveraging the engine’s indexed results.
Exercise: Extending Clarity’s Search Results with Suggestions
Here, you'll use the search suggestions API to retrieve suggestions as a user starts typing “sunglasses.”
-
While viewing the search endpoints in the API explorer, expand the
postSuggestionsPage
endpoint.
-
Set the following values for the respective parameters:
Parameter Value currentURL /search destinationFriendlyURL /search plid 1 search sun -
Input the following code to the Request body:
-
Click Execute.
-
Examine the response body to verify it includes exactly five suggestions, providing a headless payload mirroring the UI’s search bar suggestions.
Conclusion
Great! You’ve successfully leveraged Liferay’s search APIs to retrieve and filter search results. Harnessing these APIs provides Clarity’s foundation for enhancing dashboards to rapidly filter and sort through extensive data.
Next, you'll review what you've learned before moving on to the next module.
Capabilities
Product
Education
Contact Us