Bert Godon 10 Years Ago Thanks for the quick response! It works great! But I have one little comment: there is no toString method on the BooleanClauseOccur object, but there is a getName method. I used BooleanClauseOccur.MUST.getName() instead of BooleanClauseOccur.SHOULD.toString(). Please sign in to reply. Reply as... Cancel Andrew Jardine Bert Godon 7 Years Ago This is a very important distinction! I just spent over an hour trying to do this same concept but allowing the user to select a DDMStructure that "MUST" be in place. I was using BooleanClauseOccur.MUST.toString() but it my query kept showing (+ddmStructureKey:xxxxx). As soon as I changed it to getName(), works like a charm. @Ray -- can you update the post for the next bugger like me that comes along and doesn't read the comments thread right away? Please sign in to reply. Reply as... Cancel
Andrew Jardine Bert Godon 7 Years Ago This is a very important distinction! I just spent over an hour trying to do this same concept but allowing the user to select a DDMStructure that "MUST" be in place. I was using BooleanClauseOccur.MUST.toString() but it my query kept showing (+ddmStructureKey:xxxxx). As soon as I changed it to getName(), works like a charm. @Ray -- can you update the post for the next bugger like me that comes along and doesn't read the comments thread right away? Please sign in to reply. Reply as... Cancel
Vanita Chawla 10 Years Ago Thanks for the blog article and your insight. It would be great if the search portlet could be configured from the portal-ext.properties or the control panel GUI at a global scope/context and per site basis. This requirement to configure search is recurring theme in our business requirements as we do more with Liferay every sprint. This global/site ability to configure search is critical for us as we embed the search portlet in the header in the theme and the search portlet instance configuration is not an option available to us. Even if we did not embed the portlet in the header, I can see value in being able to configure search globally or on a per site basis. . It would be great if this could be built into Liferay. In the meantime - is there anything we can do to do a support customization for the configuration of the search portlet? Couple of specific configuration examples I can think of are - restrict search scope to a specific site for a a site, disable user to show up in search, add active announcements to show up in search results. Thanks again. Please sign in to reply. Reply as... Cancel
Muradali Hasan 10 Years Ago Thanks for nice information,I just want to know, if we want to include two or more extension for DLFileEntry How it can be done.I am trying using entryClassName:com.liferay.portlet.journal.model.JournalArticle (+entryClassName:com.liferay.portlet.documentlibrary.model.DLFileEntry +extension:pdf (+extension:doc))But it only search for pdf documents.My question is how can we include multiple extension of fileThanks Please sign in to reply. Reply as... Cancel Ricardo Vieira Muradali Hasan 7 Years Ago Did you find an answer for this? Please sign in to reply. Reply as... Cancel
Ricardo Vieira Muradali Hasan 7 Years Ago Did you find an answer for this? Please sign in to reply. Reply as... Cancel
Justyna Gralinska 10 Years Ago For anyone interested in this functionality (just the core, not the configurable bit) but unclear on how to implement it- you need to create a new hook in eclipse and then:1. Add this code from to main_search .jspf somewhere above the search results table (html/portlet/search)Query stringQuery = StringQueryFactoryUtil.create("entryClassName:com.liferay.portlet.journal.model.JournalArticle (+entryClassName:com.liferay.portlet.documentlibrary.model.DLFileEntry +extension:pdf)");BooleanClause clause = BooleanClauseFactoryUtil.create(searchContext, stringQuery, BooleanClauseOccur.MUST.getName());searchContext.setBooleanClauses(new BooleanClause[] {clause});2. Declare the dependencies in init.jsp. i.e. add them to all the other dependencies at the top (html/portlet/search)page import="com.liferay.portal.kernel.search.SearchContext" %><%@page import="com.liferay.portal.kernel.search.BooleanClause" %><%@page import="com.liferay.portal.kernel.search.BooleanClauseFactoryUtil" %><%@page import="com.liferay.portal.kernel.search.BooleanClauseOccur" %><%@page import="com.liferay.portal.kernel.search.StringQueryFactoryUtil" %><%@page import="com.liferay.portal.kernel.search.Query" %><%@ Please sign in to reply. Reply as... Cancel
Joseph Toman 9 Years Ago I'm glad to find something written about this API. Thanks! One follow up question:SearchContext has methods like setAssetTagNames and setAssetCategoryIds . How do the tags and categories specified there interact with the queries set with setBooleanClauses? ANDed? ORed? Overridden? Please sign in to reply. Reply as... Cancel
Giannis Foufas 9 Years Ago Hello,Could you please complete the above code example?I would like to know how the searchContext is used to do the actual search.Regards,Query stringQuery = StringQueryFactoryUtil.create("entryClassName:com.liferay.portlet.journal.model.JournalArticle (+entryClassName:com.liferay.portlet.documentlibrary.model.DLFileEntry +extension:pdf)");BooleanClause clause = BooleanClauseFactoryUtil.create(searchContext, stringQuery, BooleanClauseOccur.SHOULD.toString());searchContext.setBooleanClauses(new BooleanClause[] {clause}); Please sign in to reply. Reply as... Cancel
Renata Willi 8 Years Ago Thanks for this helpful article. The code works great. Only journal articles and pdf files are shown as search result, but it's not sorted according search relevance any more. All PDF files are listed at first and then all the journal articles. Why has the order changed? How can I sort it the other way round? Please sign in to reply. Reply as... Cancel Premysl Steidl Renata Willi 7 Years Ago Hi, did you find solution for this? I'm facing the same problem. Please sign in to reply. Reply as... Cancel
Premysl Steidl Renata Willi 7 Years Ago Hi, did you find solution for this? I'm facing the same problem. Please sign in to reply. Reply as... Cancel