Details

    • Feature Request
    • Status: Reviewed
    • Minor
    • Resolution: Not Aligned with the Roadmap
    • None
    • None
    • None

    Description

      I heard this feature request a lot of my users so I'll share it here:

      The current search works like this, first enter a keyword and send it, then use facet filter to get better results. I was asked, why they have to use these facet filters and why they aren't predefined. They want to send a keyword and already get a filtered result list for a certain category or tag.

      I've implemented this on UI level:
      First of all I had to allow multiple instances for the search portlet, as this is useful in this case. So add a '<instanceable>true</instanceable>' to '<portlet-name>3</portlet-name>' in liferay-portlet.xml.

      At https://github.com/liferay/liferay-portal/blob/6.1.x/portal-web/docroot/html/portlet/search/init.jsp#L89 add this:

      String categoryFilter = GetterUtil.getString(portletPreferences.getValue("categoryFilter", ""), "");
      String tagFilter = GetterUtil.getString(portletPreferences.getValue("tagFilter", ""), "");
      

      At https://github.com/liferay/liferay-portal/blob/6.1.x/portal-web/docroot/html/portlet/search/configuration.jsp#L67 add this:

      	<br />
      	
      	<aui:fieldset label="categorization">
      		
      		<% 
      		com.liferay.portlet.asset.model.impl.AssetCategoryImpl c = new com.liferay.portlet.asset.model.impl.AssetCategoryImpl();
      		com.liferay.portlet.asset.model.impl.AssetTagImpl t = new com.liferay.portlet.asset.model.impl.AssetTagImpl();
      		%>
      		
      		<aui:input label="category-filter" helpMessage="display-categoryFilter-help" name="preferences--categoryFilter--" type="hidden" value="<%= categoryFilter %>" />
      		<aui:input helpMessage="display-categoryFilter-help" name="categoryFilter" type="assetCategories" value="<%= categoryFilter %>" model="<%= c.getClass() %>" />
      		
      		<aui:input label="" name="preferences--tagFilter--" type="hidden" value="<%= tagFilter %>" />
      		<aui:input helpMessage="display-tagFilter-help" name="tagFilter" type="assetTags" value="<%= tagFilter %>" model="<%= t.getClass() %>" />
      		
      	</aui:fieldset>
      

      Replace https://github.com/liferay/liferay-portal/blob/6.1.x/portal-web/docroot/html/portlet/search/configuration.jsp#L69 with this:

      		<aui:button type="submit" onClick="setSearchFilter()" />
      

      At https://github.com/liferay/liferay-portal/blob/6.1.x/portal-web/docroot/html/portlet/search/configuration.jsp#L72 add this:

      <aui:script>
      	function setSearchFilter() {
      		var categories = "";
      		var tags = "";
      		<%
      		List <AssetVocabulary> voks = AssetVocabularyLocalServiceUtil.getAssetVocabularies(0, AssetVocabularyLocalServiceUtil.getAssetVocabulariesCount());
      		for (AssetVocabulary vok : voks) {
      			%>
      			if (typeof(document.<portlet:namespace />fm.<portlet:namespace />assetCategoryIds_<%= vok.getVocabularyId() %>) != "undefined") {
      				categories = categories + document.<portlet:namespace />fm.<portlet:namespace />assetCategoryIds_<%= vok.getVocabularyId() %>.value;
      			}
      			<%
      		}
      		%>
      		if (categories.length != 0) {
      			if (categories.length != 5) {
      				alert("Just one category!");
      				categories = categories.substr(0, 5);
      			}
      		}
      		
      		tags = document.<portlet:namespace />fm.<portlet:namespace />assetTagNames.value;
      		if (tags.indexOf(",") != -1) {
      			alert("Just one tag!");
      			tags = tags.substr(0, tags.indexOf(",") );
      		}
      		
      		document.<portlet:namespace />fm.<portlet:namespace />categoryFilter.value = categories;
      		document.<portlet:namespace />fm.<portlet:namespace />tagFilter.value = tags;
      	}
      </aui:script>
      

      At https://github.com/liferay/liferay-portal/blob/6.1.x/portal-web/docroot/html/taglib/ui/search/start.jsp#L18 add this:

      <%@ page import="com.liferay.portlet.asset.service.AssetCategoryLocalServiceUtil" %>
      

      After https://github.com/liferay/liferay-portal/blob/6.1.x/portal-web/docroot/html/taglib/ui/search/start.jsp#L19 add this:

      namespace = themeDisplay.getPortletDisplay().getId();
      

      Replace https://github.com/liferay/liferay-portal/blob/6.1.x/portal-web/docroot/html/taglib/ui/search/start.jsp#L31 with this:

      	portletURL = liferayPortletResponse.createLiferayPortletURL(namespace, PortletRequest.RENDER_PHASE);
      

      Replace https://github.com/liferay/liferay-portal/blob/6.1.x/portal-web/docroot/html/taglib/ui/search/start.jsp#L34 with this:

      	portletURL = new PortletURLImpl(request, namespace, plid, PortletRequest.RENDER_PHASE);
      

      At https://github.com/liferay/liferay-portal/blob/6.1.x/portal-web/docroot/html/taglib/ui/search/start.jsp#L42 add this:

      namespace = "_" + themeDisplay.getPortletDisplay().getId() + "_";
      
      String assetCategoryPredefined = portletRequest.getPreferences().getValue("categoryFilter", "");
      if (!assetCategoryPredefined.isEmpty()) {
      	assetCategoryPredefined = AssetCategoryLocalServiceUtil.getCategory(Long.parseLong(assetCategoryPredefined)).getTitle(languageKey);
      }
      String assetTagPredefined = portletRequest.getPreferences().getValue("tagFilter", "");
      
      assetTagPredefined = assetTagPredefined.toLowerCase();
      

      I think that's it, I hope, I didn't forget some line.

      With this feature one can add a search portlet to e. g. the page "Current tasks" and configure it with the tag "current tasks". Now, when someone enters a keyword, the results will be filtered to this tag already. The user get's a list of exactly the results, he want's, without any extra steps.

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              mod David Kubitza (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Packages

                  Version Package