How to implement Query Indexing Mechanism in Liferay DXP ?

Vishnu S Kumar, modified 7 Years ago. Regular Member Posts: 131 Join Date: 7/28/17 Recent Posts

Our motive is to show to the search user, the related keywords if the users search yields result lesser than a threshold value. I read the Liferay developer docs and implemented query indexing but it didn't work. My approach is explained below.

In the $LIFERAY_HOME I added the following portal-ext.properties and then restarted the Liferay.

index.search.query.indexing.enabled=true
index.search.query.indexing.threshold=1
index.search.query.suggestion.scores.threshold=500
index.search.query.suggest.max=10

 

Also in the search context, I added these configs after the testing failed.

 searchContext.getQueryConfig().setQueryIndexingEnabled(true);
 searchContext.getQueryConfig().setQueryIndexingThreshold(1);


 searchContext.getQueryConfig().setQuerySuggestionEnabled(true);
 searchContext.getQueryConfig().setQuerySuggestionScoresThreshold(500);

 

 I tested it again like this. First searched keyword "abcd xyz", that yields 3 results so the keyword should be indexed as its more than the indexing threshold (1).  Then I searched multiple times with different keywords like "xyz","abcd", "abcd lmno" etc. All of these yield 0 or more results but less than the suggestion scores threshold (500) so it should give me the related keyword suggestions. But the suggestion is empty for all these hits.

indexer = IndexerRegistryUtil.getIndexer(JournalArticle.class.getName());
Hit hits=indexer.search(searchContext);
HitsProcessorRegistryUtil.process(searchContext, hits);
String[] str=hits.getQuerySuggestions(); // empty array

 

Am I not following it correctly or are there any mistakes in my testing? Thanks in advance for your expert opinions and answers.

Ref: https://dev.liferay.com/es/develop/tutorials/-/knowledge_base/7-0/introduction-to-liferay-search#hitsprocessor