Example usage for com.liferay.portal.kernel.search Summary Summary

List of usage examples for com.liferay.portal.kernel.search Summary Summary

Introduction

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

Prototype

public Summary(Locale locale, String title, String content) 

Source Link

Usage

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

License:Open Source License

public Summary getSummary(Document document, String snippet, PortletURL portletURL) {

    String title = document.get(Field.TITLE);

    String content = snippet;/*  w  w w .  ja v  a2 s .c  om*/

    if (Validator.isNull(snippet)) {
        content = document.get(Field.DESCRIPTION);

        if (Validator.isNull(content)) {
            content = StringUtil.shorten(document.get(Field.CONTENT), 200);
        }
    }

    String resourcePrimKey = document.get(Field.ENTRY_CLASS_PK);

    portletURL.setParameter("jspPage", "/admin/view_slogan.jsp");
    portletURL.setParameter("resourcePrimKey", resourcePrimKey);

    return new Summary(title, content, portletURL);

}

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

License:Open Source License

@Test
public void testDLFileEntryAttachment() throws Exception {
    Mockito.when(assetRenderer.getSearchSummary((Locale) Matchers.any()))
            .thenReturn(SearchTestUtil.SUMMARY_CONTENT);

    Mockito.when(assetRenderer.getTitle((Locale) Matchers.any())).thenReturn(SearchTestUtil.SUMMARY_TITLE);

    replace(method(AssetRendererFactoryRegistryUtil.class, "getAssetRendererFactoryByClassName", String.class))
            .with(new InvocationHandler() {

                @Override/*from ww  w  .j  ava 2 s. c om*/
                public AssetRendererFactory<?> invoke(Object proxy, Method method, Object[] args)
                        throws Throwable {

                    String className = (String) args[0];

                    if (_DL_FILE_ENTRY_CLASS_NAME.equals(className)) {
                        return null;
                    }

                    if (SearchTestUtil.ATTACHMENT_OWNER_CLASS_NAME.equals(className)) {

                        return assetRendererFactory;
                    }

                    throw new IllegalArgumentException();
                }

            });

    Mockito.doReturn(assetRenderer).when(assetRendererFactory)
            .getAssetRenderer(SearchTestUtil.ATTACHMENT_OWNER_CLASS_PK);

    Mockito.when(_dlAppLocalService.getFileEntry(SearchTestUtil.ENTRY_CLASS_PK)).thenReturn(_fileEntry);

    Mockito.doThrow(new IllegalArgumentException()).when(_indexerRegistry).getIndexer(Mockito.anyString());

    Mockito.doReturn(_indexer).when(_indexerRegistry).getIndexer(_DL_FILE_ENTRY_CLASS_NAME);

    Mockito.doReturn(null).when(_indexerRegistry).getIndexer(SearchTestUtil.ATTACHMENT_OWNER_CLASS_NAME);

    String title = RandomTestUtil.randomString();
    String content = RandomTestUtil.randomString();

    Summary summary = new Summary(null, title, content);

    Mockito.doReturn(summary).when(_indexer).getSummary((Document) Matchers.any(), Matchers.anyString(),
            (PortletRequest) Matchers.isNull(), (PortletResponse) Matchers.isNull());

    SearchResult searchResult = assertOneSearchResult(
            SearchTestUtil.createAttachmentDocument(_DL_FILE_ENTRY_CLASS_NAME));

    Assert.assertEquals(SearchTestUtil.ATTACHMENT_OWNER_CLASS_NAME, searchResult.getClassName());
    Assert.assertEquals(SearchTestUtil.ATTACHMENT_OWNER_CLASS_PK, searchResult.getClassPK());

    Summary searchResultSummary = searchResult.getSummary();

    Assert.assertNotSame(summary, searchResultSummary);
    Assert.assertEquals(SearchTestUtil.SUMMARY_CONTENT, searchResultSummary.getContent());
    Assert.assertEquals(SearchTestUtil.SUMMARY_TITLE, searchResultSummary.getTitle());

    List<RelatedSearchResult<FileEntry>> relatedSearchResults = searchResult.getFileEntryRelatedSearchResults();

    Assert.assertEquals(relatedSearchResults.toString(), 1, relatedSearchResults.size());

    RelatedSearchResult<FileEntry> relatedSearchResult = relatedSearchResults.get(0);

    FileEntry relatedSearchResultFileEntry = relatedSearchResult.getModel();

    Assert.assertSame(_fileEntry, relatedSearchResultFileEntry);

    Summary relatedSearchResultSummary = relatedSearchResult.getSummary();

    Assert.assertSame(summary, relatedSearchResultSummary);
    Assert.assertEquals(content, relatedSearchResultSummary.getContent());
    Assert.assertEquals(title, relatedSearchResultSummary.getTitle());

    assertEmptyCommentRelatedSearchResults(searchResult);
    assertEmptyVersions(searchResult);
}

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

License:Open Source License

@Override
protected Summary doGetSummary(Document document, Locale locale, String snippet, PortletURL portletURL) {

    String title = document.get(Field.TITLE);

    String content = snippet;/*ww  w  .  j  a  v a  2s.c  o  m*/

    if (Validator.isNull(snippet)) {
        content = StringUtil.shorten(document.get(Field.CONTENT), 200);
    }

    String questionId = document.get(Field.ENTRY_CLASS_PK);

    portletURL.setParameter("mvcPath", "/question/view_question.jsp");
    portletURL.setParameter("questionId", questionId);

    return new Summary(title, content, portletURL);
}

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

License:Open Source License

@Override
protected Summary doGetSummary(Document document, Locale locale, String snippet, PortletRequest portletRequest,
        PortletResponse portletResponse) {

    Locale defaultLocale = LocaleUtil.fromLanguageId(document.get("defaultLanguageId"));

    Locale snippetLocale = getSnippetLocale(document, locale);

    String localizedTitleName = DocumentImpl.getLocalizedName(locale, Field.TITLE);

    if ((snippetLocale == null) && (document.getField(localizedTitleName) == null)) {

        snippetLocale = defaultLocale;/*from   www.j av a  2s.com*/
    } else {
        snippetLocale = locale;
    }

    String title = document.get(snippetLocale, Field.SNIPPET + StringPool.UNDERLINE + Field.TITLE, Field.TITLE);

    if (Validator.isNull(title) && !snippetLocale.equals(defaultLocale)) {
        title = document.get(defaultLocale, Field.SNIPPET + StringPool.UNDERLINE + Field.TITLE, Field.TITLE);
    }

    String content = getDDMContentSummary(document, snippetLocale, portletRequest, portletResponse);

    if (Validator.isNull(content) && !snippetLocale.equals(defaultLocale)) {
        content = getDDMContentSummary(document, defaultLocale, portletRequest, portletResponse);
    }

    Summary summary = new Summary(snippetLocale, title, content);

    summary.setMaxContentLength(200);

    return summary;
}

From source file:com.liferay.knowledgebase.admin.util.AdminIndexer.java

License:Open Source License

@Override
protected Summary doGetSummary(Document document, Locale locale, String snippet, PortletURL portletURL,
        PortletRequest portletRequest, PortletResponse portletResponse) {

    String title = document.get(Field.TITLE);

    String content = snippet;//from   w w  w .  ja v a 2  s .com

    if (Validator.isNull(snippet)) {
        content = document.get(Field.DESCRIPTION);

        if (Validator.isNull(content)) {
            content = StringUtil.shorten(document.get(Field.CONTENT), 200);
        }
    }

    String resourcePrimKey = document.get(Field.ENTRY_CLASS_PK);

    portletURL.setParameter("mvcPath", "/admin/view_article.jsp");
    portletURL.setParameter("resourcePrimKey", resourcePrimKey);

    return new Summary(title, content, portletURL);
}

From source file:com.liferay.portlet.blogs.util.BlogsIndexer.java

License:Open Source License

@Override
protected Summary doGetSummary(Document document, Locale locale, String snippet, PortletURL portletURL) {

    String title = document.get(Field.TITLE);

    String content = snippet;/*from   w w w . java  2s .c  om*/

    if (Validator.isNull(snippet)) {
        content = StringUtil.shorten(document.get(Field.CONTENT), 200);
    }

    String entryId = document.get(Field.ENTRY_CLASS_PK);

    portletURL.setParameter("struts_action", "/blogs/view_entry");
    portletURL.setParameter("entryId", entryId);

    return new Summary(title, content, portletURL);
}

From source file:com.liferay.portlet.bookmarks.util.BookmarksIndexer.java

License:Open Source License

@Override
protected Summary doGetSummary(Document document, Locale locale, String snippet, PortletURL portletURL) {

    String title = document.get(Field.TITLE);

    String url = document.get(Field.URL);

    String entryId = document.get(Field.ENTRY_CLASS_PK);

    portletURL.setParameter("struts_action", "/bookmarks/view_entry");
    portletURL.setParameter("entryId", entryId);

    return new Summary(title, url, portletURL);
}

From source file:com.liferay.portlet.calendar.util.CalIndexer.java

License:Open Source License

@Override
protected Summary doGetSummary(Document document, Locale locale, String snippet, PortletURL portletURL) {

    String title = document.get(Field.TITLE);

    String content = snippet;//from   w  w w.  ja v  a 2  s  .  c  om

    if (Validator.isNull(snippet)) {
        content = StringUtil.shorten(document.get(Field.DESCRIPTION), 200);
    }

    String eventId = document.get(Field.ENTRY_CLASS_PK);

    portletURL.setParameter("struts_action", "/calendar/view_event");
    portletURL.setParameter("eventId", eventId);

    return new Summary(title, content, portletURL);
}

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

License:Open Source License

@Override
protected Summary doGetSummary(Document document, Locale locale, String snippet, PortletURL portletURL) {

    LiferayPortletURL liferayPortletURL = (LiferayPortletURL) portletURL;

    liferayPortletURL.setLifecycle(PortletRequest.ACTION_PHASE);

    try {//from w w w  .j  a v  a 2 s  .  c  o m
        liferayPortletURL.setWindowState(LiferayWindowState.EXCLUSIVE);
    } catch (WindowStateException wse) {
    }

    String title = document.get(Field.TITLE);

    String content = snippet;

    if (Validator.isNull(snippet)) {
        content = StringUtil.shorten(document.get(Field.CONTENT), 200);
    }

    String fileEntryId = document.get(Field.ENTRY_CLASS_PK);

    portletURL.setParameter("struts_action", "/document_library/get_file");
    portletURL.setParameter("fileEntryId", fileEntryId);

    return new Summary(title, content, portletURL);
}

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

License:Open Source License

@Override
protected Summary doGetSummary(Document document, Locale locale, String snippet, PortletURL portletURL) {

    String title = document.get(locale, Field.TITLE);

    String content = snippet;//from  w ww. ja v a  2 s . com

    if (Validator.isNull(snippet)) {
        content = StringUtil.shorten(document.get(locale, Field.CONTENT), 200);
    }

    String groupId = document.get(Field.GROUP_ID);
    String articleId = document.get("articleId");
    String version = document.get(Field.VERSION);

    portletURL.setParameter("struts_action", "/journal/edit_article");
    portletURL.setParameter("groupId", groupId);
    portletURL.setParameter("articleId", articleId);
    portletURL.setParameter("version", version);

    return new Summary(title, content, portletURL);
}