Today we will discuss about Index Post Processor Hook in Liferay. In Liferay if you want to providing indexing on some column for searching ,sorting etc. than you can use Index Post Processor Hook.
Ex-Sign in-->Admin -->Control panel-->Users and organization--> all users. Than try to search user by First Name, Last Name,Screen Name you can search easily but than try to search user by Job Title than no result is found.So today we apply indexing on Job Title by using Index Post Processor Hook.
So lets start step by step:-
Step 1:-Create Liferay hook project
File-->New-->Liferay Plugin Project-->Provide name-->Select hook in plugin type-->Finish.
You can see snapshot in step 2 of Portal Properties Hook in Liferay
Step 2:-Create Class that provide indexing
Now create a package com.demo inside src and then create your class that extends BaseIndexerPostProcessor and override postProcessDocument method.
CustomIndexer.java
Explanation:-
document.addText(Field.TITLE,jobTitle);
Liferay already apply query on the basis of jobTitle.By using addText we send our jobTitle for indexing, so liferay use this in query.For more detail you may refer UserIndexer.java in source code.As a result for example a user has name "Developer" and other user with Job Title "Developer" than in output both result come.
Step 3:-Provide entry in liferay-hook.xml
Now open liferay-hook.xml click on overview and select indexer class Name as User and IndexerPostProcessor as your class.
This will provide entry in liferay-hook.xml as:-
liferay-hook.xml
Step 4:-Check output
Now deploy the hook and create new user and give some job title. Now try to search this user by Job title.You can easily search this user.
Note:- Only those user can be searched by Job title that are created after deployment of Hook . Previous users are not search by Job title as there is no indexing on job title.
Project Structure
You can Download Source code from Index Post Processor Hook in Liferay
Hope this will Help.....
Related Post:-