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

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

Introduction

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

Prototype

public void delete(long companyId, String uid) throws SearchException;

Source Link

Usage

From source file:com.liferay.content.targeting.util.CampaignUtil.java

License:Open Source License

public static List<Campaign> getCampaigns(Hits hits) throws PortalException, SystemException {

    List<Document> documents = hits.toList();

    List<Campaign> campaigns = new ArrayList<Campaign>(documents.size());

    for (Document document : documents) {
        long campaignId = GetterUtil.getLong(document.get("campaignId"));

        Campaign campaign = CampaignLocalServiceUtil.fetchCampaign(campaignId);

        if (campaign == null) {
            campaigns = null;//from   w w  w  . j a  v a  2s.c  o  m

            Indexer indexer = IndexerRegistryUtil.getIndexer(Campaign.class);

            long companyId = GetterUtil.getLong(document.get(Field.COMPANY_ID));

            indexer.delete(companyId, document.getUID());
        } else if (campaigns != null) {
            campaigns.add(campaign);
        }
    }

    return campaigns;
}

From source file:com.liferay.content.targeting.util.UserSegmentUtil.java

License:Open Source License

public static List<UserSegment> getUserSegments(Hits hits) throws PortalException, SystemException {

    List<Document> documents = hits.toList();

    List<UserSegment> userSegments = new ArrayList<UserSegment>(documents.size());

    for (com.liferay.portal.kernel.search.Document document : documents) {
        long userSegmentId = GetterUtil.getLong(document.get("userSegmentId"));

        UserSegment userSegment = UserSegmentLocalServiceUtil.fetchUserSegment(userSegmentId);

        if (userSegment == null) {
            userSegments = null;//from  w w w  .  j  a  v a2 s.  c  o  m

            Indexer indexer = IndexerRegistryUtil.getIndexer(UserSegment.class);

            long companyId = GetterUtil.getLong(document.get(Field.COMPANY_ID));

            indexer.delete(companyId, document.getUID());
        } else if (userSegments != null) {
            userSegments.add(userSegment);
        }
    }

    return userSegments;
}

From source file:com.liferay.dynamic.data.lists.service.impl.DDLRecordLocalServiceImpl.java

License:Open Source License

protected List<DDLRecord> getRecords(Hits hits) throws PortalException {
    List<DDLRecord> records = new ArrayList<>();

    for (Document document : hits.toList()) {
        long recordId = GetterUtil.getLong(document.get(com.liferay.portal.kernel.search.Field.ENTRY_CLASS_PK));

        try {/*w  ww  .j a va 2  s. co  m*/
            DDLRecord record = getRecord(recordId);

            records.add(record);
        } catch (NoSuchRecordException nsre) {
            if (_log.isWarnEnabled()) {
                _log.warn("DDL record index is stale and contains record " + recordId, nsre);
            }

            long companyId = GetterUtil
                    .getLong(document.get(com.liferay.portal.kernel.search.Field.COMPANY_ID));

            Indexer<DDLRecord> indexer = getDDLRecordIndexer();

            indexer.delete(companyId, document.getUID());
        }
    }

    return records;
}

From source file:com.liferay.dynamic.data.mapping.service.impl.DDMFormInstanceRecordLocalServiceImpl.java

License:Open Source License

protected List<DDMFormInstanceRecord> getFormInstanceRecords(Hits hits) throws PortalException {

    List<DDMFormInstanceRecord> formInstanceRecords = new ArrayList<>();

    for (Document document : hits.toList()) {
        long recordId = GetterUtil.getLong(document.get(Field.ENTRY_CLASS_PK));

        try {//from  w w  w.j  av a 2s.c  o m
            DDMFormInstanceRecord formInstanceRecord = getFormInstanceRecord(recordId);

            formInstanceRecords.add(formInstanceRecord);
        } catch (NoSuchFormInstanceRecordException nsfire) {
            if (_log.isWarnEnabled()) {
                _log.warn("DDM form instance record index is stale and" + "contains record " + recordId,
                        nsfire);
            }

            long companyId = GetterUtil.getLong(document.get(Field.COMPANY_ID));

            Indexer<DDMFormInstanceRecord> indexer = getDDMFormInstanceRecordIndexer();

            indexer.delete(companyId, document.getUID());
        }
    }

    return formInstanceRecords;
}

From source file:com.liferay.experts.questions.util.QuestionsUtil.java

License:Open Source License

public static List<Question> getQuestions(Hits hits) throws PortalException, SystemException {

    List<Question> questions = new ArrayList<Question>();

    List<Document> documents = hits.toList();

    for (Document document : documents) {
        long questionId = GetterUtil.getLong(document.get(Field.ENTRY_CLASS_PK));

        try {/*from w  w w  . ja v a2 s.c o m*/
            Question question = QuestionLocalServiceUtil.getQuestion(questionId);

            questions.add(question);
        } catch (NoSuchQuestionException nsae) {
            Indexer indexer = IndexerRegistryUtil.getIndexer(Question.class);

            long companyId = GetterUtil.getLong(document.get(Field.COMPANY_ID));

            indexer.delete(companyId, String.valueOf(questionId));
        }
    }

    return questions;
}

From source file:com.liferay.journal.util.impl.JournalUtil.java

License:Open Source License

/**
 * @deprecated As of 4.0.0, with no direct replacement
 *///from w ww . j av  a 2s  .c o  m
@Deprecated
public static List<JournalArticle> getArticles(Hits hits) throws PortalException {

    List<com.liferay.portal.kernel.search.Document> documents = hits.toList();

    List<JournalArticle> articles = new ArrayList<>(documents.size());

    for (com.liferay.portal.kernel.search.Document document : documents) {
        String articleId = document.get(Field.ARTICLE_ID);
        long groupId = GetterUtil.getLong(document.get(Field.SCOPE_GROUP_ID));

        JournalArticle article = JournalArticleLocalServiceUtil.fetchLatestArticle(groupId, articleId,
                WorkflowConstants.STATUS_APPROVED);

        if (article == null) {
            articles = null;

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

            long companyId = GetterUtil.getLong(document.get(Field.COMPANY_ID));

            indexer.delete(companyId, document.getUID());
        } else if (articles != null) {
            articles.add(article);
        }
    }

    return articles;
}

From source file:com.liferay.portlet.journal.util.JournalUtil.java

License:Open Source License

public static Tuple getArticles(Hits hits) throws PortalException, SystemException {

    List<JournalArticle> articles = new ArrayList<JournalArticle>();
    boolean corruptIndex = false;

    List<com.liferay.portal.kernel.search.Document> documents = hits.toList();

    for (com.liferay.portal.kernel.search.Document document : documents) {
        long groupId = GetterUtil.getLong(document.get(Field.GROUP_ID));
        String articleId = document.get("articleId");

        try {/*from   www.  ja  va  2 s .  c o  m*/
            JournalArticle article = JournalArticleLocalServiceUtil.getArticle(groupId, articleId);

            articles.add(article);
        } catch (NoSuchArticleException nsae) {
            corruptIndex = true;

            Indexer indexer = IndexerRegistryUtil.getIndexer(JournalArticle.class);

            long companyId = GetterUtil.getLong(document.get(Field.COMPANY_ID));

            indexer.delete(companyId, document.getUID());
        }
    }

    return new Tuple(articles, corruptIndex);
}

From source file:com.liferay.portlet.usersadmin.util.UsersAdminImpl.java

License:Open Source License

public Tuple getOrganizations(Hits hits) throws PortalException, SystemException {

    List<Organization> organizations = new ArrayList<Organization>();
    boolean corruptIndex = false;

    List<Document> documents = hits.toList();

    for (Document document : documents) {
        long organizationId = GetterUtil.getLong(document.get(Field.ORGANIZATION_ID));

        try {/*  w  w w .j  a  v  a  2  s . c  om*/
            Organization organization = OrganizationLocalServiceUtil.getOrganization(organizationId);

            organizations.add(organization);
        } catch (NoSuchOrganizationException nsoe) {
            corruptIndex = true;

            Indexer indexer = IndexerRegistryUtil.getIndexer(Organization.class);

            long companyId = GetterUtil.getLong(document.get(Field.COMPANY_ID));

            indexer.delete(companyId, document.getUID());
        }
    }

    return new Tuple(organizations, corruptIndex);
}

From source file:com.liferay.portlet.usersadmin.util.UsersAdminImpl.java

License:Open Source License

public Tuple getUsers(Hits hits) throws PortalException, SystemException {
    List<User> users = new ArrayList<User>();
    boolean corruptIndex = false;

    List<Document> documents = hits.toList();

    for (Document document : documents) {
        long userId = GetterUtil.getLong(document.get(Field.USER_ID));

        try {/*from  w w w .  j av  a2s.c  o  m*/
            User user = UserLocalServiceUtil.getUser(userId);

            users.add(user);
        } catch (NoSuchUserException nsue) {
            corruptIndex = true;

            Indexer indexer = IndexerRegistryUtil.getIndexer(User.class);

            long companyId = GetterUtil.getLong(document.get(Field.COMPANY_ID));

            indexer.delete(companyId, document.getUID());
        }
    }

    return new Tuple(users, corruptIndex);
}