Thursday 11 August 2016

liferay indexer hook

post processor indexer HookIndexer hook implements a post processing system on top of the existing indexer.

For example go to Users and Organizations and search based on type.

You wont get the result based on type.

To achieve this just follow the below steps.

Step 1 :

Create a liferay project and choose plugin type as hook and finish.

Step 2 :

Modify in liferay-hook.xml

<?xml version="1.0"?>

<!DOCTYPE hook PUBLIC "-//Liferay//DTD Hook 6.1.0//EN" "http://www.liferay.com/dtd/liferay-hook_6_1_0.dtd">

<hook>

<indexer-post-processor>

<indexer-class-name>com.liferay.portal.model.Organization</indexer-class-name>

<indexer-post-processor-impl>com.javaeasyforu.MyCustomPostIndexer</indexer-post-processor-impl>

</indexer-post-processor>

</hook>

Step 3 :

create a package and java class

docroot/WEB-INF/src  ---->create a class as MyCustomPostIndexer

package com.javaeasyforu;

import com.liferay.portal.kernel.search.BaseIndexerPostProcessor;

import com.liferay.portal.kernel.search.Document;

import com.liferay.portal.kernel.search.Field;

import com.liferay.portal.model.Organization;

public class MyCustomPostIndexer extends BaseIndexerPostProcessor 

{

public void postProcessDocument(Document document, Object object)throws Exception {

  Organization orgEntity = (Organization) object;

  String indexerOrgTitle = null;

  try 

  {

    indexerOrgTitle = orgEntity.getType();

  }

  catch (Exception e) 

  {

    e.printStackTrace();

  }

  if (indexerOrgTitle.length() > 0)

  {

    document.addText(Field.TITLE, indexerOrgTitle);

  }

 }

}

Step 4 Right click on project and deploy

Now go to control panel and click on Users and Organizations

Step 5 :

Search for Type and see the result

Note : It will effect only for new and update records but not for existing records. So edit for some organization and check the result.


Key Point :

Eclipse is not opening properly

# A fatal error has been detected by the Java Runtime Environment 

#

# SIGSEGV (0xb) at pc=0x00007f8e88aaa2a1, pid=7607, tid=140252668163840

Solution: After extracting eclipse you have file called config.ini inside configuration folder. Go there and add the below line at the end

org.eclipse.swt.browser.DefaultType=mozilla

No comments:

Post a Comment