Would you like to modify the search summaries, indexes, and queries available in your portal instance? Developing an Indexer Post Processor hook lets you do just that. The indexer hook implements a post processing system on top of the existing indexer to allow plugin hook developers to modify their search, index, and query capabilities. Let’s run through a simple example to preview what you can accomplish with an indexer hook. For our example, we’re going to add Job Title into the User Indexer so we can search for users by their Job Title.
In your existing example-hook project, open the liferay-hook.xml file and insert the following lines before the closing </hook> tag:
The <indexer-class-name/> tag clarifies the model entity for the indexer. Furthermore, the <indexer-post-processor-impl/> tag clarifies the implementation of the interface.
Create a new class in the docroot/WEB-INF/src/com/liferay/hook/indexer directory of your example-hook named SampleIndexerPostProcessor. Then replace the Java source file’s contents with the following lines:
Notice the SampleIndexerPostProcessor class extends Liferay’s BaseIndexerPostProcessor base implementation. Then we add our own logic to enable users to search for Job Title amongst all the portal’s users. Thus, we’ve added a new feature for the User Indexer. Let’s give it a try!
Navigate to the Control Panel → Users and Organizations and make sure a user has a job title, which can be added in any user’s My Account interface. Then test out the indexer hook by searching for that job title.
Figure 11.5: In this example, searching for Nose Model returns one user with the matching job title.
In the next section, we’ll explore more hooks that allow for customizing Liferay’s core features.