Skip to content

lmarqs/liferay-training

Repository files navigation

Introduction to Liferay development

This source is a implementation of the training materials to Liferay development.

All steps to create this app can be found at Developing a Web Application section.

Update Search to Liferay 7.1

More information about how Liferay search api works can be found at:

Section 7.0 7.1
Search Link Coming soon
Introduction to liferay search Link Coming soon
Leveraging Search Link Coming soon

Steps

All changes are made on the guestbook-service module, search package. The steps are merged from this PR: #2 - Update Searching to Liferay 7.1

  1. Update dependencies.

    Add the api and spi search packages as dependencies on build.gradle.

    compileOnly group: "com.liferay", name: "com.liferay.portal.search.api", version: "2.0.0"
    compileOnly group: "com.liferay", name: "com. liferay.portal.search.spi", version: "2.0.0"

    See build.gradle.

  2. Refactor the BaseIndexer constructor.

    1. Implement the interface BaseSearcher.

      • Sets the default selected field names;
      • Makes the search results permissions-aware at search time, as well as in the index;
      • Sets filter search to true, enabling a document-by-document check of the search results’ VIEW permissions.

      See GuestbookSearcher.

    2. Create the SearchRegistrar components to register the new search service

      Those services do the following:

      • Sets the default selected field names;
      • Sets the default selected localized field names;
      • Sets the contributors (modelIndexWriterContributor and modelSummaryContributor);
      • Allow search on all languages.

      See EntrySearchRegistrar and GuestbookSearchRegistrar.

  3. Implement ModelPreFilterContributor.

    The same feature of BaseIndexer#postProcessContextBooleanFilter. This method is invoked while the main search query is being constructed.

    • Ensures that entities with the status STATUS_IN_TRASH are not added to the query.

    See EntryModelPreFilterContributor and GuestbookModelPreFilterContributor.

  4. Implement KeywordQueryContributor.

    The same feature of BaseIndexer#postProcessSearchQuery.

    • Add the localized values of any full text fields that might contribute to search relevance.

    See EntryKeywordQueryContributor and GuestbookKeywordQueryContributor.

  5. Implement ModelDocumentContributor.

    The same feature of BaseIndexer#doGetDocument.

    • Select the entity’s fields to build a search document that’s indexed by the search engine.

    See EntryModelDocumentContributor and GuestbookModelDocumentContributor.

  6. Implement ModelSummaryContributor.

    The same feature of BaseIndexer#createSummary.

    • Show a condensed, text-based version of the entity that can be displayed generically.

    See EntryModelSummaryContributor and GuestbookModelSummaryContributor.

  7. Implement ModelIndexerWriterContributor.

    The same feature of BaseIndexer#doReindex with an addition of a batch re-indexer.

    • Implements the classes which gets called when an entity is updated or a user explicitly triggers a reindex.
    • Reindex the Entry records when the Guestbook is guestbook has its name changed.

    See EntryModelSummaryContributor and GuestbookModelSummaryContributor.

  8. Deprecate the implementations of BaseIndexer.

Notice

  1. The implementation of hasPermission and doDelete is no longer needed.

  2. On the original doc (setting-the-guestbook-status and setting-the-entry-workflow-status) does not mention the use of @Indexable annotation above the updateStatus methods. It turns out that without this annotation, records are not displayed in search results after being approved in the workflow. Those annotation had been added on this commit before the updating to 7.1.

Use cases

Happy day

This simple use case checks the integration between the guestbook app and the Liferay's search engine.

  1. Add a Entry;
  2. Check if the entry is displayed in search results.

Happy day - Sequence diagram

Using permissions

This use case demonstrates how to test if the permission aware is enable for search.

  1. Add a Entry
  2. Check if the entry is displayed in search results;
  3. Log out from the portal;
  4. Check if the entry is not displayed in search results;

Using permissions - Sequence diagram

Using workflow

Workflow is a review process that ensures a submitted entity isn’t published before it’s reviewed. Enabling workflow in the guestbook application also prevents unapproved entries from appearing in search results.

The guestbook application allows to check if the search is integrated with workflow following this steps:

  1. Create a guestbook entry;
  2. Check if the entry is not displayed in search results;
  3. Approve the new entry in workflow;
  4. Check if the entry is displayed in search results.

Using workflow - Sequence diagram

Releases

No releases published

Packages

No packages published

Languages