Search Organization using Facets Search

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.

 

 

Blogs
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.
What about having a auto suggestion search of organization.....????
What about having a auto suggestion search of organization.....????
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?
Hello
I tried this approach since I have problems displaying Organizations when using FacetSearch.
I did not manage to get it working under Liferay 6.2, can you give me more information on where excatly to put the code segment in init.jsp?
Thank you and best regards
Update: We solved this problem by implementing a corresponding OrganizationAssetRenderer and OrganizationAssetRendererFactory Class. (Liferay 6.2)