List of usage examples for com.liferay.portal.kernel.search Field TITLE
String TITLE
To view the source code for com.liferay.portal.kernel.search Field TITLE.
Click Source Link
From source file:org.liferay.jukebox.util.ArtistIndexer.java
License:Open Source License
@Override protected Summary doGetSummary(Document document, Locale locale, String snippet, PortletURL portletURL) { Summary summary = createSummary(document); summary.setMaxContentLength(200);//from ww w .j av a 2 s . c om String title = document.get(Field.TITLE); String content = snippet; if (Validator.isNull(snippet)) { content = StringUtil.shorten(document.get("bio"), 200); } portletURL.setParameter("jspPage", "/html/artists/view_artist.jsp"); portletURL.setParameter("artistId", document.get(Field.CLASS_PK)); return new Summary(title, content, portletURL); }
From source file:org.liferay.jukebox.util.SongIndexer.java
License:Open Source License
@Override public void postProcessSearchQuery(BooleanQuery searchQuery, SearchContext searchContext) throws Exception { if (searchContext.getAttributes() == null) { return;/*from w ww .j a va2s . com*/ } addSearchTerm(searchQuery, searchContext, Field.TITLE, true); addSearchTerm(searchQuery, searchContext, "album", true); addSearchTerm(searchQuery, searchContext, "artist", true); }
From source file:org.liferay.jukebox.util.SongIndexer.java
License:Open Source License
@Override protected Document doGetDocument(Object obj) throws Exception { Song song = (Song) obj;// ww w .ja v a 2s. c o m Document document = getBaseModelDocument(PORTLET_ID, song); document.addDate(Field.MODIFIED_DATE, song.getModifiedDate()); document.addText(Field.TITLE, song.getName()); Album album = AlbumLocalServiceUtil.getAlbum(song.getAlbumId()); document.addText("album", album.getName()); document.addKeyword("albumId", album.getAlbumId()); Artist artist = ArtistLocalServiceUtil.getArtist(song.getArtistId()); document.addText("artist", artist.getName()); document.addKeyword("artistId", artist.getArtistId()); return document; }
From source file:org.rsc.liferay.solr.SolrIndexSearcher.java
License:Open Source License
protected Hits subset(SolrQuery solrQuery, Query query, QueryConfig queryConfig, QueryResponse queryResponse, boolean allResults) throws Exception { long startTime = System.currentTimeMillis(); Hits hits = new HitsImpl(); SolrDocumentList solrDocumentList = queryResponse.getResults(); long total = solrDocumentList.getNumFound(); if (allResults && (total > 0)) { solrQuery.setRows((int) total); queryResponse = _solrServer.query(solrQuery); return subset(solrQuery, query, queryConfig, queryResponse, false); }/*from ww w . j a va 2 s.c o m*/ List<Document> documents = new ArrayList<Document>(); List<Float> scores = new ArrayList<Float>(); List<String> snippets = new ArrayList<String>(); float maxScore = -1; Set<String> queryTerms = new HashSet<String>(); int subsetTotal = 0; for (SolrDocument solrDocument : solrDocumentList) { Document document = new DocumentImpl(); Collection<String> names = solrDocument.getFieldNames(); for (String name : names) { Collection<Object> fieldValues = solrDocument.getFieldValues(name); Field field = new Field(name, ArrayUtil.toStringArray(fieldValues.toArray(new Object[fieldValues.size()]))); document.add(field); } documents.add(document); String snippet = StringPool.BLANK; if (queryConfig.isHighlightEnabled()) { snippet = getSnippet(solrDocument, queryConfig, queryTerms, queryResponse.getHighlighting(), Field.CONTENT); if (Validator.isNull(snippet)) { snippet = getSnippet(solrDocument, queryConfig, queryTerms, queryResponse.getHighlighting(), Field.TITLE); } if (Validator.isNotNull(snippet)) { snippets.add(snippet); } } if (queryConfig.isScoreEnabled()) { float score = GetterUtil.getFloat(String.valueOf(solrDocument.getFieldValue("score"))); if (score > maxScore) { maxScore = score; } scores.add(score); } else { scores.add(maxScore); } subsetTotal++; } hits.setDocs(documents.toArray(new Document[subsetTotal])); hits.setLength((int) total); hits.setQuery(query); hits.setQueryTerms(queryTerms.toArray(new String[queryTerms.size()])); Float[] scoresArray = scores.toArray(new Float[subsetTotal]); if (queryConfig.isScoreEnabled() && (subsetTotal > 0) && (maxScore > 0)) { for (int i = 0; i < scoresArray.length; i++) { scoresArray[i] = scoresArray[i] / maxScore; } } hits.setScores(scoresArray); float searchTime = (float) (System.currentTimeMillis() - startTime) / Time.SECOND; hits.setSearchTime(searchTime); hits.setSnippets(snippets.toArray(new String[subsetTotal])); hits.setStart(startTime); return hits; }
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);/*from www .ja va 2s. c om*/ 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;//from w ww. j a va2s. co m }
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 ww w.j a v a 2 s. co 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 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); }/*w w w . j a va2s. 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 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
protected Document doGetDocument(Object obj) throws Exception { Customer entry = (Customer) obj;//from ww w.j ava 2 s .com Document document = getBaseModelDocument(PORTLET_ID, entry); //Document TITLE document.addText(Field.TITLE, HtmlUtil.extractText(entry.getName())); document.addText("name", HtmlUtil.extractText(entry.getName())); //street field document.addText("street", HtmlUtil.extractText(entry.getStreet())); //city field document.addText("city", HtmlUtil.extractText(entry.getCity())); //zip field document.addText("zip", HtmlUtil.extractText(entry.getZip())); return document; }
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;//w w w . java 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); }