Foren

How to customize liferay dxp search scoring?

Vishnu S Kumar, geändert vor 6 Jahren.

How to customize liferay dxp search scoring?

Regular Member Beiträge: 131 Beitrittsdatum: 28.07.17 Neueste Beiträge
We have a custom search portlet and a custom asset called 'Library'. Our application uses this 'Library' and 'JournalArticle' both. While doing a search we found that Liferay gives more score to the journal article result than that of the 'Library' content, even if 'Library' has more matching terms. How do we change this behavior?
thumbnail
Russell Bohl, geändert vor 6 Jahren.

RE: How to customize liferay dxp search scoring? (Antwort)

Expert Beiträge: 289 Beitrittsdatum: 13.02.13 Neueste Beiträge
Note: I'm not necessarily an expert in this, but I've seen it discussed before.

If I'm not mistaken this is really a function of the underlying Search Engine. Read here if you're using Elasticsearch: https://www.elastic.co/guide/en/elasticsearch/guide/current/scoring-theory.html

Off the top of my head, one reason that you might be seeing more results for Journal articles despite fewer matching terms is that matches in shorter fields cause a higher score. So, matches in the title field will tend to outscore matches in the content field, for example.

That said, I think you can get what you want, because Liferay's API exposes the Boost feature in the com.liferay.portal.kernel.search.Query.setBoost(float) method.

As far as how you would boost one or more fields in your Library document, you need to set the boost at query time (postProcessSearchQuery method). Since you're rolling your own search Portlet, you'd probably also need to make sure it's getting the boost value and accounting for it at result display time. For a model whose indexer you don't have access to, you would do the same in an Indexer Post Processor (https://dev.liferay.com/develop/reference/-/knowledge_base/7-0/indexer-post-processor).

Exactly how to implement this, I don't know, but that's the theory, from what I understand.
thumbnail
Andrew Jardine, geändert vor 6 Jahren.

RE: How to customize liferay dxp search scoring?

Liferay Legend Beiträge: 2416 Beitrittsdatum: 22.12.10 Neueste Beiträge
Are you able to share any code with us? Are you just using the "Search Portlet" or do you have some custom code that you have written?
Vishnu S Kumar, geändert vor 6 Jahren.

RE: How to customize liferay dxp search scoring?

Regular Member Beiträge: 131 Beitrittsdatum: 28.07.17 Neueste Beiträge
Hi Andrew,

We have a custom search code, with base indexer and post-processor. I solved this by adding boost values to each field, while creating the query.
thumbnail
Andrew Jardine, geändert vor 6 Jahren.

RE: How to customize liferay dxp search scoring?

Liferay Legend Beiträge: 2416 Beitrittsdatum: 22.12.10 Neueste Beiträge
Hi Vishnu,

Great! Thanks for taking the time to follow up and complete the thread so that the next person that comes along doesn't end up wondering if it was ever solved emoticon
Vishnu S Kumar, geändert vor 6 Jahren.

RE: How to customize liferay dxp search scoring?

Regular Member Beiträge: 131 Beitrittsdatum: 28.07.17 Neueste Beiträge
Thanks for the support. emoticon