Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Sheetal Mohan Sharma
Filter and Refine contents based on multiple categories?
July 5, 2011 12:51 AM
Answer

Sheetal Mohan Sharma

Rank: New Member

Posts: 4

Join Date: March 8, 2011

Recent Posts

We are using asset-publisher and categories navigation portlets. Displaying content’s based on category and tags criteria works well but how should we get results by filtering and refining results based on check-box(es)/links selected? We have seen faceted-search portlet but this does not help in our case.

Here is my solution approach and please guide me here.

intend to solve this by having check boxes instead of links in categories navigation portlet by using a jsp hook and then pass the checked category id’s as request parameters to the action class (and modify the query which is used for retrieving the contents based on category id’s.

So far I am able to create checkboxes as shown in this image. The main problem is identification of the action class which is being called on click of category link in category navigation portlet. Hence I am not able to retrieve the checked categories ids from request.

The current URL displayed on category link hit is as fallows:

http://serverName:8080/web/mediasolutions/demos?p_p_id=122_INSTANCE_K5Gj&p_p_lifecycle=0&p_p_state=normal&p_p_mode=view&p_p_col_id=column-2&p_p_col_count=2&p_r_p_564233524_categoryId=13569

As it clear from above URL it passes a single category id on link click p_r_p_564233524_categoryId=13569. I want to achieve filter and refine approach on click of each check-box and for that I guess I need to be able to

1. Save the current state of results.
2. Should be able refine the current result set on next check-box selection.

**Can any body suggest me the action classes and other relevant information ( code snippets, design docs etc)required for above solution approach?**

I am also fine with what I see here at - http://portal.eqentia.com/socialmedia/connection/1520-Blogs?connection_refine=1587&filter=all

[1]: http://i.stack.imgur.com/LiAKf.jpg
Attachment

Attachments: Filter By CheckBox.JPG (40.2k)
Sheetal Mohan Sharma
RE: Filter and Refine contents based on multiple categories?
July 14, 2011 11:21 PM
Answer

Sheetal Mohan Sharma

Rank: New Member

Posts: 4

Join Date: March 8, 2011

Recent Posts

This has been fixed by using hook in asset-publisher. No changes were required in DB or query. The service layer accepts list of categories and thats what we am sending now.
Alain Dresse
RE: Filter and Refine contents based on multiple categories?
February 7, 2012 1:21 PM
Answer

Alain Dresse

Rank: Junior Member

Posts: 95

Join Date: July 18, 2011

Recent Posts

Sheetal,

Could you please share the hooks on the asset-publisher and on the categories navigator ?

Thanks,
Alain
Sebastian Wikholm
RE: Filter and Refine contents based on multiple categories?
February 21, 2012 3:42 AM
Answer

Sebastian Wikholm

Rank: Junior Member

Posts: 76

Join Date: March 10, 2011

Recent Posts

If possible could you share that to me too?
berree annelaure
RE: Filter and Refine contents based on multiple categories?
October 2, 2012 9:35 AM
Answer

berree annelaure

Rank: New Member

Posts: 1

Join Date: October 2, 2012

Recent Posts

I know i am late but i am very interested by the code of the hooks.
Could you share them with me ?

Thanks
Pravin Pawar
RE: Filter and Refine contents based on multiple categories?
February 26, 2013 4:35 AM
Answer

Pravin Pawar

Rank: Junior Member

Posts: 62

Join Date: November 17, 2009

Recent Posts

Hi Shital

Sheetal Mohan Sharma:
This has been fixed by using hook in asset-publisher. No changes were required in DB or query. The service layer accepts list of categories and thats what we am sending now.


Your inputs will be highly appreciated.
eastor liu
RE: Filter and Refine contents based on multiple categories?
April 22, 2013 1:13 AM
Answer

eastor liu

Rank: New Member

Posts: 5

Join Date: August 16, 2012

Recent Posts

Hello ,here is my hook:
the liferay-hook.xml
1<?xml version="1.0"?>
2<!DOCTYPE hook PUBLIC "-//Liferay//DTD Hook 6.1.0//EN" "http://www.liferay.com/dtd/liferay-hook_6_1_0.dtd">
3
4<hook>
5<custom-jsp-dir>/WEB-INF/custom_jsps</custom-jsp-dir>
6</hook>

and the jsp's location which you have to modify is ROOT/html/portlet/asset_publisher/init.jsp .You should modify it by using hook.

Here is init.jsp:
  1<%--
  2/**
  3 * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
  4 *
  5 * This library is free software; you can redistribute it and/or modify it under
  6 * the terms of the GNU Lesser General Public License as published by the Free
  7 * Software Foundation; either version 2.1 of the License, or (at your option)
  8 * any later version.
  9 *
 10 * This library is distributed in the hope that it will be useful, but WITHOUT
 11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 12 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 13 * details.
 14 */
 15--%>
 16
 17<%@ include file="/html/portlet/init.jsp" %>
 18
 19<%@ page import="com.liferay.portal.NoSuchModelException" %><%@
 20page import="com.liferay.portal.kernel.repository.model.FileEntry" %><%@
 21page import="com.liferay.portal.kernel.search.Hits" %><%@
 22page import="com.liferay.portal.kernel.xml.Document" %><%@
 23page import="com.liferay.portal.kernel.xml.Element" %><%@
 24page import="com.liferay.portal.kernel.xml.SAXReaderUtil" %><%@
 25page import="com.liferay.portal.security.permission.comparator.ModelResourceComparator" %><%@
 26page import="com.liferay.portlet.asset.AssetRendererFactoryRegistryUtil" %><%@
 27page import="com.liferay.portlet.asset.NoSuchEntryException" %><%@
 28page import="com.liferay.portlet.asset.NoSuchTagException" %><%@
 29page import="com.liferay.portlet.asset.NoSuchTagPropertyException" %><%@
 30page import="com.liferay.portlet.asset.model.AssetCategory" %><%@
 31page import="com.liferay.portlet.asset.model.AssetEntry" %><%@
 32page import="com.liferay.portlet.asset.model.AssetRenderer" %><%@
 33page import="com.liferay.portlet.asset.model.AssetRendererFactory" %><%@
 34page import="com.liferay.portlet.asset.model.AssetTag" %><%@
 35page import="com.liferay.portlet.asset.model.AssetTagProperty" %><%@
 36page import="com.liferay.portlet.asset.model.AssetVocabulary" %><%@
 37page import="com.liferay.portlet.asset.service.AssetCategoryLocalServiceUtil" %><%@
 38page import="com.liferay.portlet.asset.service.AssetEntryLocalServiceUtil" %><%@
 39page import="com.liferay.portlet.asset.service.AssetEntryServiceUtil" %><%@
 40page import="com.liferay.portlet.asset.service.AssetTagLocalServiceUtil" %><%@
 41page import="com.liferay.portlet.asset.service.AssetTagPropertyLocalServiceUtil" %><%@
 42page import="com.liferay.portlet.asset.service.AssetVocabularyLocalServiceUtil" %><%@
 43page import="com.liferay.portlet.asset.service.persistence.AssetEntryQuery" %><%@
 44page import="com.liferay.portlet.asset.util.AssetUtil" %><%@
 45page import="com.liferay.portlet.assetpublisher.search.AssetDisplayTerms" %><%@
 46page import="com.liferay.portlet.assetpublisher.search.AssetSearch" %><%@
 47page import="com.liferay.portlet.assetpublisher.search.AssetSearchTerms" %><%@
 48page import="com.liferay.portlet.assetpublisher.util.AssetPublisherUtil" %><%@
 49page import="com.liferay.portlet.documentlibrary.model.DLFileEntry" %><%@
 50page import="com.liferay.portlet.documentlibrary.model.DLFileEntryConstants" %><%@
 51page import="com.liferay.portlet.documentlibrary.model.DLFolderConstants" %><%@
 52page import="com.liferay.portlet.documentlibrary.service.DLAppLocalServiceUtil" %><%@
 53page import="com.liferay.portlet.documentlibrary.util.DocumentConversionUtil" %><%@
 54page import="com.liferay.portlet.journal.model.JournalArticle" %><%@
 55page import="com.liferay.portlet.journal.model.JournalStructure" %><%@
 56page import="com.liferay.portlet.journal.service.JournalStructureLocalServiceUtil" %><%@
 57page import="com.liferay.util.RSSUtil" %><%@
 58page import="com.liferay.util.xml.DocUtil" %>
 59
 60<%
 61PortletPreferences preferences = renderRequest.getPreferences();
 62
 63String portletResource = ParamUtil.getString(request, "portletResource");
 64
 65if (Validator.isNotNull(portletResource)) {
 66    preferences = PortletPreferencesFactoryUtil.getPortletSetup(request, portletResource);
 67}
 68
 69String selectionStyle = preferences.getValue("selectionStyle", null);
 70
 71if (Validator.isNull(selectionStyle)) {
 72    selectionStyle = "dynamic";
 73}
 74
 75boolean defaultScope = GetterUtil.getBoolean(preferences.getValue("defaultScope", null), true);
 76
 77long[] groupIds = AssetPublisherUtil.getGroupIds(preferences, scopeGroupId, layout);
 78
 79long[] availableClassNameIds = AssetRendererFactoryRegistryUtil.getClassNameIds();
 80
 81for (long classNameId : availableClassNameIds) {
 82    AssetRendererFactory assetRendererFactory = AssetRendererFactoryRegistryUtil.getAssetRendererFactoryByClassName(PortalUtil.getClassName(classNameId));
 83
 84    if (!assetRendererFactory.isSelectable()) {
 85        availableClassNameIds = ArrayUtil.remove(availableClassNameIds, classNameId);
 86    }
 87}
 88
 89boolean anyAssetType = GetterUtil.getBoolean(preferences.getValue("anyAssetType", null), true);
 90
 91long[] classNameIds = AssetPublisherUtil.getClassNameIds(preferences, availableClassNameIds);
 92
 93long[] classTypeIds = GetterUtil.getLongValues(portletPreferences.getValues("classTypeIds", null));
 94
 95String customUserAttributes = GetterUtil.getString(preferences.getValue("customUserAttributes", StringPool.BLANK));
 96
 97AssetEntryQuery assetEntryQuery = new AssetEntryQuery();
 98
 99String[] allAssetTagNames = new String[0];
100
101if (selectionStyle.equals("dynamic")) {
102    if (!ArrayUtil.contains(groupIds, scopeGroupId)) {
103        assetEntryQuery = AssetPublisherUtil.getAssetEntryQuery(preferences, ArrayUtil.append(groupIds, scopeGroupId));
104    }
105    else {
106        assetEntryQuery = AssetPublisherUtil.getAssetEntryQuery(preferences, groupIds);
107    }
108
109    allAssetTagNames = AssetPublisherUtil.getAssetTagNames(preferences, scopeGroupId);
110
111    assetEntryQuery.setClassTypeIds(classTypeIds);
112
113    AssetPublisherUtil.addUserAttributes(user, StringUtil.split(customUserAttributes), assetEntryQuery);
114}
115
116long assetVocabularyId = GetterUtil.getLong(preferences.getValue("assetVocabularyId", StringPool.BLANK));
117
118long assetCategoryId = ParamUtil.getLong(request, "categoryId");
119
120String assetCategoryTitle = null;
121String assetVocabularyTitle = null;
122
123if (assetCategoryId > 0) {
124    long[] cid=GetterUtil.getLongValues((String[])request.getParameterValues("categoryId"));
125    assetEntryQuery.setAllCategoryIds(cid);
126
127    AssetCategory assetCategory = AssetCategoryLocalServiceUtil.getCategory(assetCategoryId);
128
129    assetCategory = assetCategory.toEscapedModel();
130
131    assetCategoryTitle = assetCategory.getTitle(locale);
132
133    AssetVocabulary assetVocabulary = AssetVocabularyLocalServiceUtil.getAssetVocabulary(assetCategory.getVocabularyId());
134
135    assetVocabulary = assetVocabulary.toEscapedModel();
136
137    assetVocabularyTitle = assetVocabulary.getTitle(locale);
138
139    PortalUtil.setPageKeywords(assetCategoryTitle, request);
140}
141
142String assetTagName = ParamUtil.getString(request, "tag");
143
144if (Validator.isNotNull(assetTagName)) {
145    allAssetTagNames = new String[] {assetTagName};
146
147    long[] assetTagIds = AssetTagLocalServiceUtil.getTagIds(scopeGroupId, allAssetTagNames);
148
149    assetEntryQuery.setAllTagIds(assetTagIds);
150
151    PortalUtil.setPageKeywords(assetTagName, request);
152}
153
154boolean showLinkedAssets = GetterUtil.getBoolean(preferences.getValue("showLinkedAssets", null), false);
155boolean showOnlyLayoutAssets = GetterUtil.getBoolean(preferences.getValue("showOnlyLayoutAssets", null));
156
157if (showOnlyLayoutAssets) {
158    assetEntryQuery.setLayout(layout);
159}
160
161if (portletName.equals(PortletKeys.RELATED_ASSETS)) {
162    AssetEntry layoutAssetEntry = (AssetEntry)request.getAttribute(WebKeys.LAYOUT_ASSET_ENTRY);
163
164    if (layoutAssetEntry != null) {
165        assetEntryQuery.setLinkedAssetEntryId(layoutAssetEntry.getEntryId());
166    }
167}
168
169boolean mergeUrlTags = GetterUtil.getBoolean(preferences.getValue("mergeUrlTags", null), true);
170boolean mergeLayoutTags = GetterUtil.getBoolean(preferences.getValue("mergeLayoutTags", null), false);
171
172String displayStyle = GetterUtil.getString(preferences.getValue("displayStyle", "abstracts"));
173
174if (Validator.isNull(displayStyle)) {
175    displayStyle = "abstracts";
176}
177
178boolean showAssetTitle = GetterUtil.getBoolean(preferences.getValue("showAssetTitle", null), true);
179boolean showContextLink = GetterUtil.getBoolean(preferences.getValue("showContextLink", null), true);
180int abstractLength = GetterUtil.getInteger(preferences.getValue("abstractLength", null), 200);
181String assetLinkBehavior = GetterUtil.getString(preferences.getValue("assetLinkBehavior", "showFullContent"));
182String orderByColumn1 = GetterUtil.getString(preferences.getValue("orderByColumn1", "modifiedDate"));
183String orderByColumn2 = GetterUtil.getString(preferences.getValue("orderByColumn2", "title"));
184String orderByType1 = GetterUtil.getString(preferences.getValue("orderByType1", "DESC"));
185String orderByType2 = GetterUtil.getString(preferences.getValue("orderByType2", "ASC"));
186boolean excludeZeroViewCount = GetterUtil.getBoolean(preferences.getValue("excludeZeroViewCount", null));
187int delta = GetterUtil.getInteger(preferences.getValue("delta", StringPool.BLANK), SearchContainer.DEFAULT_DELTA);
188String paginationType = GetterUtil.getString(preferences.getValue("paginationType", "none"));
189boolean showAvailableLocales = GetterUtil.getBoolean(preferences.getValue("showAvailableLocales", null));
190boolean showMetadataDescriptions = GetterUtil.getBoolean(preferences.getValue("showMetadataDescriptions", null), true);
191
192boolean defaultAssetPublisher = false;
193
194UnicodeProperties typeSettingsProperties = layout.getTypeSettingsProperties();
195
196String defaultAssetPublisherPortletId = typeSettingsProperties.getProperty(LayoutTypePortletConstants.DEFAULT_ASSET_PUBLISHER_PORTLET_ID, StringPool.BLANK);
197
198if (defaultAssetPublisherPortletId.equals(portletDisplay.getId()) || (Validator.isNotNull(defaultAssetPublisherPortletId) && defaultAssetPublisherPortletId.equals(portletResource))) {
199    defaultAssetPublisher = true;
200}
201
202boolean enablePermissions = GetterUtil.getBoolean(preferences.getValue("enablePermissions", null));
203
204assetEntryQuery.setEnablePermissions(enablePermissions);
205
206boolean enableRelatedAssets = GetterUtil.getBoolean(preferences.getValue("enableRelatedAssets", null), true);
207boolean enableRatings = GetterUtil.getBoolean(preferences.getValue("enableRatings", null));
208boolean enableComments = GetterUtil.getBoolean(preferences.getValue("enableComments", null));
209boolean enableCommentRatings = GetterUtil.getBoolean(preferences.getValue("enableCommentRatings", null));
210boolean enableTagBasedNavigation = GetterUtil.getBoolean(preferences.getValue("enableTagBasedNavigation", null));
211
212String[] conversions = DocumentConversionUtil.getConversions("html");
213String[] extensions = preferences.getValues("extensions", new String[0]);
214boolean openOfficeServerEnabled = PrefsPropsUtil.getBoolean(PropsKeys.OPENOFFICE_SERVER_ENABLED, PropsValues.OPENOFFICE_SERVER_ENABLED);
215boolean enableConversions = openOfficeServerEnabled && (extensions != null) && (extensions.length > 0);
216boolean enablePrint = GetterUtil.getBoolean(preferences.getValue("enablePrint", null));
217boolean enableFlags = GetterUtil.getBoolean(preferences.getValue("enableFlags", null));
218boolean enableSocialBookmarks = GetterUtil.getBoolean(preferences.getValue("enableSocialBookmarks", null), true);
219String socialBookmarksDisplayStyle = preferences.getValue("socialBookmarksDisplayStyle", "horizontal");
220String socialBookmarksDisplayPosition = preferences.getValue("socialBookmarksDisplayPosition", "bottom");
221
222String defaultMetadataFields = StringPool.BLANK;
223String allMetadataFields = "create-date,modified-date,publish-date,expiration-date,priority,author,view-count,categories,tags";
224
225String[] metadataFields = StringUtil.split(preferences.getValue("metadataFields", defaultMetadataFields));
226
227boolean enableRSS = GetterUtil.getBoolean(preferences.getValue("enableRss", null));
228int rssDelta = GetterUtil.getInteger(preferences.getValue("rssDelta", "20"));
229String rssDisplayStyle = preferences.getValue("rssDisplayStyle", RSSUtil.DISPLAY_STYLE_ABSTRACT);
230String rssFormat = preferences.getValue("rssFormat", "atom10");
231String rssName = preferences.getValue("rssName", portletDisplay.getTitle());
232
233String[] assetEntryXmls = preferences.getValues("assetEntryXml", new String[0]);
234
235boolean viewInContext = assetLinkBehavior.equals("viewInPortlet");
236
237boolean showPortletWithNoResults = false;
238boolean groupByClass = (assetVocabularyId == -1);
239boolean allowEmptyResults = false;
240
241Map<String, PortletURL> addPortletURLs = null;
242
243Format dateFormatDate = FastDateFormatFactoryUtil.getDate(locale, timeZone);
244%>
245
246<%@ include file="/html/portlet/asset_publisher/init-ext.jsp" %>
247
248<%!
249private String _checkViewURL(String viewURL, String currentURL, ThemeDisplay themeDisplay) {
250    if (Validator.isNotNull(viewURL) && viewURL.startsWith(themeDisplay.getURLPortal())) {
251        viewURL = HttpUtil.setParameter(viewURL, "redirect", currentURL);
252    }
253
254    return viewURL;
255}
256%>


I change the following :
1
2long[] cid=GetterUtil.getLongValues((String[])request.getParameterValues("categoryId"));
3assetEntryQuery.setAllCategoryIds(cid);

and deploy your hook .
Enter the url (example):http://localhost:8080/web/guest/tuangou?p_p_id=122_INSTANCE_cV5qhqR4qD22&p_p_lifecycle=0&p_p_state=normal&p_p_mode=view&p_p_col_id=column-1&p_p_col_count=2&p_r_p_564233524_resetCur=true&p_r_p_564233524_categoryId=14719&p_r_p_564233524_categoryId=18103

Now it's ok.
eastor liu
RE: Filter and Refine contents based on multiple categories?
April 22, 2013 1:28 AM
Answer

eastor liu

Rank: New Member

Posts: 5

Join Date: August 16, 2012

Recent Posts

i change the "setting tag" like :
 1allAssetTagNames = (String[])request.getParameterValues("tag");
 2    if (Validator.isNotNull(allAssetTagNames)) {
 3        //allAssetTagNames = (String[])request.getParameterValues("tag");
 4       
 5        long[] assetTagIds = AssetTagLocalServiceUtil.getTagIds(scopeGroupId, allAssetTagNames);
 6
 7        assetEntryQuery.setAllTagIds(assetTagIds);
 8        for( long i: assetEntryQuery.getAllTagIds()){
 9            out.print("tagid is "+i);
10        }
11
12        PortalUtil.setPageKeywords(assetTagName, request);
13    }


but it does not work ,i don't know why.
Rahul Bhattacharya
RE: Filter and Refine contents based on multiple categories?
April 30, 2013 9:12 AM
Answer

Rahul Bhattacharya

Rank: Junior Member

Posts: 59

Join Date: January 16, 2010

Recent Posts

i implemented this.
you can download it here.
Chris Tantalo
RE: Filter and Refine contents based on multiple categories?
March 14, 2014 12:12 PM
Answer

Chris Tantalo

Rank: Junior Member

Posts: 33

Join Date: August 21, 2012

Recent Posts

Sheetal Mohan Sharma,
How did you actually solve this? We are looking into the same thing, and are surprised that the Liferay doesn't support multiple categories to be selected at same time. Can you please give your code as an example on how to do this?
Adnan Yaqoob
RE: Filter and Refine contents based on multiple categories?
August 6, 2015 2:50 PM
Answer

Adnan Yaqoob

Rank: Junior Member

Posts: 25

Join Date: March 24, 2014

Recent Posts

Any idea how to modify the list of selected categories on portlet which appears like "Content with Topic <category> x."

I'm able to modify the logic as desired but it shows only one selected on display. I want to display all the selected categories
See attached picture
Attachment

Attachments: Snap-1.png (65.9k)