Personalizing Search Experiences with Blueprints
As we saw in the previous lesson, using search facets is great in providing visitors a way to quickly filter search results. However, Clarity has some search use cases that they wish to further customize and personalize. Liferay’s Search Blueprints provide the necessary tools to meet Clarity’s customization needs.
Use Blueprints to define implicit search criteria that can be added to any user’s search query to help enhance the search experience. Blueprints offers a UI-based configuration experience where search criteria is set by dragging and dropping elements. Use Blueprints to boost, filter, or even hide specific search results. Apply a different Blueprint to each search results page, or leverage your Blueprints with headless APIs.
Complete the following exercises to better understand the capabilities of Search Blueprints.
Exercise: Customizing Search Results with Search Blueprints
Here you’ll revisit the Open Positions results page and create a Search Blueprint to only return recent job listing articles as the Clarity Admin user.
To do this,
-
Sign in as the Clarity Admin user.
- Username:
admin@clarityvisionsolutions.com
- Password:
learn
- Username:
-
Open the Site Menu (), expand Content and Data, and select Web Content.
-
Click on the Structures tab and click Job Listing. In the very right, click the Properties () icon. Take note of the Structure Key ID (i.e. 34060).
-
Open the Global Menu (), navigate to Applications → Blueprints.
-
Click the add button to add a new search blueprint. Enter
Job Listings Last 60 Days
as the title and click Create. -
In the right menu of query elements, expand the FILTER section and find the Filter by Exact Terms Match element. Click Add for the element.
-
In the Field field, enter
ddmStructureKey
. In the Values field, enter the Structure Key ID of the job listing web content structure (e.g. 34060). -
In the left navigation, click Query Settings.
-
Click Selected Types and click Select Asset Types.
-
Select Web Content Article and click Done.
-
In the top menu, click Preview to preview the Search Blueprint in action. For example, search for the term
Developer
to see developer related results. -
Click Add () to add another query element above the first one.
-
Expand the CUSTOM section and find the Custom JSON Element element. Click Add for the element.
-
From the training workspace, go to the
[repository-folder]/exercises/lesson-18/
folder and open thefilter-last-60d.json
file on your machine. -
Replace the sample code in the JSON Text Area with the data from the file.
-
In the top menu, click Preview to preview the Search Blueprint in action. For example, search for the term
Developer
to see developer related results. In the custom JSON element try editing the logic by changingnow-60d
tonow-1d
. Try another preview search. -
Change the JSON element back to
now-60d
. Click Save.
Edit the Open Positions Page to use the search blueprints.
-
Navigate to the Open Positions page (i.e. Careers → Open Positions). In the top menubar, click the edit page () icon.
-
From the Fragments and Widgets menu, drag and drop a Blueprints Options widget to the bottom of the page below the Search Options widget.
-
Click the Actions menu () and select Configuration. Click Select to choose a search blueprint.
-
Click Select for the Job Listings Last 60 Days blueprint. Click Save and close the window.
-
Note, we can now remove the search Type Facet widget that filters for web content articles. The search Custom Filter widget that filters for job listing web content can also be removed.
-
Click Publish. The search results now only show job listings that were created in the last 60 days.
Great! You’ve created two search blueprints and applied them in the Open Positions page as an alternative to the Custom Filter widget you added in a previous exercise.
Next, you’ll learn how to use search blueprints with collection providers.
Exercise: Dynamic Collections with Search Blueprints
One simple way to leverage search blueprints is with collection providers. Every time you create a search blueprint, a collection provider is automatically generated. Then, showing the results of the search blueprint is as easy as adding a collection display widget onto a site page. For example, Clarity wants to have a site page that automatically displays a list of upcoming events. A search blueprint can query upcoming events on their calendar to automatically fetch these upcoming events. While logged in as the Clarity Admin user, follow these steps to see how this works.
-
Create a site page with a calendar widget.
-
From the Site Menu (), navigate to Site Builder → Pages.
-
Click New and select Page.
-
Select Primary Master Page.
-
Enter Calendar as the name and click Add.
-
Select Fragments and Widgets in the left menu and select the Widgets tab. Scroll down to the Collaboration section and drag a Calendar widget onto the page. Click Publish.
-
In the list of site pages, find the calendar page you just created, click the options icon and select View.
-
Select the Month view and click on any date that is before your current date and enter
Past Event 1
as the name and click Save. -
Click on any date that is after your current date and enter
Future Event 1
as the name and click Save. -
Add one more event after Future Event 1 and enter
Future Event 2
as the name and click Save.
-
-
Enable the Collections with Search Blueprints feature flag.
-
Open the Global Menu (), navigate to Control Panel → Instance Settings.
-
Click Feature Flags and select Beta in the left navigation. Enable
Collections with Search Blueprints (LPS-129412)
.
-
-
Create a future events Search Blueprints Element.
-
From the Global Menu, navigate to Applications → Blueprints.
-
Click on the Elements tab and click Add.
-
Enter Future Events as the title and click Create.
-
From the training workspace, go to the
[repository-folder]/exercises/lesson-18/
folder and open thefilter-future-events.json
file on your machine. -
Replace the sample JSON with the data from the file.
-
Click Save.
-
-
Create a future events Search Blueprint.
-
Still in the search blueprints application, click on the Blueprints tab.
-
Click Add to create a new blueprint. Enter Future Events as the name and click Create.
-
In the right menu of query elements, expand the FILTER section and find the Future Events element you created in the previous step. Click Add for the element.
-
In the left navigation, click Query Settings. Change the searchable type to Selected Types. Click Select Asset Types and check Calendar Event and click Done.
-
Click Save for the blueprint.
-
-
Create a future events site page with a collection provider.
-
From the Site Menu (), navigate to Site Builder → Pages.
-
Click New and select Page.
-
Select Primary Master Page.
-
Enter Future Events as the name and click Add.
-
Select Fragments and Widgets in the left menu and select the Fragments tab. In the search bar, search for
collection
and find the Collection Display fragment. Drag the fragment onto the page. -
Click on the Collection Display fragment you just added. In the configuration menu on the right, click Select Collection ().
-
In the new window select the Collection Providers tab. Select the Future Events collection provider.
-
Under style display, select Bulleted List.
-
Click Publish.
The search blueprint automatically provides a collection of future events.
-
You now have created and configured a search blueprint that uses a collection provider to display future calendar events.
Next, you’ll learn how to leverage search blueprints with custom fields, then query the fields in Liferay’s headless APIs.
Exercise: Search Blueprints with Custom Fields
Occasionally businesses need to integrate with other web services. For example, the employee benefits system Clarity utilizes wants to reference Clarity employees based on the registration ID numbers the service uses. In Liferay, a custom field can be added to user accounts to add this additional field. Then Liferay’s headless APIs can be used to query this custom field. While logged in as the Clarity Admin user, follow the steps below to see this in action.
Note: The user account headless APIs cannot filter for custom fields directly. Therefore, a search blueprint is leveraged to be able to query for this custom field.
-
From the Global Menu, go to Control Panel → Custom Fields.
-
Select User and click New to begin creating a custom field.
-
Select Input Field and enter these details.
Field Value Field Name RegistrationId
Data Type Integer -
Click Save.
-
From the Global Menu, go to Control Panel → Users & Organizations.
-
Select Ian Miller, scroll down to the bottom, and enter
555777
for the registration ID. -
Click Save.
-
From the Global Menu, navigate to Applications → Blueprints.
-
Click Add () to begin creating a search blueprint.
-
For title, enter
RegistrationId
and click Create. -
In the right menu of query elements, expand the FILTER section, find the Filter by Exact Terms Match element, and click Add for the element.
-
Enter these values:
Field Value Field expando__keyword__custom_fields__RegistrationId_long
Values ${keywords}
-
Click Save and take note of ID number of the search blueprint (e.g.
32256
). -
In the Global Menu, navigate to Control Panel → Instance Settings.
-
Click Feature Flags and go to Beta in the left navigation.
-
Scroll down and enable
Search Headless API (LPS-179669)
.Note: Beta features are not recommended for production use, but this feature will be available as a full feature Q3 2024.
-
Use a new browser window and access Liferay’s API Explorer at
http://localhost:8080/o/api
. -
Click the REST Applications drop-down menu and select portal-search-rest/v1.0.
-
Expand the postSearchPage endpoint panel and scroll down to the Request Body section.
-
From the downloaded course bundle, navigate to the
[repository-folder]/exercises/lesson-18/
folder, then open theapi-post-search.json
file. -
Copy the data from the file and paste it into the Request Body field.
-
Replace
{blueprint ID}
with the ID number of your search blueprint. -
For nestedFields, enter
embedded
. -
For search, enter
555777
. -
Click Execute.
-
Verify this returns Ian Miller’s user information.
In this way, Liferay can be set up as a headless system that can be utilized by a third-party service.
You’ve used a custom registration ID field with search blueprints to retrieve user information.
Conclusion
Congratulations! You’ve completed Module 9 - Search. Throughout this module, you learned about working with the various tools and features Liferay Search offers.
In the next module, you’ll learn how you can use Liferay Objects to customize Liferay DXP.
Up Next: Module 10 - Customizing Liferay DXP
Additional Resources
See official documentation to learn more about using search blueprints to tailor search experiences: