Issue
- As a developer, I would like to trigger reindex on my portal using a script, instead of running it via UI. This would for example bring the benefits of schedulable reindexing.
Environment
- Liferay DXP 7.1
- Liferay DXP 7.2
- Liferay DXP 7.3
Resolution
Indeed, there is no 'official recommendation' exist about triggering reindexing via scripts, CLI/shell commands, nor API calls.
However, this sample Groovy script may be used in order to get closer to such expectations (Scripts can run at menu Server Administration -> Script):
def companyId = com.liferay.portal.kernel.util.PortalUtil.getCompanyId(actionRequest);def userId = java.lang.Long.parseLong(userInfo.get("liferay.user.id"));
com.liferay.portal.kernel.search.IndexWriterHelperUtil.reindex(userId, "reindex", [companyId] as long[], null);
The script above reindexes one particular company, from where the script has been executed. Although, using PortalUtil.getCompanyId() it should be possible to trigger the reindex on all the required companyId.
During reindex, expect the following warnings which may appear in Liferay logs:
org.apache.tika.config.InitializableProblemHandler$3 handleInitializableProblem
WARNING: TIFFImageWriter not loaded. tiff files will not be processed
See https://pdfbox.apache.org/2.0/dependencies.html#jai-image-io
for optional dependencies.
J2KImageReader not loaded. JPEG2000 files will not be processed.
See https://pdfbox.apache.org/2.0/dependencies.html#jai-image-io
for optional dependencies.
org.apache.tika.config.InitializableProblemHandler$3 handleInitializableProblem
WARNING: org.xerial's sqlite-jdbc is not loaded.
Please provide the jar on your classpath to parse sqlite files.
See tika-parsers/pom.xml for the correct version.
After understanding the reindex may not have effect on the highlighted type of files - such behavior is intended -, these warnings may be safely ignored.
Additional Information
- Please note: Such custom scripts may only be applied in production at your own discretion, after thorough testing.