Example usage for com.liferay.portal.kernel.search Indexer getClassName

List of usage examples for com.liferay.portal.kernel.search Indexer getClassName

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.search Indexer getClassName.

Prototype

public String getClassName();

Source Link

Usage

From source file:com.liferay.journal.search.JournalArticleIndexer.java

License:Open Source License

@Override
public void reindexDDMStructures(List<Long> ddmStructureIds) throws SearchException {

    if (_indexStatusManager.isIndexReadOnly() || !isIndexerEnabled()) {
        return;/*from   w w w  .j  av  a 2  s . c o  m*/
    }

    try {
        final String[] ddmStructureKeys = new String[ddmStructureIds.size()];

        for (int i = 0; i < ddmStructureIds.size(); i++) {
            long ddmStructureId = ddmStructureIds.get(i);

            DDMStructure ddmStructure = _ddmStructureLocalService.getDDMStructure(ddmStructureId);

            ddmStructureKeys[i] = ddmStructure.getStructureKey();
        }

        final Indexer<JournalArticle> indexer = _indexerRegistry.nullSafeGetIndexer(JournalArticle.class);

        final ActionableDynamicQuery actionableDynamicQuery = _journalArticleLocalService
                .getActionableDynamicQuery();

        actionableDynamicQuery.setAddCriteriaMethod(new ActionableDynamicQuery.AddCriteriaMethod() {

            @Override
            public void addCriteria(DynamicQuery dynamicQuery) {
                Property ddmStructureKey = PropertyFactoryUtil.forName("DDMStructureKey");

                dynamicQuery.add(ddmStructureKey.in(ddmStructureKeys));

                if (!isIndexAllArticleVersions()) {
                    Property statusProperty = PropertyFactoryUtil.forName("status");

                    Integer[] statuses = { WorkflowConstants.STATUS_APPROVED,
                            WorkflowConstants.STATUS_IN_TRASH };

                    dynamicQuery.add(statusProperty.in(statuses));
                }
            }

        });
        actionableDynamicQuery
                .setPerformActionMethod(new ActionableDynamicQuery.PerformActionMethod<JournalArticle>() {

                    @Override
                    public void performAction(JournalArticle article) throws PortalException {

                        try {
                            indexer.reindex(indexer.getClassName(), article.getResourcePrimKey());
                        } catch (Exception e) {
                            throw new PortalException(e);
                        }
                    }

                });

        actionableDynamicQuery.performActions();
    } catch (Exception e) {
        throw new SearchException(e);
    }
}