Enabling Search and Indexing for Guestbooks

In this section, you’ll create the classes that control these aspects of the search functionality:

  • Registration:

    • GuestbookSearchRegistrar registers the search services to the search framework for the Guestbook entity.
  • Indexing:

    • GuestbookModelDocumentContributor controls which Guestbook fields are indexed in the search engine.

    • GuestbookModelIndexerWriterContributor configures the re-indexing and batch re-indexing behavior for Guestbooks.

  • Querying:

    • GuestbookKeywordQueryContributor contributes clauses to the ongoing search query.

    • GuestbookModelPreFilterContributor controls how search results are filtered before they’re returned from the search engine.

  • Generating Result Summaries:

    • GuestbookModelSummaryContributor constructs the result summary for Guestbooks, including specifying which fields to use.

After creating the search classes, you’ll modify the service layer to update the search index when a guestbook is persisted. Specifically, GuestbookLocalServiceImpl’s addGuestbook, updateGuestbook, and deleteGuestbook methods are updated to invoke the guestbook indexer.

In prior versions of Liferay DXP, search and indexing was accomplished with one *Indexer class that extended BaseIndexer. In Liferay DXP 7.1 is a new pattern that relies on composition instead of inheritance. If you want to use the old approach, feel free to extend BaseIndexer. It’s still supported.

Since there’s no reason to search for guestbooks in the UI, only back-end work is necessary.

Let’s Go!

« Search and IndexingUnderstanding Search and Indexing »
Was this article helpful?
0 out of 0 found this helpful