Liferay Search Blueprint: Improving the Search Experience

 


A Search Blueprint is a design plan for Liferay’s search behavior. The search experience starts at a Search Bar for most users. When a search term is entered, a complex query is constructed by Liferay’s search infrastructure, then sent to the search engine. You can see Liferay’s complete query using the Search Insights widget. This query can be thought of as Liferay’s default blueprint for the search page, controlling what is searched and how. 

This document/blog will provide a comprehensive guide to Liferay Search Blueprint. We will cover the following topics:

  • How does search work in Liferay?
  • How to create a Liferay Search Blueprint.
  • What Can I Do in the Blueprints UI?
  • Advanced: Configuring Query Clause Contributors
  • Search Blueprints Configuration Reference.
  • How to apply search blueprint into search page.
  • Search Blueprint use case. 

How does search work in Liferay?

Search Request: Liferay sends a search request to Elasticsearch, which can include the query body and additional parameters that help direct the response returned by Elasticsearch.

QueryThe query body instructs the search in how to determine if matching content is found in the index. For example, what kind of query should be used when searching indexed content containing a title field? And if it matches the title field, should the score be boosted? 

Clause: A clause is a self-contained portion of the main bool query. Most often one of the more nested queries is what’s referred to when the word clause is invoked. 

What Can I Do in the Blueprints UI?

Create an element-based Blueprint, then apply it to the page to create a search solution. The features available for doing so include:



Blueprints are made up of Elements with some additional settings on top.

Elements: 

Elements are visual building blocks that combine to build an entire Blueprint. Each Element is backed by a JSON fragment that defines a concrete search behavior. Elements are provided out of the box with Search Experiences, and an Element editor lets you create your own or duplicate the existing elements to use as starting points for your own needs. We can also include our own unique element clicking (+) button. 



Advanced: Configuring Query Clause Contributors

Liferay’s back-end code (and potentially any custom applications deployed in your Liferay instance) contributes query clauses to the ongoing search.

These clauses contributed by the back-end can be configured via Search Blueprints. However, most users should never touch two settings:

  • Search Framework Indexer Clauses
  • Search Framework Query Contributors 

Liferay’s back-end code (and potentially any custom applications deployed in your Liferay instance) contributes query clauses to the ongoing search.

These clauses contributed by the back-end can be configured via Search Blueprints. However, most users should never touch two settings:

  • Search Framework Indexer Clauses
  • Search Framework Query Contributors

The default settings are usually enough. If you’re sure you must tweak this behavior beyond using the Searchable Types, you must understand the way these back-end contributors work:

  1. Use Searchable Types to disable individual indexers from participating in the search. If you disable a type’s indexer, no clauses for the type are added to the search query, even if its Query Contributors are selected. Results for these types do not appear for users.
  2. Use Search Framework Indexer Clauses to disable all Liferay’s indexers from contributing clauses to the search. The only reason to disable all indexers is to build a search query from scratch, disabling all Query Contributors and Searchable Assets as well.
  3. Use the Search Framework Query Contributors section to remove certain contributors from participating in the search. Disable certain clause contributors if you want to override them using your own Blueprints configuration, or disable all clauses to completely override Liferay’s search behavior, disabling Liferay’s Indexers and Searchable Types as well. 


As an example, if the administrator does not want Liferay to create articleId clauses in request queries, we can disable the journal article query contributor setting. See the image below.



After that setting liferay not including below clauses into search query. You can also verify that by adding a search insight widget to the search page and see the search request query string.

{"bool": {
               "should": [
                   {"match_phrase": {"articleId": {
                       "query""kotlin",
                       "slop"50
                   }}},
                   {"match_phrase": {"articleId": {
                       "query""kotlin",
                       "boost"2
                   }}}
               ],
               "must": [{"match": {"articleId": {"query""kotlin"}}}]
           }},


Creating Search Blueprints

To create Search Blueprints,

  1. Open the Blueprints application by clicking Blueprints from Global Menu → Applications (Search Experiences).
  2. Add a Blueprint by clicking Add ().




3.In the New Search Blueprint window, give the Blueprint a name (required) and a description (optional).

4.Depending on your Blueprint plan, next you’ll use these menus to continue building the Blueprint:    a. Query Builder: in the Query Elements section, add new query clauses to the search by choosing or composing Elements for the Blueprint. In the Query Settings section, configure additional settings for the query (like which asset and object types to search).     b. Configuration: Configure advanced settings (e.g., Sorts or Aggregations) in the search.

5.Once you’re finished with the initial Blueprint creation, Click Save.

Adding Elements to blueprint

  1. Open the Add Query Elements sidebar by clicking the Add (+) button on the Query Elements


   2.Expand the Element category you’d like to explore Link.
   3.Hover over the Element, then click the Add button.
   4.The Element is added to the Query Builder, ready to configure: as an example i                        add boost all keyword match element to blueprint, see the below image. 



  In Above image, the configured element, when a search keyword matches in the title field, assigns 4000 boosts. You can see the result by clicking on the Preview button.
  1. After adding Elements, make sure you save the Blueprint.

We can also add our custom Elasticsearch query into the blueprint. 



 Choosing which Liferay Assets to Search

Decide which Liferay Asset Types to include in the Blueprint’s query. Use Query Settings → Searchable Types: 



  • All asset and object types are selected by default.
  • To remove specific types, click Select Asset Types to open the Select Types, then de-select the corresponding checkboxes. 


Conclusion

In conclusion, Liferay Search Blueprint is a powerful tool that enables organizations to customize and improve the search experience within their Liferay portal. By creating a blueprint, administrators can define the search behavior, control what is searched and how, and enhance the relevance and personalization of search results. We can also define aggregation, sort, and highlights in query.

Read More Liferay Search Blueprint: Improving the Search Experience

 

Comments

Popular posts from this blog

How to Hire the Best Java Developers For Your Upcoming Project

AWS CDK (Cloud Development Kit): A Comprehensive Guide

Tensorflow vs. PyTorch : Choosing the best Deep Learning Framework