Example usage for com.liferay.portal.kernel.search Document addUID

List of usage examples for com.liferay.portal.kernel.search Document addUID

Introduction

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

Prototype

public void addUID(String portletId, String field1);

Source Link

Usage

From source file:com.inkwell.internet.slogan.search.SloganIndexer.java

License:Open Source License

@Override
protected void doDelete(Object obj) throws Exception {

    Slogan slogan = (Slogan) obj;//  w  w w  .  j  a  v a  2 s. c o m
    Document document = new DocumentImpl();

    document.addUID(PORTLET_ID, slogan.getPrimaryKey());

    SearchEngineUtil.deleteDocument(slogan.getCompanyId(), document.get(Field.UID));

}

From source file:com.inkwell.internet.slogan.search.SloganIndexer.java

License:Open Source License

@Override
protected Document doGetDocument(Object obj) throws Exception {

    Slogan slogan = (Slogan) obj;/*from   w ww  .j  a  v  a  2  s  . c  o m*/
    long companyId = slogan.getCompanyId();
    long groupId = getParentGroupId(slogan.getGroupId());
    long scopeGroupId = slogan.getGroupId();
    long userId = slogan.getUserId();
    long resourcePrimKey = slogan.getPrimaryKey();
    String title = slogan.getSloganText();
    String content = slogan.getSloganText();
    String description = slogan.getSloganText();
    Date modifiedDate = slogan.getSloganDate();

    long[] assetCategoryIds = AssetCategoryLocalServiceUtil.getCategoryIds(Slogan.class.getName(),
            resourcePrimKey);

    List<AssetCategory> categories = AssetCategoryLocalServiceUtil.getCategories(Slogan.class.getName(),
            resourcePrimKey);

    String[] assetCategoryNames = StringUtil.split(ListUtil.toString(categories, "name"));

    // EE lets you do this quicker: 

    // String[] assetCategoryNames =
    //     AssetCategoryLocalServiceUtil.getCategoryNames(
    //         Slogan.class.getName(), resourcePrimKey);

    String[] assetTagNames = AssetTagLocalServiceUtil.getTagNames(Slogan.class.getName(), resourcePrimKey);

    Document document = new DocumentImpl();

    document.addUID(PORTLET_ID, resourcePrimKey);

    document.addModifiedDate(modifiedDate);

    document.addKeyword(Field.COMPANY_ID, companyId);
    document.addKeyword(Field.PORTLET_ID, PORTLET_ID);
    document.addKeyword(Field.GROUP_ID, groupId);
    document.addKeyword(Field.SCOPE_GROUP_ID, scopeGroupId);
    document.addKeyword(Field.USER_ID, userId);
    document.addText(Field.TITLE, title);
    document.addText(Field.CONTENT, content);
    document.addText(Field.DESCRIPTION, description);
    document.addKeyword(Field.ASSET_CATEGORY_IDS, assetCategoryIds);
    document.addKeyword("assetCategoryNames", assetCategoryNames);
    //document.addKeyword(Field.ASSET_CATEGORY_NAMES, assetCategoryNames);
    document.addKeyword(Field.ASSET_TAG_NAMES, assetTagNames);

    document.addKeyword(Field.ENTRY_CLASS_NAME, Slogan.class.getName());
    document.addKeyword(Field.ENTRY_CLASS_PK, resourcePrimKey);

    return document;
}

From source file:com.liferay.alloy.mvc.BaseAlloyIndexer.java

License:Open Source License

@Override
protected void doDelete(Object obj) throws Exception {
    BaseModel<?> baseModel = (BaseModel<?>) obj;

    Document document = new DocumentImpl();

    document.addUID(portletId, String.valueOf(baseModel.getPrimaryKeyObj()));

    AuditedModel auditedModel = (AuditedModel) obj;

    SearchEngineUtil.deleteDocument(getSearchEngineId(), auditedModel.getCompanyId(), document.get(Field.UID));
}

From source file:com.liferay.configuration.admin.web.internal.search.ConfigurationModelIndexer.java

License:Open Source License

@Override
protected void doDelete(ConfigurationModel configurationModel) throws Exception {

    Document document = newDocument();

    document.addUID(ConfigurationAdminPortletKeys.SYSTEM_SETTINGS, configurationModel.getFactoryPid());

    _indexWriterHelper.deleteDocument(getSearchEngineId(), CompanyConstants.SYSTEM, document.get(Field.UID),
            isCommitImmediately());//from  w w  w. ja v a2 s  . c o m
}

From source file:com.liferay.configuration.admin.web.internal.search.ConfigurationModelIndexer.java

License:Open Source License

@Override
protected Document doGetDocument(ConfigurationModel configurationModel) throws Exception {

    Document document = newDocument();

    document.addUID(ConfigurationAdminPortletKeys.SYSTEM_SETTINGS, configurationModel.getID());
    document.addKeyword(FieldNames.CONFIGURATION_MODEL_FACTORY_PID, configurationModel.getFactoryPid());
    document.addKeyword(FieldNames.CONFIGURATION_MODEL_ID, configurationModel.getID());
    document.addKeyword(Field.COMPANY_ID, CompanyConstants.SYSTEM);

    ResourceBundleLoader resourceBundleLoader = _resourceBundleLoaderProvider
            .getResourceBundleLoader(configurationModel.getBundleSymbolicName());

    document.addLocalizedText(Field.DESCRIPTION,
            _translate(resourceBundleLoader, GetterUtil.getString(configurationModel.getDescription())));

    document.addKeyword(Field.ENTRY_CLASS_NAME, getClassName());

    AttributeDefinition[] requiredAttributeDefinitions = configurationModel
            .getAttributeDefinitions(ObjectClassDefinition.ALL);

    List<String> attributeNames = new ArrayList<>(requiredAttributeDefinitions.length);

    List<String> attributeDescriptions = new ArrayList<>(requiredAttributeDefinitions.length);

    for (AttributeDefinition attributeDefinition : requiredAttributeDefinitions) {

        attributeNames.add(attributeDefinition.getName());
        attributeDescriptions.add(attributeDefinition.getDescription());
    }//from   w  w  w  . jav a2 s  .  c  o m

    document.addKeyword(FieldNames.CONFIGURATION_MODEL_ATTRIBUTE_NAME,
            attributeNames.toArray(new String[attributeNames.size()]));
    document.addText(FieldNames.CONFIGURATION_MODEL_ATTRIBUTE_DESCRIPTION,
            attributeDescriptions.toArray(new String[attributeDescriptions.size()]));

    document.addLocalizedText(Field.TITLE,
            _translate(resourceBundleLoader, GetterUtil.getString(configurationModel.getName())));

    return document;
}

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

License:Open Source License

@Override
protected void doDelete(Object obj) throws Exception {
    Campaign campaign = (Campaign) obj;//from  www.j  a v a2s.  com

    Document document = new DocumentImpl();

    document.addUID(PORTLET_ID, campaign.getCampaignId());

    SearchEngineUtil.deleteDocument(getSearchEngineId(), campaign.getCompanyId(), document.get(Field.UID));
}

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

License:Open Source License

@Override
protected void doDelete(Object obj) throws Exception {
    UserSegment userSegment = (UserSegment) obj;

    Document document = new DocumentImpl();

    document.addUID(PORTLET_ID, userSegment.getUserSegmentId());

    SearchEngineUtil.deleteDocument(getSearchEngineId(), userSegment.getCompanyId(), document.get(Field.UID));
}

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

License:Open Source License

@Override
protected Document doGetDocument(JournalArticle journalArticle) throws Exception {

    Document document = getBaseModelDocument(CLASS_NAME, journalArticle);

    long classPK = journalArticle.getId();

    if (!isIndexAllArticleVersions()) {
        classPK = journalArticle.getResourcePrimKey();
    }/* w  ww . j a  va  2 s  .c  o m*/

    document.addUID(CLASS_NAME, classPK);

    String articleDefaultLanguageId = LocalizationUtil.getDefaultLanguageId(journalArticle.getDocument());

    String[] languageIds = LocalizationUtil.getAvailableLanguageIds(journalArticle.getDocument());

    for (String languageId : languageIds) {
        String content = extractDDMContent(journalArticle, languageId);

        String description = journalArticle.getDescription(languageId);

        String title = journalArticle.getTitle(languageId);

        if (languageId.equals(articleDefaultLanguageId)) {
            document.addText(Field.CONTENT, content);
            document.addText(Field.DESCRIPTION, description);
            document.addText("defaultLanguageId", languageId);
        }

        document.addText(LocalizationUtil.getLocalizedName(Field.CONTENT, languageId), content);
        document.addText(LocalizationUtil.getLocalizedName(Field.DESCRIPTION, languageId), description);
        document.addText(LocalizationUtil.getLocalizedName(Field.TITLE, languageId), title);
    }

    document.addKeyword(Field.FOLDER_ID, journalArticle.getFolderId());

    String articleId = journalArticle.getArticleId();

    if (journalArticle.isInTrash()) {
        articleId = TrashUtil.getOriginalTitle(articleId);
    }

    document.addKeywordSortable(Field.ARTICLE_ID, articleId);

    document.addKeyword(Field.LAYOUT_UUID, journalArticle.getLayoutUuid());
    document.addKeyword(Field.TREE_PATH, StringUtil.split(journalArticle.getTreePath(), CharPool.SLASH));
    document.addKeyword(Field.VERSION, journalArticle.getVersion());

    document.addKeyword("ddmStructureKey", journalArticle.getDDMStructureKey());
    document.addKeyword("ddmTemplateKey", journalArticle.getDDMTemplateKey());
    document.addDate("displayDate", journalArticle.getDisplayDate());
    document.addKeyword("head", JournalUtil.isHead(journalArticle));

    boolean headListable = JournalUtil.isHeadListable(journalArticle);

    document.addKeyword("headListable", headListable);

    // Scheduled listable articles should be visible in asset browser

    if (journalArticle.isScheduled() && headListable) {
        boolean visible = GetterUtil.getBoolean(document.get("visible"));

        if (!visible) {
            document.addKeyword("visible", true);
        }
    }

    addDDMStructureAttributes(document, journalArticle);

    return document;
}

From source file:com.liferay.mail.util.MessageIndexer.java

License:Open Source License

@Override
protected void doDelete(Object obj) throws Exception {
    SearchContext searchContext = new SearchContext();

    searchContext.setSearchEngineId(getSearchEngineId());

    if (obj instanceof Account) {
        Account account = (Account) obj;

        searchContext.setCompanyId(account.getCompanyId());
        searchContext.setEnd(QueryUtil.ALL_POS);
        searchContext.setSorts(SortFactoryUtil.getDefaultSorts());
        searchContext.setStart(QueryUtil.ALL_POS);

        BooleanQuery booleanQuery = BooleanQueryFactoryUtil.create(searchContext);

        booleanQuery.addRequiredTerm(Field.PORTLET_ID, PORTLET_ID);

        booleanQuery.addRequiredTerm("accountId", account.getAccountId());

        Hits hits = SearchEngineUtil.search(searchContext, booleanQuery);

        List<String> uids = new ArrayList<String>(hits.getLength());

        for (int i = 0; i < hits.getLength(); i++) {
            Document document = hits.doc(i);

            uids.add(document.get(Field.UID));
        }/* w  w w.j a  va2 s.  c  om*/

        SearchEngineUtil.deleteDocuments(getSearchEngineId(), account.getCompanyId(), uids,
                isCommitImmediately());
    } else if (obj instanceof Folder) {
        Folder folder = (Folder) obj;

        searchContext.setCompanyId(folder.getCompanyId());
        searchContext.setEnd(QueryUtil.ALL_POS);
        searchContext.setSorts(SortFactoryUtil.getDefaultSorts());
        searchContext.setStart(QueryUtil.ALL_POS);

        BooleanQuery booleanQuery = BooleanQueryFactoryUtil.create(searchContext);

        booleanQuery.addRequiredTerm(Field.PORTLET_ID, PORTLET_ID);

        booleanQuery.addRequiredTerm("folderId", folder.getFolderId());

        Hits hits = SearchEngineUtil.search(searchContext, booleanQuery);

        List<String> uids = new ArrayList<String>(hits.getLength());

        for (int i = 0; i < hits.getLength(); i++) {
            Document document = hits.doc(i);

            uids.add(document.get(Field.UID));
        }

        SearchEngineUtil.deleteDocuments(getSearchEngineId(), folder.getCompanyId(), uids,
                isCommitImmediately());
    } else if (obj instanceof Message) {
        Message message = (Message) obj;

        Document document = new DocumentImpl();

        document.addUID(PORTLET_ID, message.getMessageId());

        SearchEngineUtil.deleteDocument(getSearchEngineId(), message.getCompanyId(), document.get(Field.UID),
                isCommitImmediately());
    }
}

From source file:com.liferay.portlet.documentlibrary.util.DLFileEntryIndexer.java

License:Open Source License

@Override
protected void doDelete(Object obj) throws Exception {
    DLFileEntry dlFileEntry = (DLFileEntry) obj;

    Document document = new DocumentImpl();

    document.addUID(PORTLET_ID, dlFileEntry.getFileEntryId());

    SearchEngineUtil.deleteDocument(getSearchEngineId(), dlFileEntry.getCompanyId(), document.get(Field.UID));
}