List of usage examples for com.liferay.portal.kernel.search Field CONTENT
String CONTENT
To view the source code for com.liferay.portal.kernel.search Field CONTENT.
Click Source Link
From source file:org.rsc.liferay.solr.SolrIndexSearcher.java
License:Open Source License
protected SolrQuery translateQuery(long companyId, Query query, Sort[] sorts, int start, int end) throws Exception { QueryConfig queryConfig = query.getQueryConfig(); SolrQuery solrQuery = new SolrQuery(); if (queryConfig.isHighlightEnabled()) { solrQuery.setHighlight(true);/* w w w . j a v a 2 s.com*/ solrQuery.setHighlightFragsize(queryConfig.getHighlightFragmentSize()); solrQuery.setHighlightSnippets(queryConfig.getHighlightSnippetSize()); String localizedContentName = DocumentImpl.getLocalizedName(queryConfig.getLocale(), Field.CONTENT); String localizedTitleName = DocumentImpl.getLocalizedName(queryConfig.getLocale(), Field.TITLE); solrQuery.setParam("hl.fl", Field.CONTENT, localizedContentName, Field.TITLE, localizedTitleName); } solrQuery.setIncludeScore(queryConfig.isScoreEnabled()); QueryTranslatorUtil.translateForSolr(query); String queryString = query.toString(); StringBundler sb = new StringBundler(6); sb.append(queryString); sb.append(StringPool.SPACE); sb.append(StringPool.PLUS); sb.append(Field.COMPANY_ID); sb.append(StringPool.COLON); sb.append(companyId); solrQuery.setQuery(sb.toString()); if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS)) { solrQuery.setRows(0); } else { solrQuery.setRows(end - start); solrQuery.setStart(start); } if (sorts != null) { for (Sort sort : sorts) { if (sort == null) { continue; } String sortFieldName = sort.getFieldName(); if (DocumentImpl.isSortableTextField(sortFieldName)) { sortFieldName = DocumentImpl.getSortableFieldName(sortFieldName); } ORDER order = ORDER.asc; if (Validator.isNull(sortFieldName) || !sortFieldName.endsWith("sortable")) { sortFieldName = "score"; order = ORDER.desc; } if (sort.isReverse()) { order = ORDER.desc; } solrQuery.addSort(new SortClause(sortFieldName, order)); } } return solrQuery; }
From source file:org.xcolab.portlets.discussions.Indexer.java
License:Open Source License
@Override public Document getDocument(Object obj) throws SearchException { DiscussionMessage message = (DiscussionMessage) obj; Document doc = new DocumentImpl(); doc.addUID(PORTLET_ID, message.getMessageId()); doc.addModifiedDate(message.getCreateDate()); doc.addKeyword(Field.COMPANY_ID, 10112L); doc.addKeyword(Field.PORTLET_ID, PORTLET_ID); doc.addKeyword(Field.GROUP_ID, message.getCategoryGroupId()); doc.addText(Field.TITLE, message.getSubject()); doc.addText(Field.CONTENT, message.getBody()); doc.addKeyword(Field.ENTRY_CLASS_NAME, DiscussionMessage.class.getName()); doc.addKeyword(Field.ENTRY_CLASS_PK, message.getMessageId()); return doc;/* w w w . j av a2s . c om*/ }
From source file:org.xcolab.portlets.search.Indexer.java
License:Open Source License
public static Document getArticleDocument(long companyId, long groupId, String articleId, double version, String title, String description, String content, String type, Date displayDate, String[] tagsCategories, String[] tagsEntries, ExpandoBridge expandoBridge) { if ((content != null) && ((content.indexOf("<dynamic-content") != -1) || (content.indexOf("<static-content") != -1))) { content = _getIndexableContent(content); content = StringUtil.replace(content, "<![CDATA[", StringPool.BLANK); content = StringUtil.replace(content, "]]>", StringPool.BLANK); }/*from w w w. ja v a 2 s .c om*/ content = StringUtil.replace(content, "&", "&"); content = StringUtil.replace(content, "<", "<"); content = StringUtil.replace(content, ">", ">"); content = HtmlUtil.extractText(content); Document doc = new DocumentImpl(); // check if this is an most recent version of an article JournalArticle article; boolean isOld = false; try { article = JournalArticleLocalServiceUtil.getArticle(groupId, articleId); if (article.getVersion() != version) { isOld = true; } } catch (Exception e1) { e1.printStackTrace(); // ignore } if (isOld) { doc.addUID(PORTLET_ID, articleId, "old"); } else { doc.addUID(PORTLET_ID, articleId); } doc.addModifiedDate(displayDate); doc.addKeyword(Field.COMPANY_ID, companyId); doc.addKeyword(Field.PORTLET_ID, PORTLET_ID); doc.addKeyword(Field.GROUP_ID, groupId); doc.addText(Field.TITLE, title); doc.addText(Field.CONTENT, content); doc.addText(Field.DESCRIPTION, description); doc.addKeyword(Field.ENTRY_CLASS_PK, articleId); doc.addKeyword(Field.VERSION, version); doc.addKeyword(Field.TYPE, type); ExpandoBridgeIndexerUtil.addAttributes(doc, expandoBridge); try { Layout pageLayout = getLayoutForContent(articleId); if (pageLayout != null) { Layout tmp = pageLayout; boolean isAbout = false; while (tmp != null && !isAbout) { if (tmp.getFriendlyURL().toLowerCase().contains("/about") || tmp.getFriendlyURL().toLowerCase().contains("/contests")) { isAbout = true; } if (tmp.getParentLayoutId() > 0) { try { tmp = LayoutLocalServiceUtil.getLayout(tmp.getGroupId(), tmp.getPrivateLayout(), tmp.getParentLayoutId()); } catch (com.liferay.portal.NoSuchLayoutException e) { tmp = null; } catch (PortalException e) { tmp = null; } } else { tmp = null; } } if (isAbout) { doc.addKeyword("PAGE_URL", pageLayout.getFriendlyURL()); doc.addKeyword(Field.ENTRY_CLASS_NAME, JournalArticle.class.getName() + ".index"); } } else { doc.addKeyword(Field.ENTRY_CLASS_NAME, JournalArticle.class.getName()); } } catch (SystemException e) { doc.addKeyword(Field.ENTRY_CLASS_NAME, JournalArticle.class.getName()); e.printStackTrace(); } return doc; }
From source file:org.xcolab.portlets.search.Indexer.java
License:Open Source License
@Override public Document getDocument(Object obj) throws SearchException { JournalArticle article = (JournalArticle) obj; String articleId = article.getArticleId(); long groupId = article.getGroupId(); long companyId = article.getCompanyId(); double version = article.getVersion(); String content = article.getContent(); String title = article.getTitle(); Date displayDate = article.getDisplayDate(); String description = article.getDescription(); String type = article.getType(); ExpandoBridge expandoBridge = article.getExpandoBridge(); if ((content != null) && ((content.indexOf("<dynamic-content") != -1) || (content.indexOf("<static-content") != -1))) { content = _getIndexableContent(content); content = StringUtil.replace(content, "<![CDATA[", StringPool.BLANK); content = StringUtil.replace(content, "]]>", StringPool.BLANK); }//from ww w .j a v a 2 s . c o m content = StringUtil.replace(content, "&", "&"); content = StringUtil.replace(content, "<", "<"); content = StringUtil.replace(content, ">", ">"); content = HtmlUtil.extractText(content); Document doc = new DocumentImpl(); // check if this is an most recent version of an article boolean isOld = false; try { JournalArticle tmpArticle = JournalArticleLocalServiceUtil.getArticle(groupId, String.valueOf(articleId)); if (article.getVersion() != version) { isOld = true; } } catch (Exception e1) { e1.printStackTrace(); // ignore } if (isOld) { doc.addUID(PORTLET_ID, articleId, "old"); } else { doc.addUID(PORTLET_ID, articleId); } doc.addModifiedDate(displayDate); doc.addKeyword(Field.COMPANY_ID, companyId); doc.addKeyword(Field.PORTLET_ID, PORTLET_ID); doc.addKeyword(Field.GROUP_ID, groupId); doc.addText(Field.TITLE, title); doc.addText(Field.CONTENT, content); doc.addText(Field.DESCRIPTION, description); doc.addKeyword(Field.ENTRY_CLASS_PK, articleId); doc.addKeyword(Field.VERSION, version); doc.addKeyword(Field.TYPE, type); ExpandoBridgeIndexerUtil.addAttributes(doc, expandoBridge); try { Layout pageLayout = getLayoutForContent(articleId); if (pageLayout != null) { Layout tmp = pageLayout; boolean isAbout = false; while (tmp != null && !isAbout) { if (tmp.getFriendlyURL().toLowerCase().contains("/about") || tmp.getFriendlyURL().toLowerCase().contains("/contests")) { isAbout = true; } if (tmp.getParentLayoutId() > 0) { try { tmp = LayoutLocalServiceUtil.getLayout(tmp.getGroupId(), tmp.getPrivateLayout(), tmp.getParentLayoutId()); } catch (com.liferay.portal.NoSuchLayoutException e) { tmp = null; } catch (PortalException e) { tmp = null; } } else { tmp = null; } } if (isAbout) { doc.addKeyword("PAGE_URL", pageLayout.getFriendlyURL()); doc.addKeyword(Field.ENTRY_CLASS_NAME, JournalArticle.class.getName() + ".index"); } } else { doc.addKeyword(Field.ENTRY_CLASS_NAME, JournalArticle.class.getName()); } } catch (SystemException e) { doc.addKeyword(Field.ENTRY_CLASS_NAME, JournalArticle.class.getName()); e.printStackTrace(); } return doc; }
From source file:org.xmlportletfactory.olafk.customer.util.CustomerIndexer.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;/* www .j av a 2 s . com*/ if (Validator.isNull(snippet)) { content = StringUtil.shorten(document.get(Field.CONTENT), 200); } String entryId = document.get(Field.ENTRY_CLASS_PK); String groupId = document.get(Field.GROUP_ID); long plid = 0; try { plid = CustomerUtil.getPlid(Long.parseLong(groupId)); } catch (Exception e) { } portletURL.setParameter("p_l_id", String.valueOf(plid)); portletURL.setParameter("view", "editCustomer"); portletURL.setParameter("customerId", String.valueOf(entryId)); portletURL.setParameter("editType", "view"); return new Summary(title, content, portletURL); }
From source file:org.xmlportletfactory.olafk.customer.util.InvoicesIndexer.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 . jav a 2 s .c om if (Validator.isNull(snippet)) { content = StringUtil.shorten(document.get(Field.CONTENT), 200); } String entryId = document.get(Field.ENTRY_CLASS_PK); String groupId = document.get(Field.GROUP_ID); long plid = 0; try { plid = InvoicesUtil.getPlid(Long.parseLong(groupId)); } catch (Exception e) { } portletURL.setParameter("p_l_id", String.valueOf(plid)); portletURL.setParameter("view", "editInvoices"); portletURL.setParameter("invoiceId", String.valueOf(entryId)); portletURL.setParameter("editType", "view"); return new Summary(title, content, portletURL); }