Boosting Search Revisited

Liferay Search Blueprints offers an exciting new way to configure and control search in Liferay DXP...


In November of 2018, I authored a blog, Boosting Search. In that blog, I showed how to boost search results for tag matches in an effort to provide some alternative to GSA's KeyMatch support.

A lot has changed in Liferay since that blog was posted, and it turns out there are much easier ways now in DXP 7.4 that won't require any code at all...

Results Ranking

In discussing the GSA KeyMatch issue, a baker may want to make the holiday cupcakes come to the top of the search results for cupcakes during the holiday, and I shared that Liferay's search couldn't handle that kind of boost and had to find some alternative.

In Liferay DXP 7.4, there is an out of the box solution to this - Results Ranking.

So let's just start with my setup so we can follow along... I did a google image search for cupcakes, downloaded a bunch, and then I uploaded them into my Liferay DXP 7.4 Update 7 environment that I'm using for the blog.

A basic search for "cupcakes" yields this result:

We see all of my images, not really sorted or anything, plus the cupcakes folder that I loaded all of the pictures into.

Now, if I go to the waffle and choose the Applications tab, I can select the Result Rankings:

On this page I can add a new ranking:

I have to put in the keywords that I'm going to tweak the results for:

This will complete a search for cupcakes and show me all of the results. In this page I can choose to pin items (forcing them to the top) or hide items that I want to exclude:

When I'm all done with my changes, my final list will look like:

We can see that I've pinned the two Christmas-related cupcakes, I've hidden the Easter and Halloween cupcakes, and I've also hidden the cupcakes folder.

Back on the main site, when I do a search now, my ranked results shine through:

So I can use Results Ranking now to pin cupcakes for the specific holiday, and I can hide cupcakes that are not available.

When visitors come to my site during the Christmas season and search for cupcakes, my special holiday themed cupcakes come to the top of the list so I can help drive people towards those elements. And I can stop them from finding the Easter cupcakes that I'm not going to be serving up until the Spring.

I can define multiple Result Ranking scenarios on separate keywords, so I can do a similar sort of thing for cakes, cookies, etc.

Before going onto the next section, go to the Result Rankings and disable the ranking, we don't want it to interfere going forward...

Search Blueprints

In the Boosting Search blog, I presented custom code that was boosting search results for tag matching on the keywords. It worked, but it is a development artifact, so any changes necessary for search has to come back to me as the developer to implement. The code itself seems kind of fragile to me, I mean it is busy walking the tree of queries looking for the right one(s) to update, any significant change on the Liferay side could prevent it from working right anymore.

Plus, as search tuning gets more complicated, there may be additional facets that I might have to create custom solutions around, and each one of those custom solutions would have similar problems, and finally I'd have to figure out how to allow them to all work together...

Liferay DXP 7.4 has an exciting new feature which will eliminate all of this custom coding - Search Blueprints.

Search Blueprints is a set of UI-based controls that you can leverage to customize search results.

Before diving into use, I'm going to cover some boring old terminology stuff. I know, I know, but this stuff is important for understanding Blueprints...

Search Blueprints is composed of two things: a Blueprint and its Elements. The elements are defined in the Liferay UI, and they are the building blocks for the Blueprint. The Blueprint itself is a design for Liferay's search behavior, and the design is based upon some configuration and some Elements.

There are different categories of Elements that you will be able to pick from for your Blueprint:

  • Boost: Defines a straight-up boost for simple criteria, such as the Boost Tags Match element that will boost a hit with a tag that matches the search keyword(s) (sound familiar?)
  • Conditional: These are complex elements that leverage conditional logic to apply, such as the Boost Contents in a Category for a Period of Time which applies a boost for a limited time.
  • Filter: Filters exclude some results from the search, for example the Staging Aware filter that excludes non-approved items from the search results.
  • Hide: Hides items based upon fixed criteria, such as the Hide Hidden Contents element which will exclude items that are marked "not searchable".
  • Match: Match elements are used to tune the result matching, for example the Text Match Over Multiple Fields element can be used to specify the fields from the indexed documents that should be used during search.
  • Custom: Custom is, well, the custom element. It is often used when you can't find a suitable Element for your needs.

Defining a Blueprint

So enough of the terminology, let's create a Blueprint!

Let's build the same kind of thing that we have for the Results Ranking, we'll boost the Christmas elements, hide the ones for other holidays and remove the folder from the results.

We'll start by going to the waffle to the Applications section and, under Search Experience, we'll pick Blueprints:

From the Blueprints control panel, we'll add a new Blueprint:

We'll give our Blueprint a name and a description:

We want to limit the types of entities to include in the search results, so let's start by going to the query settings and changing Searchable Types from All Searchable Types to Selected Types, then we can pick what we want to include:

I didn't include the Documents Folder, so we know the cupcakes folder will be excluded from the results:

Next flip to the Query Elements panel, and we'll add a Boost Tagged Contents element and choose Christmas for the tag to boost:

If you use the Preview feature from the top right side and then search for cupcakes, you can see that my Christmas images are at the top, but I'm also showing the ones for the other holidays:

Let's go ahead and add two Hide Tagged Content elements to exclude the easter and halloween tags:

Now, on the preview, we'll get the results we expect:

The preview looks good, so we can save the Blueprint. If we go back to the site and do a search, we see the original, unfiltered results:

To use our Blueprint, we need to add a Blueprints Options widget. Note I'm using a widget page here, if you have a content page for search you'll go down a slightly different but similar path:

Don't be worried about the big box in the page, that is only visible to you the administrator. For guests or regular users, they will not see the Blueprints Options portlet or the blue box.

Click on the Configure Blueprints options in this page link to bring up the settings:

Click the Select button and choose the Christmas Promotion item:

After selecting the blueprint, we can see and save the selection:

Now, if we repeat the search again, we get our expected results:


There really is so much more to Blueprints, I've hardly scratched the surface. Using all of the available Blueprint Elements, you can really manage your search results in new and interesting ways.

But I hope you can see where a search customization that I had to do over 3 years ago has now been replaced with an out of the box technique that I created directly in the UI.

You might be asking, "Sure Dave, but where's the code for a custom Element, you're always giving us code...". Well, not in this case. I did mention earlier about the Custom category of elements? Those are extremely flexible solutions where all you need is the Elastic query or the query JSON and you can add almost whatever is missing, all without coding.

Since I've covered these things, I want to provide some links to Liferay's documentation where you can learn more about each feature:

Liferay actually has a lot more features around the Search Page Experience (SPX) that I encourage you to dig into if you want to learn more. You can find more details here:

I hope this helps you to figure out your own ways to customize your search experience!

And hey, if you have problems with Blueprints or there's a missing Element that if you had your life would be so much better, swing over to the Liferay Community Slack and post about it. I'll make sure it gets to the Liferay Search team!