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 |
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
-
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.
-
Refactor the
BaseIndexer
constructor.-
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
. -
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
andmodelSummaryContributor
); - Allow search on all languages.
-
-
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
andGuestbookModelPreFilterContributor
. -
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
andGuestbookKeywordQueryContributor
. -
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
andGuestbookModelDocumentContributor
. -
Implement
ModelSummaryContributor
.The same feature of
BaseIndexer#createSummary
.- Show a condensed, text-based version of the entity that can be displayed generically.
See
EntryModelSummaryContributor
andGuestbookModelSummaryContributor
. -
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
andGuestbookModelSummaryContributor
. -
Deprecate the implementations of BaseIndexer.
Notice
The implementation of
hasPermission
anddoDelete
is no longer needed.On the original doc (setting-the-guestbook-status and setting-the-entry-workflow-status) does not mention the use of
@Indexable
annotation above theupdateStatus
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.
This simple use case checks the integration between the guestbook app and the Liferay's search engine.
- Add a Entry;
- Check if the entry is displayed in search results.
This use case demonstrates how to test if the permission aware is enable for search.
- Add a Entry
- Check if the entry is displayed in search results;
- Log out from the portal;
- Check if the entry is not displayed in search results;
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:
- Create a guestbook entry;
- Check if the entry is not displayed in search results;
- Approve the new entry in workflow;
- Check if the entry is displayed in search results.