Example usage for com.liferay.portal.kernel.search Field CLASS_NAME_ID

List of usage examples for com.liferay.portal.kernel.search Field CLASS_NAME_ID

Introduction

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

Prototype

String CLASS_NAME_ID

To view the source code for com.liferay.portal.kernel.search Field CLASS_NAME_ID.

Click Source Link

Usage

From source file:com.liferay.calendar.search.CalendarBookingIndexer.java

License:Open Source License

@Override
protected Document doGetDocument(CalendarBooking calendarBooking) throws Exception {

    Document document = getBaseModelDocument(CLASS_NAME, calendarBooking);

    document.addKeyword(Field.CLASS_NAME_ID, _classNameLocalService.getClassNameId(Calendar.class));
    document.addKeyword(Field.CLASS_PK, calendarBooking.getCalendarId());

    Locale defaultLocale = LocaleUtil.getSiteDefault();

    String defaultLanguageId = LocaleUtil.toLanguageId(defaultLocale);

    String[] descriptionLanguageIds = getLanguageIds(defaultLanguageId, calendarBooking.getDescription());

    for (String descriptionLanguageId : descriptionLanguageIds) {
        String description = calendarBooking.getDescription(descriptionLanguageId);

        document.addText(LocalizationUtil.getLocalizedName(Field.DESCRIPTION, descriptionLanguageId),
                description);//ww  w  .j av  a  2s  .  c o  m
    }

    document.addKeyword(Field.RELATED_ENTRY, true);

    String[] titleLanguageIds = getLanguageIds(defaultLanguageId, calendarBooking.getTitle());

    for (String titleLanguageId : titleLanguageIds) {
        String title = calendarBooking.getTitle(titleLanguageId);

        document.addText(LocalizationUtil.getLocalizedName(Field.TITLE, titleLanguageId), title);
    }

    document.addKeyword(Field.VIEW_ACTION_ID, CalendarActionKeys.VIEW_BOOKING_DETAILS);

    String calendarBookingId = String.valueOf(calendarBooking.getCalendarBookingId());

    if (calendarBooking.isInTrash()) {
        calendarBookingId = TrashUtil.getOriginalTitle(calendarBookingId);
    }

    document.addKeyword("calendarBookingId", calendarBookingId);

    document.addText("defaultLanguageId", defaultLanguageId);
    document.addNumber("endTime", calendarBooking.getEndTime());
    document.addText("location", calendarBooking.getLocation());
    document.addNumber("startTime", calendarBooking.getStartTime());

    return document;
}

From source file:com.liferay.calendar.search.test.CalendarBookingIndexerIndexedFieldsTest.java

License:Open Source License

@Test
public void testIndexedFields() throws Exception {
    String originalTitle = "entity title";
    String translatedTitle = "entitas neve";

    String description = StringUtil.toLowerCase(RandomTestUtil.randomString());

    CalendarBooking calendarBooking = addCalendarBooking(new LocalizedValuesMap() {
        {//from   w w w.  j  ava 2 s.c om
            put(LocaleUtil.US, originalTitle);
            put(LocaleUtil.HUNGARY, translatedTitle);
        }
    }, new LocalizedValuesMap() {
        {
            put(LocaleUtil.US, originalTitle);
            put(LocaleUtil.HUNGARY, translatedTitle);
        }
    }, new LocalizedValuesMap() {
        {
            put(LocaleUtil.US, description);
            put(LocaleUtil.HUNGARY, description);
        }
    });

    Map<String, String> map = new HashMap<>();

    map.put(Field.CLASS_NAME_ID, String.valueOf(portal.getClassNameId(Calendar.class)));

    map.put(Field.EXPIRATION_DATE, "99950812133000");
    map.put(Field.EXPIRATION_DATE.concat("_sortable"), "9223372036854775807");
    map.put(Field.PRIORITY, "0.0");
    map.put(Field.PUBLISH_DATE, "19700101000000");
    map.put(Field.PUBLISH_DATE.concat("_sortable"), "0");
    map.put(Field.RELATED_ENTRY, "true");
    map.put(Field.STAGING_GROUP, "false");
    map.put(Field.STATUS, "0");
    map.put("viewActionId", CalendarActionKeys.VIEW_BOOKING_DETAILS);

    populateTitle(originalTitle, map);

    populateTranslatedTitle(translatedTitle, map);

    CalendarResource calendarResource = calendarBooking.getCalendarResource();

    populateCalendarResource(calendarResource, map);

    Calendar calendar = calendarResource.getDefaultCalendar();

    populateCalendar(calendar, map);

    populateCalendarBooking(calendarBooking, map);

    DateFormat dateFormat = DateFormatFactoryUtil.getSimpleDateFormat("yyyyMMddHHmm");

    populateCalendarDate(Field.CREATE_DATE, calendar.getCreateDate(), dateFormat, map);
    populateCalendarDate(Field.MODIFIED_DATE, calendar.getModifiedDate(), dateFormat, map);

    calendarFieldsFixture.populateGroupRoleId(map);
    calendarFieldsFixture.populateRoleId("Owner", map);
    calendarFieldsFixture.populateUID(calendarBooking, map);

    String keywords = "nev";

    Document document = calendarSearchFixture.searchOnlyOne(keywords, LocaleUtil.HUNGARY);

    adjustDatePrecision(Field.CREATE_DATE, document, dateFormat);
    adjustDatePrecision(Field.MODIFIED_DATE, document, dateFormat);

    FieldValuesAssert.assertFieldValues(map, document, keywords);
}

From source file:com.liferay.document.library.internal.search.DLFileEntrySearchResultContributor.java

License:Open Source License

@Override
public void addRelatedModel(SearchResult searchResult, Document document, Locale locale,
        PortletRequest portletRequest, PortletResponse portletResponse) throws PortalException {

    long entryClassPK = GetterUtil.getLong(document.get(Field.ENTRY_CLASS_PK));

    FileEntry fileEntry = _dlAppLocalService.getFileEntry(entryClassPK);

    if (fileEntry != null) {
        Summary summary = _summaryFactory.getSummary(document, DLFileEntry.class.getName(),
                fileEntry.getFileEntryId(), locale, portletRequest, portletResponse);

        if (Validator.isNull(summary.getContent())) {
            summary.setContent(fileEntry.getTitle());
        }/*from ww  w  .j ava  2 s.c o m*/

        searchResult.addFileEntry(fileEntry, summary);
    } else {
        long classNameId = GetterUtil.getLong(document.get(Field.CLASS_NAME_ID));

        ClassName className = _classNameLocalService.getClassName(classNameId);

        long classPK = GetterUtil.getLong(document.get(Field.CLASS_PK));

        Summary summary = _summaryFactory.getSummary(document, className.getClassName(), classPK, locale,
                portletRequest, portletResponse);

        searchResult.setSummary(summary);
    }
}

From source file:com.liferay.dynamic.data.lists.internal.search.DDLRecordIndexer.java

License:Open Source License

@Override
protected Document doGetDocument(DDLRecord ddlRecord) throws Exception {
    Document document = getBaseModelDocument(CLASS_NAME, ddlRecord);

    DDLRecordVersion recordVersion = ddlRecord.getRecordVersion();

    DDLRecordSet recordSet = recordVersion.getRecordSet();

    document.addKeyword(Field.CLASS_NAME_ID, classNameLocalService.getClassNameId(DDLRecordSet.class));
    document.addKeyword(Field.CLASS_PK, recordSet.getRecordSetId());
    document.addKeyword(Field.CLASS_TYPE_ID, recordVersion.getRecordSetId());
    document.addKeyword(Field.RELATED_ENTRY, true);
    document.addKeyword(Field.STATUS, recordVersion.getStatus());
    document.addKeyword(Field.VERSION, recordVersion.getVersion());

    document.addText("ddmContent", extractDDMContent(recordVersion, LocaleUtil.getSiteDefault()));
    document.addKeyword("recordSetId", recordSet.getRecordSetId());
    document.addKeyword("recordSetScope", recordSet.getScope());

    DDMStructure ddmStructure = recordSet.getDDMStructure();

    DDMFormValues ddmFormValues = storageEngine.getDDMFormValues(recordVersion.getDDMStorageId());

    ddmIndexer.addAttributes(document, ddmStructure, ddmFormValues);

    return document;
}

From source file:com.liferay.dynamic.data.mapping.internal.search.DDMFormInstanceRecordIndexer.java

License:Open Source License

@Override
protected Document doGetDocument(DDMFormInstanceRecord ddmFormInstanceRecord) throws Exception {

    Document document = getBaseModelDocument(CLASS_NAME, ddmFormInstanceRecord);

    DDMFormInstanceRecordVersion ddmFormInstanceRecordVersion = ddmFormInstanceRecord
            .getFormInstanceRecordVersion();

    DDMFormInstance ddmFormInstance = ddmFormInstanceRecordVersion.getFormInstance();

    document.addKeyword(Field.CLASS_NAME_ID, classNameLocalService.getClassNameId(DDMFormInstance.class));
    document.addKeyword(Field.CLASS_PK, ddmFormInstance.getFormInstanceId());
    document.addKeyword(Field.CLASS_TYPE_ID, ddmFormInstanceRecordVersion.getFormInstanceId());
    document.addKeyword(Field.RELATED_ENTRY, true);
    document.addKeyword(Field.STATUS, ddmFormInstanceRecordVersion.getStatus());
    document.addKeyword(Field.VERSION, ddmFormInstanceRecordVersion.getVersion());

    document.addKeyword("formInstanceId", ddmFormInstance.getFormInstanceId());

    DDMStructure ddmStructure = ddmFormInstance.getStructure();

    DDMFormValues ddmFormValues = storageEngine.getDDMFormValues(ddmFormInstanceRecordVersion.getStorageId());

    addContent(ddmFormInstanceRecordVersion, ddmFormValues, document);

    ddmIndexer.addAttributes(document, ddmStructure, ddmFormValues);

    return document;
}

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

License:Open Source License

@Override
public void postProcessContextBooleanFilter(BooleanFilter contextBooleanFilter, SearchContext searchContext)
        throws Exception {

    Long classNameId = (Long) searchContext.getAttribute(Field.CLASS_NAME_ID);

    if ((classNameId != null) && (classNameId != 0)) {
        contextBooleanFilter.addRequiredTerm(Field.CLASS_NAME_ID, classNameId.toString());
    }//from w w  w .  ja v  a2 s.c  om

    addStatus(contextBooleanFilter, searchContext);

    addSearchClassTypeIds(contextBooleanFilter, searchContext);

    String ddmStructureFieldName = (String) searchContext.getAttribute("ddmStructureFieldName");
    Serializable ddmStructureFieldValue = searchContext.getAttribute("ddmStructureFieldValue");

    if (Validator.isNotNull(ddmStructureFieldName) && Validator.isNotNull(ddmStructureFieldValue)) {

        QueryFilter queryFilter = _ddmIndexer.createFieldValueQueryFilter(ddmStructureFieldName,
                ddmStructureFieldValue, searchContext.getLocale());

        contextBooleanFilter.add(queryFilter, BooleanClauseOccur.MUST);
    }

    String ddmStructureKey = (String) searchContext.getAttribute("ddmStructureKey");

    if (Validator.isNotNull(ddmStructureKey)) {
        contextBooleanFilter.addRequiredTerm("ddmStructureKey", ddmStructureKey);
    }

    String ddmTemplateKey = (String) searchContext.getAttribute("ddmTemplateKey");

    if (Validator.isNotNull(ddmTemplateKey)) {
        contextBooleanFilter.addRequiredTerm("ddmTemplateKey", ddmTemplateKey);
    }

    boolean head = GetterUtil.getBoolean(searchContext.getAttribute("head"), Boolean.TRUE);
    boolean relatedClassName = GetterUtil.getBoolean(searchContext.getAttribute("relatedClassName"));
    boolean showNonindexable = GetterUtil.getBoolean(searchContext.getAttribute("showNonindexable"));

    if (head && !relatedClassName && !showNonindexable) {
        contextBooleanFilter.addRequiredTerm("head", Boolean.TRUE);
    }

    if (!relatedClassName && showNonindexable) {
        contextBooleanFilter.addRequiredTerm("headListable", Boolean.TRUE);
    }
}

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

License:Open Source License

protected SearchContext buildSearchContext(long companyId, long groupId, List<Long> folderIds, long classNameId,
        String articleId, String title, String description, String content, int status, String ddmStructureKey,
        String ddmTemplateKey, LinkedHashMap<String, Object> params, boolean andSearch, int start, int end,
        Sort sort) {/*w w  w . jav  a2 s.  c o  m*/

    SearchContext searchContext = new SearchContext();

    searchContext.setAndSearch(andSearch);

    Map<String, Serializable> attributes = new HashMap<>();

    attributes.put(Field.ARTICLE_ID, articleId);
    attributes.put(Field.CLASS_NAME_ID, classNameId);
    attributes.put(Field.CONTENT, content);
    attributes.put(Field.DESCRIPTION, description);
    attributes.put(Field.STATUS, status);
    attributes.put(Field.TITLE, title);
    attributes.put("ddmStructureKey", ddmStructureKey);
    attributes.put("ddmTemplateKey", ddmTemplateKey);
    attributes.put("params", params);

    searchContext.setAttributes(attributes);

    searchContext.setCompanyId(companyId);
    searchContext.setEnd(end);
    searchContext.setFolderIds(folderIds);
    searchContext.setGroupIds(new long[] { groupId });

    if (params != null) {
        searchContext.setIncludeDiscussions(GetterUtil.getBoolean(params.get("includeDiscussions")));

        String keywords = (String) params.remove("keywords");

        if (Validator.isNotNull(keywords)) {
            searchContext.setKeywords(keywords);
        }
    }

    QueryConfig queryConfig = new QueryConfig();

    queryConfig.setHighlightEnabled(false);
    queryConfig.setScoreEnabled(false);

    searchContext.setQueryConfig(queryConfig);

    if (sort != null) {
        searchContext.setSorts(sort);
    }

    searchContext.setStart(start);

    return searchContext;
}

From source file:com.liferay.journal.web.internal.display.context.JournalDisplayContext.java

License:Open Source License

public SearchContainer<MBMessage> getCommentsSearchContainer() throws PortalException {

    SearchContainer<MBMessage> searchContainer = new SearchContainer(_liferayPortletRequest,
            _liferayPortletResponse.createRenderURL(), null, null);

    SearchContext searchContext = SearchContextFactory
            .getInstance(_liferayPortletRequest.getHttpServletRequest());

    searchContext.setAttribute(Field.CLASS_NAME_ID, PortalUtil.getClassNameId(JournalArticle.class));

    searchContext.setAttribute("discussion", Boolean.TRUE);

    List<MBMessage> mbMessages = new ArrayList<>();

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

    Hits hits = indexer.search(searchContext);

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

        MBMessage mbMessage = MBMessageLocalServiceUtil.fetchMBMessage(entryClassPK);

        mbMessages.add(mbMessage);/*from  w  w  w .  j av  a 2  s. c o  m*/
    }

    searchContainer.setResults(mbMessages);

    searchContainer.setTotal(hits.getLength());

    return searchContainer;
}

From source file:com.liferay.journal.web.internal.display.context.JournalDisplayContext.java

License:Open Source License

protected SearchContext buildSearchContext(long companyId, long groupId, List<java.lang.Long> folderIds,
        long classNameId, String ddmStructureKey, String ddmTemplateKey, String keywords,
        LinkedHashMap<String, Object> params, int start, int end, Sort sort, boolean showVersions) {

    String articleId = null;//  w  ww.  j av  a2s  .  com
    String title = null;
    String description = null;
    String content = null;
    boolean andOperator = false;

    if (Validator.isNotNull(keywords)) {
        articleId = keywords;
        title = keywords;
        description = keywords;
        content = keywords;
    } else {
        andOperator = true;
    }

    if (params != null) {
        params.put("keywords", keywords);
    }

    SearchContext searchContext = new SearchContext();

    searchContext.setAndSearch(andOperator);

    Map<String, Serializable> attributes = new HashMap<>();

    attributes.put(Field.ARTICLE_ID, articleId);
    attributes.put(Field.CLASS_NAME_ID, classNameId);
    attributes.put(Field.CONTENT, content);
    attributes.put(Field.DESCRIPTION, description);
    attributes.put(Field.STATUS, getStatus());
    attributes.put(Field.TITLE, title);
    attributes.put("ddmStructureKey", ddmStructureKey);
    attributes.put("ddmTemplateKey", ddmTemplateKey);
    attributes.put("params", params);

    searchContext.setAttributes(attributes);

    searchContext.setCompanyId(companyId);
    searchContext.setEnd(end);
    searchContext.setFolderIds(folderIds);
    searchContext.setGroupIds(new long[] { groupId });
    searchContext.setIncludeDiscussions(GetterUtil.getBoolean(params.get("includeDiscussions"), true));

    if (params != null) {
        keywords = (String) params.remove("keywords");

        if (Validator.isNotNull(keywords)) {
            searchContext.setKeywords(keywords);
        }
    }

    searchContext.setAttribute("head", !showVersions);
    searchContext.setAttribute("params", params);
    searchContext.setEnd(end);
    searchContext.setFolderIds(folderIds);
    searchContext.setStart(start);

    QueryConfig queryConfig = new QueryConfig();

    queryConfig.setHighlightEnabled(false);
    queryConfig.setScoreEnabled(false);

    searchContext.setQueryConfig(queryConfig);

    if (sort != null) {
        searchContext.setSorts(sort);
    }

    searchContext.setStart(start);

    return searchContext;
}

From source file:com.liferay.message.boards.internal.search.MBMessageIndexer.java

License:Open Source License

public MBMessageIndexer() {
    setDefaultSelectedFieldNames(Field.ASSET_TAG_NAMES, Field.CLASS_NAME_ID, Field.CLASS_PK, Field.COMPANY_ID,
            Field.CONTENT, Field.ENTRY_CLASS_NAME, Field.ENTRY_CLASS_PK, Field.GROUP_ID, Field.MODIFIED_DATE,
            Field.SCOPE_GROUP_ID, Field.TITLE, Field.UID);
    setFilterSearch(true);/*w  w  w .  j  a  v  a2s .  c  o m*/
    setPermissionAware(true);
}