Issue
- When attempting to run the script from step 2 on Importing the Search Tuning Indexes in 7.4 to import the Result Rankings data, execution fails with the following errors:
startup failed:
Script1.groovy: 3: unable to resolve class com.liferay.registry.Registry
@ line 3, column 1.
import com.liferay.registry.Registry;
^
Script1.groovy: 4: unable to resolve class com.liferay.registry.RegistryUtil
@ line 4, column 1.
import com.liferay.registry.RegistryUtil;
^
Script1.groovy: 1: unable to resolve class com.liferay.portal.instances.service.PortalInstancesLocalService
@ line 1, column 1.
import com.liferay.portal.instances.service.PortalInstancesLocalService;
^
3 errors
Line 1: import com.liferay.portal.instances.service.PortalInstancesLocalService;
Line 2: import com.liferay.portal.search.tuning.rankings.storage.RankingsDatabaseImporter;
Line 3: import com.liferay.registry.Registry;
Line 4: import com.liferay.registry.RegistryUtil;
Line 5:
Line 6: Registry registry = RegistryUtil.getRegistry();
Line 7:
Line 8: PortalInstancesLocalService portalInstancesLocalService = registry.getServices(PortalInstancesLocalService.class, null)[0];
Line 9: RankingsDatabaseImporter rankingsDatabaseImporter = registry.getServices(RankingsDatabaseImporter.class, null)[0];
Line 10:
Line 11: for (long companyId : portalInstancesLocalService.getCompanyIds()) {
Line 12: rankingsDatabaseImporter.populateDatabase(companyId);
Line 13: }
Environment
-
2025.Q1
Resolution
- Run the following script instead:
import com.liferay.portal.kernel.module.util.SystemBundleUtil
import com.liferay.portal.kernel.util.PortalUtil
import com.liferay.portal.search.tuning.rankings.storage.RankingsDatabaseImporter
import org.osgi.framework.BundleContext
import org.osgi.util.tracker.ServiceTracker
BundleContext bundleContext = SystemBundleUtil.getBundleContext();
ServiceTracker rankingsDatabaseImporterTracker = new ServiceTracker(
bundleContext, RankingsDatabaseImporter.class.getName(), null
)
try {
rankingsDatabaseImporterTracker.open()
RankingsDatabaseImporter rankingsDatabaseImporter = (RankingsDatabaseImporter) rankingsDatabaseImporterTracker.getService()
for (long companyId : PortalUtil.getCompanyIds()) {
rankingsDatabaseImporter.populateDatabase(companyId);
}
} finally {
rankingsDatabaseImporterTracker.close()
}
-
Enabling INFO logging for
com.liferay.portal.search.tuning.rankings.web.internal.storage.RankingsDatabaseImporterImplbefore running the script is recommended.
Additional Information
- The problematic script currently posted on Importing the Search Tuning Indexes in 7.4 shall be updated with the one mentioned in the resolution.