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

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

Introduction

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

Prototype

String RELATED_ENTRY

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

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);//from  ww  w  .ja v a2  s  . co  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  a  v a2s.  c o  m*/
            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.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.message.boards.internal.search.MBMessageIndexer.java

License:Open Source License

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

    document.addKeyword(Field.CATEGORY_ID, mbMessage.getCategoryId());
    document.addText(Field.CONTENT, processContent(mbMessage));
    document.addKeyword(Field.ROOT_ENTRY_CLASS_PK, mbMessage.getRootMessageId());
    document.addText(Field.TITLE, mbMessage.getSubject());

    if (mbMessage.isAnonymous()) {
        document.remove(Field.USER_NAME);
    }/*w  w  w  .  j  av a 2  s.co m*/

    MBDiscussion discussion = mbDiscussionLocalService.fetchThreadDiscussion(mbMessage.getThreadId());

    if (discussion == null) {
        document.addKeyword("discussion", false);
    } else {
        document.addKeyword("discussion", true);
    }

    document.addKeyword("threadId", mbMessage.getThreadId());

    if (mbMessage.isDiscussion()) {
        List<RelatedEntryIndexer> relatedEntryIndexers = RelatedEntryIndexerRegistryUtil
                .getRelatedEntryIndexers(mbMessage.getClassName());

        if (relatedEntryIndexers != null) {
            for (RelatedEntryIndexer relatedEntryIndexer : relatedEntryIndexers) {

                Comment comment = commentManager.fetchComment(mbMessage.getMessageId());

                if (comment != null) {
                    relatedEntryIndexer.addRelatedEntryFields(document, comment);

                    document.addKeyword(Field.RELATED_ENTRY, true);
                }
            }
        }
    }

    return document;
}

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

License:Open Source License

@Override
public void addRelatedEntryFields(Document document, Object obj) throws Exception {

    MBMessage message = (MBMessage) obj;

    DLFileEntry dlFileEntry = DLFileEntryLocalServiceUtil.getDLFileEntry(message.getClassPK());

    document.addKeyword(Field.FOLDER_ID, dlFileEntry.getFolderId());
    document.addKeyword(Field.HIDDEN, dlFileEntry.isInHiddenFolder());
    document.addKeyword(Field.RELATED_ENTRY, true);
}

From source file:org.liferay.jukebox.util.AlbumIndexer.java

License:Open Source License

@Override
public void addRelatedEntryFields(Document document, Object obj) throws Exception {

    if (obj instanceof DLFileEntry) {
        DLFileEntry dlFileEntry = (DLFileEntry) obj;

        Album album = AlbumLocalServiceUtil.getAlbum(GetterUtil.getLong(dlFileEntry.getTitle()));

        document.addKeyword(Field.CLASS_NAME_ID, PortalUtil.getClassNameId(Album.class.getName()));
        document.addKeyword(Field.CLASS_PK, album.getAlbumId());
        document.addKeyword(Field.RELATED_ENTRY, true);
    }/*w  ww  . ja va2 s .co  m*/
}

From source file:org.liferay.jukebox.util.ArtistIndexer.java

License:Open Source License

@Override
public void addRelatedEntryFields(Document document, Object obj) throws Exception {

    if (obj instanceof DLFileEntry) {
        DLFileEntry dlFileEntry = (DLFileEntry) obj;

        Artist artist = ArtistLocalServiceUtil.getArtist(GetterUtil.getLong(dlFileEntry.getTitle()));

        document.addKeyword(Field.CLASS_NAME_ID, PortalUtil.getClassNameId(Artist.class.getName()));
        document.addKeyword(Field.CLASS_PK, artist.getArtistId());
        document.addKeyword(Field.RELATED_ENTRY, true);
    }/*from   www. ja va 2 s . c  om*/
}

From source file:org.liferay.jukebox.util.SongIndexer.java

License:Open Source License

@Override
public void addRelatedEntryFields(Document document, Object obj) throws Exception {

    if (obj instanceof DLFileEntry) {
        DLFileEntry dlFileEntry = (DLFileEntry) obj;

        Song song = SongLocalServiceUtil.getSong(GetterUtil.getLong(dlFileEntry.getTitle()));

        document.addKeyword(Field.CLASS_NAME_ID, PortalUtil.getClassNameId(Song.class.getName()));
        document.addKeyword(Field.CLASS_PK, song.getSongId());
        document.addKeyword(Field.RELATED_ENTRY, true);
    }/* www.j  a va 2  s .  co  m*/
}