Liferay boolean query for searching
By default liferay supports lucene, so how to retrieve entries
Code as follows ,
BooleanQuery fullQuery = BooleanQueryFactoryUtil.create(searchContext);
BooleanQuery searchQuery = BooleanQueryFactoryUtil.create(searchContext);
Searching the blog
searchQuery.addRequiredTerm(Field.ENTRY_CLASS_NAME, BlogsEntry.class.getName());
Adding required terms to search query
searchQuery.addRequiredTerm(Field.ASSET_CATEGORY_IDS, CategoryId);
fullQuery.add(searchQuery, BooleanClauseOccur.MUST);
Adding optional terms where the content should belong to at lease one of these categories
BooleanQuery categoryQuery = BooleanQueryFactoryUtil.create(searchContext);
categoryQuery.addExactTerm(Field.ASSET_CATEGORY_IDS, CategoryId);
fullQuery.add(categoryQuery, BooleanClauseOccur.MUST);
Then use fullquery to search blogs
SearchContext searchContext =
SearchContextFactory. getInstance(PortalUtil.getHttpServletRequest(renderRequest));
Hits hits = SearchEngineUtil.search(searchContext, fullQuery);
It will return hits , convert to document and iterate document to get the entries.
List<Document> docList = resultHits.toList();
for ( Document document : docList ){
doc.get(Field.ENTRY_CLASS_PK); //classPK
doc.getValues(Field.ASSET_TAG_NAMES) // tags
doc.get(Field.MODIFIED_DATE)// modified date
}
I have found very useful information over there, thanks for sharing this. please try to add more informative posts in order to keep us in touch.
ReplyDeleteactually the documentation about these topics is very rare , thanks for that
ReplyDeleteYour words of interest in this article almost match my own thoughts. This article is really
ReplyDeletecommendable. I liked this post very much. Thank you very much for sharing such posts.
Skip Hire Leicester