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

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

Introduction

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

Prototype

public Document getDocument(T object) throws SearchException;

Source Link

Usage

From source file:com.liferay.bookmarks.service.impl.BookmarksEntryLocalServiceImpl.java

License:Open Source License

@Override
public void setTreePaths(final long folderId, final String treePath, final boolean reindex)
        throws PortalException {

    if (treePath == null) {
        throw new IllegalArgumentException("Tree path is null");
    }//from   w ww. j  a v  a  2  s. c  om

    final IndexableActionableDynamicQuery indexableActionableDynamicQuery = getIndexableActionableDynamicQuery();

    indexableActionableDynamicQuery.setAddCriteriaMethod(new ActionableDynamicQuery.AddCriteriaMethod() {

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

            dynamicQuery.add(folderIdProperty.eq(folderId));

            Property treePathProperty = PropertyFactoryUtil.forName("treePath");

            dynamicQuery
                    .add(RestrictionsFactoryUtil.or(treePathProperty.isNull(), treePathProperty.ne(treePath)));
        }

    });

    final Indexer<BookmarksEntry> indexer = IndexerRegistryUtil.getIndexer(BookmarksEntry.class);

    indexableActionableDynamicQuery
            .setPerformActionMethod(new ActionableDynamicQuery.PerformActionMethod<BookmarksEntry>() {

                @Override
                public void performAction(BookmarksEntry entry) throws PortalException {

                    entry.setTreePath(treePath);

                    updateBookmarksEntry(entry);

                    if (!reindex) {
                        return;
                    }

                    Document document = indexer.getDocument(entry);

                    indexableActionableDynamicQuery.addDocuments(document);
                }

            });

    indexableActionableDynamicQuery.performActions();
}

From source file:com.liferay.journal.service.impl.JournalArticleLocalServiceImpl.java

License:Open Source License

@Override
public void setTreePaths(final long folderId, final String treePath, final boolean reindex)
        throws PortalException {

    if (treePath == null) {
        throw new IllegalArgumentException("Tree path is null");
    }// ww  w  . j a  v a2 s .  co  m

    final IndexableActionableDynamicQuery indexableActionableDynamicQuery = getIndexableActionableDynamicQuery();

    indexableActionableDynamicQuery.setAddCriteriaMethod(new ActionableDynamicQuery.AddCriteriaMethod() {

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

            dynamicQuery.add(folderIdProperty.eq(folderId));

            Property treePathProperty = PropertyFactoryUtil.forName("treePath");

            dynamicQuery
                    .add(RestrictionsFactoryUtil.or(treePathProperty.isNull(), treePathProperty.ne(treePath)));
        }

    });

    final Indexer<JournalArticle> indexer = IndexerRegistryUtil.getIndexer(JournalArticle.class.getName());

    indexableActionableDynamicQuery
            .setPerformActionMethod(new ActionableDynamicQuery.PerformActionMethod<JournalArticle>() {

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

                    article.setTreePath(treePath);

                    updateJournalArticle(article);

                    if (!reindex) {
                        return;
                    }

                    com.liferay.portal.kernel.search.Document document = indexer.getDocument(article);

                    indexableActionableDynamicQuery.addDocuments(document);
                }

            });

    indexableActionableDynamicQuery.performActions();
}