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


      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 add this:

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

      At 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() %>" />

      Replace with this:

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

      At add this:

      	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;

      At add this:

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

      After add this:

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

      Replace with this:

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

      Replace with this:

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

      At 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.


        Issue Links



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




                  Version Package