« Back

Search Organization using Facets Search

General Blogs July 16, 2013 By priti parmar

Liferay provide facet search with great features ,we can add new entries in search using configuration of portlet  to achive this follow the below steps,

Step 1 : create a hook

  • override init.jsp in hook add organization model entry

 

if (displayAssetTypeFacet) {

sb.append("{className: 'com.liferay.portal.kernel.search.facet.AssetEntriesFacet',

data: {frequencyThreshold: 1, values:

[ 'com.liferay.portlet.blogs.model.BlogsEntry',

'com.liferay.portlet.documentlibrary.model.DLFileEntry',

'com.liferay.portlet.journal.model.JournalArticle',

'com.liferay.portlet.wiki.model.WikiPage',

'com.liferay.portal.model.User',

'com.liferay.portal.model.Organization'

]},

displayStyle: 'asset_entries', fieldName: 'entryClassName',

label: 'asset-type',

order: 'OrderHitsDesc',

static: false,

weight: 1.5},

");

}

 

  • override main_search_result_form.jsp and add url entry for organization detail view

 

PortletURL portletURL = (PortletURL)request.getAttribute("search.jsp-portletURL");

//Condition for Organization redirection

PortletURL orgURL = PortletURLUtil.clone(portletURL, renderResponse);

orgURL.setParameter("struts_action", "/search/view_organization");

orgURL.setParameter("organizationId", document.get(Field.ORGANIZATION_ID));

orgURL.setParameter("redirect",portletURL.toString());

if(className.contains("Organization"))

{

viewURL =orgURL.toString();

}

else

{

viewURL = _checkViewURL(themeDisplay, viewURL, currentURL);

}

  • Create view_organization.jsp to display the organization detail
     

<%@ include file="/html/portlet/directory/init.jsp"%>

 

<%

Organization organization = (Organization) request.getAttribute("organization");

long organizationId = BeanParamUtil.getLong(organization, request,"organizationId");

request.setAttribute(WebKeys.ORGANIZATION, organization);

request.setAttribute("addresses.className",

Organization.class.getName());

request.setAttribute("addresses.classPK", organizationId);

request.setAttribute("emailAddresses.className",

Organization.class.getName());

request.setAttribute("emailAddresses.classPK", organizationId);

request.setAttribute("phones.className",

Organization.class.getName());

request.setAttribute("phones.classPK", organizationId);

request.setAttribute("websites.className",

Organization.class.getName());

request.setAttribute("websites.classPK", organizationId);

String redirect = ParamUtil.getString(request, "redirect");

String backURL = ParamUtil.getString(request, "backURL", redirect);

%>

<liferay-ui:header backURL="<%=backURL.toString()%>" title="organization" />

<div class="organization-information">

<div class="section entity-details">

<liferay-util:include page="/html/portlet/directory/organization/details.jsp" />

</div>

 

<div class="section entity-email-addresses">

       <liferay-util:include

        page="/html/portlet/directory/common/additional_email_addresses.jsp" />

</div>

 

<div class="section entity-websites">

<liferay-util:include  page="/html/portlet/directory/common/websites.jsp" />

</div>

 

<div class="section entity-addresses">

<liferay-util:include page="/html/portlet/directory/organization/addresses.jsp" />

</div>

 

<div class="section entity-phones">

<liferay-util:include page="/html/portlet/directory/organization/phone_numbers.jsp" />

</div>

 

<div class="section entity-services">

<liferay-util:include page="/html/portlet/directory/organization/services.jsp" />

</div>

 

<div class="section entity-comments">

<liferay-util:include page="/html/portlet/directory/organization/comments.jsp" />

</div>

</div>

 

Step 2 : add new Struts action in liferay-hook.xml

 

<portal-properties>portal.properties</portal-properties>

<struts-action>

<struts-action-path>/search/view_organization</struts-action-path>

<struts-action-impl>

com.liferay.portal.hook.action.OrganizationSearchAction

</struts-action-impl>

</struts-action>

 

Step 3 : add struts action entry in portal.properties

auth.public.paths=/search/view_organization

 

Step 4 : Create a package com.liferay.portal.hook.action and add OrganizationSearchAction.java

 

package com.liferay.portal.hook.action;

 

import com.liferay.portal.kernel.struts.BaseStrutsPortletAction;

import com.liferay.portal.kernel.struts.StrutsPortletAction;

import com.liferay.portal.kernel.util.ParamUtil;

import com.liferay.portal.model.Organization;

import com.liferay.portal.service.OrganizationLocalServiceUtil;

 

import javax.portlet.ActionRequest;

import javax.portlet.ActionResponse;

import javax.portlet.PortletConfig;

import javax.portlet.RenderRequest;

import javax.portlet.RenderResponse;

import javax.portlet.ResourceRequest;

import javax.portlet.ResourceResponse;

 

public class OrganizationSearchAction extends BaseStrutsPortletAction {

public void processAction(

StrutsPortletAction originalStrutsPortletAction,

PortletConfig portletConfig, ActionRequest actionRequest,

ActionResponse actionResponse)

throws Exception {

 

originalStrutsPortletAction.processAction(

originalStrutsPortletAction, portletConfig, actionRequest,

actionResponse);

}

 

public String render(

StrutsPortletAction originalStrutsPortletAction,

PortletConfig portletConfig, RenderRequest renderRequest,

RenderResponse renderResponse)

throws Exception {

long organizationId = ParamUtil.getLong(renderRequest, "organizationId");

Organization org = OrganizationLocalServiceUtil.getOrganization(organizationId);

renderRequest.setAttribute("organization", org);

return "/portlet/search/view_organization.jsp";

}

 

public void serveResource(

StrutsPortletAction originalStrutsPortletAction,

PortletConfig portletConfig, ResourceRequest resourceRequest,

ResourceResponse resourceResponse)

throws Exception {

 

originalStrutsPortletAction.serveResource(

originalStrutsPortletAction, portletConfig, resourceRequest,

resourceResponse);

}

}

 

Step 5: Deploy hook now organization is available for search in search portlet.

 

 

Threaded Replies Author Date
Good Explanation Muniraj saravanan July 16, 2013 7:01 AM
Dear Madam, This is a good explanation. I... Ahmed Hasan July 25, 2013 4:59 AM
What about having a auto suggestion search of... Ramkumar Chandran August 4, 2013 1:08 AM
What about having a auto suggestion search of... Ramkumar Chandran August 4, 2013 1:08 AM
As Liferay newbie (but not portlet newbie) I... Falk Pschebezin December 11, 2013 7:27 AM

Posted on 7/16/13 7:01 AM.
Dear Madam,

This is a good explanation.

I have covered Faceted Search in Chaper 14.3 my eBook "Liferay Portlet Cookbook". Can you please download the same, review the contents and give your valuable feedback. The link is http://mpowerglobal.com/download-cookbook.
Posted on 7/25/13 4:59 AM.
What about having a auto suggestion search of organization.....????
Posted on 8/4/13 1:08 AM.
What about having a auto suggestion search of organization.....????
Posted on 8/4/13 1:08 AM.
As Liferay newbie (but not portlet newbie) I adapted this. It worked after a short time. But this works only for portal administrators. All other users cannot find organizations, not even organization owners.

Do you have any suggestions to let other users find organizations in this way?
Posted on 12/11/13 7:27 AM.