List of usage examples for com.liferay.portal.kernel.search Field ENTRY_CLASS_PK
String ENTRY_CLASS_PK
To view the source code for com.liferay.portal.kernel.search Field ENTRY_CLASS_PK.
Click Source Link
From source file:com.slayer.service.impl.LMSBookLocalServiceImpl.java
License:Open Source License
public List<LMSBook> advancedSearch(long companyId, long groupId, String bookTitle, String author, boolean andSearch) { Hits hits = null;//from w w w . ja va2s . co m try { hits = getHits(companyId, groupId, bookTitle, author, andSearch); } catch (SystemException e) { e.printStackTrace(); } if (hits == null || hits.getLength() == 0) return null; List<LMSBook> books = new ArrayList<LMSBook>(); for (int i = 0; i < hits.getLength(); i++) { Document doc = hits.doc(i); long bookId = GetterUtil.getLong(doc.get(Field.ENTRY_CLASS_PK)); try { LMSBook book = fetchLMSBook(bookId); books.add(book); } catch (SystemException e) { e.printStackTrace(); } } return books; }
From source file:com.ssavr.solr.service.impl.IceCreamLocalServiceImpl.java
License:Open Source License
/*************************************************************************** ************************** GET ******************************************** ***************************************************************************/ public IceCreamBean getIceCreamBean(IceCream iceCream) throws Exception { String uid = "iceCream_" + iceCream.getUuid(); IceCreamBean bean = new IceCreamBean(); bean.setUid(uid);//w w w . j a v a 2 s . c om bean.setCompanyId(iceCream.getCompanyId()); bean.setIceCreamId(iceCream.getIceCreamId()); bean.setName(iceCream.getName()); bean.setFlavor(iceCream.getFlavor()); List<IceCreamDocuments> documents = iceCreamDocumentsLocalService .getIceCreamDocumentsByIceCreamId(iceCream.getIceCreamId()); List<String> documentsContent = new ArrayList<String>(); if (!documents.isEmpty()) { List<String> documentIds = new ArrayList<String>(); for (IceCreamDocuments document : documents) { documentIds.add(String.valueOf(document.getDocumentId())); } String documentsStr = StringUtil.merge(documentIds, StringPool.SPACE); SolrQuery query = new SolrQuery(); query.setQuery(Field.ENTRY_CLASS_PK + ":(" + documentsStr + ")"); query.addFilterQuery( Field.ENTRY_CLASS_NAME + ":(com.liferay.portlet.documentlibrary.model.DLFileEntry)"); query.setStart(0); query.setRows(10000000); String activeServerUrl = SolrUtil.getActiveSolrServer(); CommonsHttpSolrServer server = new CommonsHttpSolrServer(activeServerUrl); QueryResponse qr = server.query(query); SolrDocumentList docs = qr.getResults(); if (_log.isDebugEnabled()) { _log.debug("Found " + docs.size() + " Document(-s)"); } for (int i = 0; i < docs.size(); ++i) { String docContent = (String) docs.get(i).getFieldValue("content"); documentsContent.add(docContent); } } bean.setIceCreamRecipeContent(documentsContent); if (_log.isDebugEnabled()) { _log.debug(bean.toString()); } return bean; }
From source file:com.vportal.portal.search.HitsOpenSearchImpl.java
License:Open Source License
public String search(HttpServletRequest request, long groupId, long userId, String keywords, int startPage, int itemsPerPage, String format) throws SearchException { try {/* w ww . ja va 2 s. c om*/ ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY); int start = (startPage * itemsPerPage) - itemsPerPage; int end = startPage * itemsPerPage; SearchContext searchContext = SearchContextFactory.getInstance(request); searchContext.setGroupIds(new long[] { groupId }); searchContext.setEnd(end); searchContext.setKeywords(keywords); searchContext.setScopeStrict(false); searchContext.setStart(start); searchContext.setUserId(userId); addSearchAttributes(themeDisplay.getCompanyId(), searchContext, keywords); Portlet portlet = PortletLocalServiceUtil.getPortletById(themeDisplay.getCompanyId(), getPortletId()); Indexer indexer = portlet.getIndexerInstance(); Hits results = indexer.search(searchContext); String[] queryTerms = results.getQueryTerms(); int total = results.getLength(); Object[] values = addSearchResults(queryTerms, keywords, startPage, itemsPerPage, total, start, getTitle(keywords), getSearchPath(), format, themeDisplay); com.liferay.portal.kernel.xml.Document doc = (com.liferay.portal.kernel.xml.Document) values[0]; Element root = (Element) values[1]; for (int i = 0; i < results.getDocs().length; i++) { Document result = results.doc(i); String portletId = result.get(Field.PORTLET_ID); String snippet = results.snippet(i); long resultGroupId = GetterUtil.getLong(result.get(Field.GROUP_ID)); PortletURL portletURL = getPortletURL(request, portletId, resultGroupId); Summary summary = getSummary(indexer, result, snippet, portletURL); String title = summary.getTitle(); String url = getURL(themeDisplay, resultGroupId, result, portletURL); Date modifedDate = result.getDate(Field.MODIFIED); String content = summary.getContent(); String[] tags = new String[0]; Field assetTagNamesField = result.getFields().get(Field.ASSET_TAG_NAMES); if (assetTagNamesField != null) { tags = assetTagNamesField.getValues(); } double ratings = 0.0; String entryClassName = result.get(Field.ENTRY_CLASS_NAME); long entryClassPK = GetterUtil.getLong(result.get(Field.ENTRY_CLASS_PK)); if ((Validator.isNotNull(entryClassName)) && (entryClassPK > 0)) { RatingsStats stats = RatingsStatsLocalServiceUtil.getStats(entryClassName, entryClassPK); ratings = stats.getTotalScore(); } double score = results.score(i); addSearchResult(root, resultGroupId, entryClassName, entryClassPK, title, url, modifedDate, content, tags, ratings, score, format); } if (_log.isDebugEnabled()) { _log.debug("Return\n" + doc.asXML()); } return doc.asXML(); } catch (Exception e) { throw new SearchException(e); } }
From source file:com.vportal.portlet.vcms.util.SearchIndexer.java
License:Open Source License
public static Document getAddArticleDocument(long companyId, long groupId, String articleId, String title, String description, String content) throws NumberFormatException, PortalException, SystemException { InputStream is = null;/*from w ww.j av a2s .c o m*/ List addedAttachments = AttachmentLocalServiceUtil.getAttachments(Long.parseLong(articleId), VcmsArticle.class); for (int i = 0; i < addedAttachments.size(); i++) { Attachment attachment = (Attachment) addedAttachments.get(i); DLFileEntry entry = null; try { entry = (DLFileEntry) DLFileEntryLocalServiceUtil.getFileEntry(attachment.getFileEntryId()); /*String fileExtension = entry.getTitleWithExtension(); String extension = fileExtension.substring(fileExtension.lastIndexOf(".")+1,fileExtension.length());*/ String extension = entry.getExtension(); is = DLLocalServiceUtil.getFileAsStream(companyId, entry.getFolderId(), entry.getName()); content = FileUtilExt.getContentFile(is, content, extension); } catch (Exception e) { // TODO: handle exception e.printStackTrace(); } } content = HtmlUtil.extractText(content); Document doc = new DocumentImpl(); doc.addUID(PORTLET_ID, articleId); 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.addModifiedDate(); doc.addKeyword(Field.ENTRY_CLASS_NAME, VcmsArticle.class.getName()); doc.addKeyword(Field.ENTRY_CLASS_PK, articleId); return doc; }
From source file:com.vportal.portlet.vcms.util.SearchIndexer.java
License:Open Source License
public Summary getDocumentSummary(com.liferay.portal.kernel.search.Document doc, PortletURL portletURL) { // Title//from w ww . j a va2s .co m String title = doc.get(Field.TITLE); // Content String content = doc.get(Field.CONTENT); content = StringUtil.shorten(content, 200); // Portlet URL String articleId = doc.get(Field.ENTRY_CLASS_PK); portletURL.setParameter("struts_action", "/vcmsviewcontent/view"); portletURL.setParameter("articleId", articleId); VcmsCARelation category = null; try { category = VcmsCARelationServiceUtil.findRelationsByArticle(articleId); } catch (Exception e) { // TODO: handle exception } String categoryId = ""; if (category != null) { categoryId = String.valueOf(category.getCategoryId()); } portletURL.setParameter("categoryId", categoryId); return new Summary(title, content, portletURL); }
From source file:gr.open.loglevelsmanager.loglevel.util.LogLevelIndexer.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. j ava2 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 = LogLevelUtil.getPlid(Long.parseLong(groupId)); } catch (Exception e) { } portletURL.setParameter("p_l_id", String.valueOf(plid)); portletURL.setParameter("view", "editLogLevel"); portletURL.setParameter("LogLevelId", String.valueOf(entryId)); portletURL.setParameter("editType", "view"); return new Summary(title, content, portletURL); }
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 www . ja v a 2 s . 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 ww w. j av a 2s . com*/ 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 2s . com 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.CustomerPortlet.java
License:Open Source License
@SuppressWarnings("unchecked") public void showViewDefault(RenderRequest renderRequest, RenderResponse renderResponse) throws IOException, PortletException { ThemeDisplay themeDisplay = (ThemeDisplay) renderRequest.getAttribute(WebKeys.THEME_DISPLAY); long groupId = themeDisplay.getScopeGroupId(); PermissionChecker permissionChecker = themeDisplay.getPermissionChecker(); boolean hasAddPermission = CustomerPermission.contains(permissionChecker, groupId, "ADD_CUSTOMER"); boolean hasModelPermissions = CustomerPermission.contains(permissionChecker, groupId, ActionKeys.PERMISSIONS);// w w w. j a va 2s . c o m List<Customer> tempResults = Collections.EMPTY_LIST; PortletPreferences prefs = renderRequest.getPreferences(); String customersFilter = ParamUtil.getString(renderRequest, "customersFilter"); String rowsPerPage = prefs.getValue("rows-per-page", "5"); String viewType = prefs.getValue("view-type", "0"); Integer cur = 1; int containerStart = 0; int containerEnd = 0; String orderByType = renderRequest.getParameter("orderByType"); String orderByCol = renderRequest.getParameter("orderByCol"); try { cur = ParamUtil.getInteger(renderRequest, "cur"); } catch (Exception e) { cur = 1; } if (cur < 1) { cur = 1; } if (Validator.isNotNull(customersFilter) || !customersFilter.equalsIgnoreCase("")) { rowsPerPage = "100"; cur = 1; } containerStart = (cur - 1) * Integer.parseInt(rowsPerPage); containerEnd = containerStart + Integer.parseInt(rowsPerPage); int total = 0; try { PortalPreferences portalPrefs = PortletPreferencesFactoryUtil.getPortalPreferences(renderRequest); if (Validator.isNull(orderByCol) && Validator.isNull(orderByType)) { orderByCol = portalPrefs.getValue("Customer_order", "Customer-order-by-col", "customerId"); orderByType = portalPrefs.getValue("Customer_order", "Customer-order-by-type", "asc"); } OrderByComparator comparator = CustomerComparator.getCustomerOrderByComparator(orderByCol, orderByType); if (customersFilter.equalsIgnoreCase("")) { if (viewType.equals("0")) { tempResults = CustomerLocalServiceUtil.findAllInGroup(groupId, containerStart, containerEnd, comparator); total = CustomerLocalServiceUtil.countAllInGroup(groupId); } else if (viewType.equals("1")) { tempResults = CustomerLocalServiceUtil.findAllInUser(themeDisplay.getUserId(), containerStart, containerEnd, comparator); total = CustomerLocalServiceUtil.countAllInUser(themeDisplay.getUserId()); } else { tempResults = CustomerLocalServiceUtil.findAllInUserAndGroup(themeDisplay.getUserId(), groupId, containerStart, containerEnd, comparator); total = CustomerLocalServiceUtil.countAllInUserAndGroup(themeDisplay.getUserId(), groupId); } } else { Indexer indexer = IndexerRegistryUtil.getIndexer(Customer.class); SearchContext searchContext = SearchContextFactory .getInstance(PortalUtil.getHttpServletRequest(renderRequest)); searchContext.setEnd(containerEnd); searchContext.setKeywords(customersFilter); searchContext.setStart(containerStart); Hits results = indexer.search(searchContext); total = results.getLength(); if (total > 0) { tempResults = new ArrayList<Customer>(total); } for (int i = 0; i < results.getDocs().length; i++) { Document doc = results.doc(i); Customer resReg = null; // Entry long entryId = GetterUtil.getLong(doc.get(Field.ENTRY_CLASS_PK)); try { resReg = CustomerLocalServiceUtil.getCustomer(entryId); resReg = resReg.toEscapedModel(); tempResults.add(resReg); } catch (Exception e) { if (_log.isWarnEnabled()) { _log.warn("Customer search index is stale and contains entry " + entryId); } continue; } } } } catch (Exception e) { _log.debug(e); } renderRequest.setAttribute("highlightRowWithKey", renderRequest.getParameter("highlightRowWithKey")); renderRequest.setAttribute("containerStart", containerStart); renderRequest.setAttribute("containerEnd", containerEnd); renderRequest.setAttribute("cur", cur); renderRequest.setAttribute("tempResults", tempResults); renderRequest.setAttribute("totalCount", total); renderRequest.setAttribute("rowsPerPage", rowsPerPage); renderRequest.setAttribute("hasAddPermission", hasAddPermission); renderRequest.setAttribute("hasModelPermissions", hasModelPermissions); renderRequest.setAttribute("orderByType", orderByType); renderRequest.setAttribute("orderByCol", orderByCol); renderRequest.setAttribute("customersFilter", customersFilter); PortletURL addCustomerURL = renderResponse.createActionURL(); addCustomerURL.setParameter("javax.portlet.action", "newCustomer"); renderRequest.setAttribute("addCustomerURL", addCustomerURL.toString()); PortletURL customersFilterURL = renderResponse.createRenderURL(); customersFilterURL.setParameter("javax.portlet.action", "doView"); renderRequest.setAttribute("customersFilterURL", customersFilterURL.toString()); include(viewJSP, renderRequest, renderResponse); }