@Override public List<TrashEntry> getEntries(Hits hits) { List<TrashEntry> entries = new ArrayList<>(); for (Document document : hits.getDocs()) { String entryClassName = GetterUtil.getString(document.get(Field.ENTRY_CLASS_NAME)); long classPK = GetterUtil.getLong(document.get(Field.ENTRY_CLASS_PK)); try { TrashEntry entry = TrashEntryLocalServiceUtil.fetchEntry(entryClassName, classPK); if (entry == null) { String userName = GetterUtil.getString(document.get(Field.REMOVED_BY_USER_NAME)); Date removedDate = document.getDate(Field.REMOVED_DATE); entry = new TrashEntryImpl(); entry.setUserName(userName); entry.setCreateDate(removedDate); TrashHandler trashHandler = TrashHandlerRegistryUtil.getTrashHandler(entryClassName); TrashRenderer trashRenderer = trashHandler.getTrashRenderer(classPK); entry.setClassName(trashRenderer.getClassName()); entry.setClassPK(trashRenderer.getClassPK()); String rootEntryClassName = GetterUtil.getString(document.get(Field.ROOT_ENTRY_CLASS_NAME)); long rootEntryClassPK = GetterUtil.getLong(document.get(Field.ROOT_ENTRY_CLASS_PK)); TrashEntry rootTrashEntry = TrashEntryLocalServiceUtil.fetchEntry(rootEntryClassName, rootEntryClassPK); if (rootTrashEntry != null) { entry.setRootEntry(rootTrashEntry); } } entries.add(entry); } catch (Exception e) { if (_log.isWarnEnabled()) { _log.warn( "Unable to find trash entry for " + entryClassName + " with primary key " + classPK); } } } return entries; }
public String search( HttpServletRequest request, long groupId, long userId, String keywords, int startPage, int itemsPerPage, String format) throws SearchException { try { ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY); int start = (startPage * itemsPerPage) - itemsPerPage; int end = startPage * itemsPerPage; Hits results = CompanyLocalServiceUtil.search(themeDisplay.getCompanyId(), userId, keywords, start, end); String[] queryTerms = results.getQueryTerms(); int total = results.getLength(); Object[] values = addSearchResults( queryTerms, keywords, startPage, itemsPerPage, total, start, "Liferay Portal Search: " + keywords, SEARCH_PATH, 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); Portlet portlet = PortletLocalServiceUtil.getPortletById(themeDisplay.getCompanyId(), portletId); if (portlet == null) { continue; } String portletTitle = PortalUtil.getPortletTitle(portletId, themeDisplay.getUser()); long resultGroupId = GetterUtil.getLong(result.get(Field.GROUP_ID)); String entryClassName = GetterUtil.getString(result.get(Field.ENTRY_CLASS_NAME)); long entryClassPK = GetterUtil.getLong(result.get(Field.ENTRY_CLASS_PK)); String title = StringPool.BLANK; PortletURL portletURL = getPortletURL(request, portletId, resultGroupId); String url = portletURL.toString(); Date modifedDate = result.getDate(Field.MODIFIED); String content = StringPool.BLANK; if (Validator.isNotNull(portlet.getIndexerClass())) { Indexer indexer = (Indexer) InstancePool.get(portlet.getIndexerClass()); String snippet = results.snippet(i); Summary summary = indexer.getSummary(result, snippet, portletURL); title = summary.getTitle(); url = portletURL.toString(); content = summary.getContent(); if (portlet.getPortletId().equals(PortletKeys.JOURNAL)) { url = getJournalURL(themeDisplay, resultGroupId, result); } } double score = results.score(i); addSearchResult( root, resultGroupId, entryClassName, entryClassPK, portletTitle + " " + CharPool.RAQUO + " " + title, url, modifedDate, content, score, format); } if (_log.isDebugEnabled()) { _log.debug("Return\n" + doc.asXML()); } return doc.asXML(); } catch (Exception e) { throw new SearchException(e); } }