List of usage examples for com.liferay.portal.kernel.search Field SNIPPET
String SNIPPET
To view the source code for com.liferay.portal.kernel.search Field SNIPPET.
Click Source Link
From source file:com.liferay.blade.samples.modelsummarycontributor.ModelSummaryContributor.java
License:Apache License
private Summary _createSummary(Document document) { String prefix = Field.SNIPPET + StringPool.UNDERLINE; String title = document.get(prefix + Field.TITLE, Field.TITLE); String company = document.get(prefix + Field.COMPANY_ID, Field.COMPANY_ID); return new Summary(title, company); }
From source file:com.liferay.docs.guestbook.search.GuestbookEntryModelSummaryContributor.java
License:Open Source License
private Summary createSummary(Document document) { String prefix = Field.SNIPPET + StringPool.UNDERLINE; String title = document.get(prefix + Field.TITLE, Field.CONTENT); String content = document.get(prefix + Field.CONTENT, Field.CONTENT); return new Summary(title, content); }
From source file:com.liferay.docs.guestbook.search.GuestbookModelSummaryContributor.java
License:Open Source License
private Summary createSummary(Document document) { String prefix = Field.SNIPPET + StringPool.UNDERLINE; String title = document.get(prefix + Field.TITLE, Field.TITLE); return new Summary(title, StringPool.BLANK); }
From source file:com.liferay.document.library.internal.search.SearchResultUtilDLFileEntryTest.java
License:Open Source License
@Test public void testDLFileEntryWithBrokenIndexer() throws Exception { Mockito.when(_dlAppLocalService.getFileEntry(SearchTestUtil.ENTRY_CLASS_PK)).thenReturn(_fileEntry); Mockito.doThrow(new IllegalArgumentException()).when(_indexer).getSummary((Document) Matchers.any(), Matchers.anyString(), (PortletRequest) Matchers.any(), (PortletResponse) Matchers.any()); Mockito.when(_indexerRegistry.getIndexer(Mockito.anyString())).thenReturn(_indexer); Document document = SearchTestUtil.createAttachmentDocument(_DL_FILE_ENTRY_CLASS_NAME); String snippet = RandomTestUtil.randomString(); document.add(new Field(Field.SNIPPET, snippet)); try (CaptureHandler captureHandler = JDKLoggerTestUtil .configureJDKLogger(SearchResultTranslatorImpl.class.getName(), Level.WARNING)) { SearchResult searchResult = assertOneSearchResult(document); List<LogRecord> logRecords = captureHandler.getLogRecords(); Assert.assertEquals(logRecords.toString(), 1, logRecords.size()); LogRecord logRecord = logRecords.get(0); long entryClassPK = GetterUtil.getLong(document.get(Field.ENTRY_CLASS_PK)); Assert.assertEquals("Search index is stale and contains entry {" + entryClassPK + "}", logRecord.getMessage()); Assert.assertEquals(SearchTestUtil.ATTACHMENT_OWNER_CLASS_NAME, searchResult.getClassName()); Assert.assertEquals(SearchTestUtil.ATTACHMENT_OWNER_CLASS_PK, searchResult.getClassPK()); Assert.assertNull(searchResult.getSummary()); Mockito.verify(_indexerRegistry).getIndexer(_DL_FILE_ENTRY_CLASS_NAME); Mockito.verify(_indexer).getSummary(document, snippet, null, null); assertEmptyFileEntryRelatedSearchResults(searchResult); Mockito.verify(_dlAppLocalService).getFileEntry(SearchTestUtil.ENTRY_CLASS_PK); assertEmptyCommentRelatedSearchResults(searchResult); assertEmptyVersions(searchResult); }//from w w w .ja va 2 s.c om }
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 ww w .j a va 2 s .c o m*/ } 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.journal.search.test.JournalArticleIndexerSummaryTest.java
License:Open Source License
protected String getSnippetFieldName(String field) { return StringBundler.concat(Field.SNIPPET, StringPool.UNDERLINE, field, StringPool.UNDERLINE, LocaleUtil.toLanguageId(Locale.US)); }
From source file:com.liferay.portlet.journal.util.JournalArticleIndexer.java
License:Open Source License
@Override protected Summary doGetSummary(Document document, Locale locale, String snippet, PortletURL portletURL) { Locale snippetLocale = getSnippetLocale(document, locale); String localizedTitleName = DocumentImpl.getLocalizedName(locale, Field.TITLE); if ((snippetLocale == null) || (document.getField(localizedTitleName) == null)) { snippetLocale = LocaleUtil.fromLanguageId(document.get("defaultLanguageId")); }//from www . j av a2 s .c om String title = document.get(snippetLocale, Field.SNIPPET + StringPool.UNDERLINE + Field.TITLE, Field.TITLE); String content = StringPool.BLANK; String ddmStructureKey = document.get("ddmStructureKey"); if (Validator.isNotNull(ddmStructureKey)) { content = getDDMContentSummary(document, snippetLocale); } else { content = getBasicContentSummary(document, snippetLocale); } 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(snippetLocale, title, content, portletURL); }
From source file:com.liferay.portlet.journal.util.JournalArticleIndexer.java
License:Open Source License
protected String getBasicContentSummary(Document document, Locale snippetLocale) { String prefix = Field.SNIPPET + StringPool.UNDERLINE; String content = document.get(snippetLocale, prefix + Field.DESCRIPTION, prefix + Field.CONTENT); if (Validator.isBlank(content)) { content = document.get(snippetLocale, Field.DESCRIPTION, Field.CONTENT); }//from w w w. j a v a2 s . c om if (content.length() > 200) { content = StringUtil.shorten(content, 200); } return content; }