public void recordHits(Hits hits, long groupId, boolean privateLayout) throws Exception { setSearcher(((HitsImpl) hits).getSearcher()); // This can later be optimized according to LEP-915. List docs = new ArrayList(hits.getLength()); List scores = new ArrayList(hits.getLength()); for (int i = 0; i < hits.getLength(); i++) { Document doc = hits.doc(i); String articleId = doc.get("articleId"); long articleGroupId = GetterUtil.getLong(doc.get(LuceneFields.GROUP_ID)); if (JournalContentSearchLocalServiceUtil.getLayoutIdsCount(groupId, privateLayout, articleId) > 0) { docs.add(hits.doc(i)); scores.add(new Float(hits.score(i))); } else if (!isShowListed() && (articleGroupId == groupId)) { docs.add(hits.doc(i)); scores.add(new Float(hits.score(i))); } } setLength(docs.size()); setDocs((Document[]) docs.toArray(new Document[0])); setScores((Float[]) scores.toArray(new Float[0])); setSearchTime((float) (System.currentTimeMillis() - getStart()) / Time.SECOND); }
public void recordHits(Hits hits, long groupId, boolean privateLayout, int start, int end) throws Exception { // This can later be optimized according to LEP-915. List<Document> docs = new ArrayList<Document>(); List<Float> scores = new ArrayList<Float>(); Document[] docsArray = hits.getDocs(); for (int i = 0; i < docsArray.length; i++) { Document doc = hits.doc(i); String articleId = doc.get(Field.ARTICLE_ID); long articleGroupId = GetterUtil.getLong(doc.get(Field.GROUP_ID)); int layoutIdsCount = JournalContentSearchLocalServiceUtil.getLayoutIdsCount(groupId, privateLayout, articleId); if ((layoutIdsCount > 0) || (!isShowListed() && (articleGroupId == groupId))) { docs.add(hits.doc(i)); scores.add(hits.score(i)); } } int length = docs.size(); hits.setLength(length); if (end > length) { end = length; } docs = docs.subList(start, end); scores = scores.subList(start, end); hits.setDocs(docs.toArray(new Document[docs.size()])); hits.setScores(ArrayUtil.toFloatArray(scores)); hits.setSearchTime((float) (System.currentTimeMillis() - hits.getStart()) / Time.SECOND); }
private String formatJournalArticleURL() { /* This checks if the object is viewable by the current user and, if so, works out * the original url for the search results. The "visible" flag variable is set for each one. */ Long lGroupId; Long lArticleId; Long lUserId; String strJournalURL = Global.strNoURLReturned; JournalContentSearchLocalServiceUtil jcslu = new JournalContentSearchLocalServiceUtil(); LayoutLocalServiceUtil llsu = new LayoutLocalServiceUtil(); List<Long> listLayouts = new ArrayList<Long>(); Layout layLayout; User user; int iCount = 0; this.isVisible = false; try { this.context = FacesContext.getCurrentInstance(); this.portletRequest = (PortletRequest) context.getExternalContext().getRequest(); this.themeDisplay = (ThemeDisplay) portletRequest.getAttribute(WebKeys.THEME_DISPLAY); } catch (Exception e) { System.out.println(e); } try { lGroupId = Long.decode(this.getGroupId()); } catch (NumberFormatException n) { lGroupId = 0l; // zero long, not letter O } try { lArticleId = Long.decode(this.getArticleId()); } catch (NumberFormatException n) { lArticleId = 0l; // zero long, not letter O } try { lUserId = Long.decode(this.getUserId()); } catch (NumberFormatException n) { lUserId = 0l; // zero long, not letter O } if ((lGroupId != 0) && (lArticleId != 0)) { try { try { permissionChecker = themeDisplay.getPermissionChecker(); this.setIsVisible( permissionChecker.hasPermission( lGroupId, this.entryClassName, this.rootEntryClassPK, ActionKeys.VIEW)); if (this.isIsVisible()) { if (getEntryClassName().equalsIgnoreCase(JournalArticle.class.getName())) { iCount = jcslu.getLayoutIdsCount(lGroupId, false, articleId); listLayouts = jcslu.getLayoutIds(lGroupId, false, articleId); if (iCount > 0) { layLayout = llsu.getLayout(lGroupId, false, listLayouts.get(0)); layoutFriendlyURL = PortalUtil.getLayoutFriendlyURL(layLayout, themeDisplay); layoutFullURL = PortalUtil.getLayoutActualURL(layLayout, themeDisplay.getPathMain()); strHost = portletRequest.getServerName(); iServerPort = portletRequest.getServerPort(); strScheme = portletRequest.getScheme(); if (layoutFullURL.startsWith("http://")) { strJournalURL = layoutFullURL; } else { if (strHost.equalsIgnoreCase("localhost")) { strJournalURL = strScheme + "://" + strHost + ":" + iServerPort + layoutFriendlyURL; } else { strJournalURL = layoutFriendlyURL; } } } } else if (getEntryClassName().equalsIgnoreCase(BlogsEntry.class.getName())) { BlogsEntry entry = BlogsEntryLocalServiceUtil.getEntry(lArticleId); Group trgtGroup = GroupLocalServiceUtil.getGroup(lGroupId); String strFrUrl = trgtGroup.getFriendlyURL(); String strUrlPath; user = UserLocalServiceUtil.getUser(lUserId); if (strFrUrl.equalsIgnoreCase("/fishnet")) { strUrlPath = "/home/-/blogs/"; } else if (strFrUrl.equalsIgnoreCase("/fishlink")) { strUrlPath = "/home/-/blogs/"; } else if (strFrUrl.equalsIgnoreCase("/freshwater-biological-association")) { strUrlPath = "/home/-/blogs/"; } else { strUrlPath = "/blog/-/blogs/"; } layoutFriendlyURL = "/web" + strFrUrl + strUrlPath + entry.getUrlTitle(); strHost = portletRequest.getServerName(); iServerPort = portletRequest.getServerPort(); strScheme = portletRequest.getScheme(); strJournalURL = strScheme + "://" + strHost + ":" + iServerPort + layoutFriendlyURL; } else if (getEntryClassName().equalsIgnoreCase(WikiPage.class.getName())) { WikiPageResource pageResource = WikiPageResourceLocalServiceUtil.getPageResource(lArticleId); WikiPage wikiPage = WikiPageLocalServiceUtil.getPage( pageResource.getNodeId(), pageResource.getTitle()); WikiNode wikiNode = WikiNodeLocalServiceUtil.getNode(pageResource.getNodeId()); String strWikiNodeName = wikiNode.getName(); String strWikiTitle = wikiPage.getTitle(); Long lPageGroupId = wikiPage.getGroupId(); Group trgtGroup = GroupLocalServiceUtil.getGroup(lPageGroupId); String strFrUrl = trgtGroup.getFriendlyURL(); strHost = portletRequest.getServerName(); iServerPort = portletRequest.getServerPort(); strScheme = portletRequest.getScheme(); // Extremely nasty hack! if (strFrUrl.equalsIgnoreCase("/tera")) { String strReplacedTitle = strWikiTitle.replaceAll("\\s", "\\+"); layoutFriendlyURL = "/web" + strFrUrl + "/home?p_p_id=54_INSTANCE_rU18&p_p_lifecycle=0&p_p_state=normal&p_p_mode=view&p_p_col_id=column-1&p_p_col_count=1&_54_INSTANCE_rU18_struts_action=%2Fwiki_display%2Fview&_54_INSTANCE_rU18_nodeName=" + strWikiNodeName + "&_54_INSTANCE_rU18_title=" + strReplacedTitle; } else if (strFrUrl.equalsIgnoreCase("/fwl")) { layoutFriendlyURL = "/web" + strFrUrl + "/wiki/-/wiki/" + strWikiNodeName + "/" + strWikiTitle; } else if (strFrUrl.equalsIgnoreCase("/fishlink")) { layoutFriendlyURL = "/web" + strFrUrl + strFrUrl + "-wiki/-/wiki/" + strWikiNodeName + "/" + strWikiTitle; } else { layoutFriendlyURL = "/freshwater-wiki/-/wiki/" + strWikiNodeName + "/" + strWikiTitle; } // </hack> strJournalURL = strScheme + "://" + strHost + ":" + iServerPort + layoutFriendlyURL; } else if (getEntryClassName().equalsIgnoreCase(DLFileEntry.class.getName())) { DLFileEntry fileEntry = DLFileEntryLocalServiceUtil.getFileEntry(lArticleId); lGroupId = fileEntry.getGroupId(); AssetEntry assetEntry = AssetEntryLocalServiceUtil.getEntry(getEntryClassName(), lArticleId); Long lEntryId = assetEntry.getEntryId(); strHost = portletRequest.getServerName(); iServerPort = portletRequest.getServerPort(); strScheme = portletRequest.getScheme(); // Another hack layoutFriendlyURL = "/fwl/documents/-/asset_publisher/8Ztl/document/id/" + lEntryId; strJournalURL = strScheme + "://" + strHost + ":" + iServerPort + "/web" + layoutFriendlyURL; if (fileEntry.getTitle().isEmpty()) { this.setTitle("From Document Library"); } else { this.setTitle(fileEntry.getTitle()); } // } else if (getEntryClassName().equalsIgnoreCase(IGImage.class.getName())) { IGImage image = IGImageLocalServiceUtil.getImage(lArticleId); strHost = portletRequest.getServerName(); iServerPort = portletRequest.getServerPort(); strScheme = portletRequest.getScheme(); layoutFriendlyURL = "igimage.fba.org.uk"; // if (layoutFullURL.startsWith("http://")) { // strJournalURL = layoutFullURL; // } else { strJournalURL = strScheme + "://" + strHost + ":" + iServerPort + layoutFriendlyURL; // } // PortletURL viewImageURL = new PortletURLImpl(request, PortletKeys.IMAGE_GALLERY, // plid, PortletRequest.RENDER_PHASE); // viewImageURL.setWindowState(WindowState.MAXIMIZED); // viewImageURL.setParameter("struts_action", "/image_gallery/view"); // viewImageURL.setParameter("folderId", String.valueOf(image.getFolderId())); } else if (getEntryClassName().equalsIgnoreCase(MBMessage.class.getName())) { MBMessage message = MBMessageLocalServiceUtil.getMessage(lArticleId); String aHref = "<a href=" + themeDisplay.getPathMain() + "/message_boards/find_message?messageId=" + message.getMessageId() + ">"; strHost = portletRequest.getServerName(); iServerPort = portletRequest.getServerPort(); strScheme = portletRequest.getScheme(); layoutFriendlyURL = "mbmessage.fba.org.uk"; // if (layoutFullURL.startsWith("http://")) { // strJournalURL = layoutFullURL; // } else { strJournalURL = strScheme + "://" + strHost + ":" + iServerPort + layoutFriendlyURL; // } } else if (getEntryClassName().equalsIgnoreCase(BookmarksEntry.class.getName())) { BookmarksEntry entry = BookmarksEntryLocalServiceUtil.getEntry(lArticleId); String entryURL = themeDisplay.getPathMain() + "/bookmarks/open_entry?entryId=" + entry.getEntryId(); strHost = portletRequest.getServerName(); iServerPort = portletRequest.getServerPort(); strScheme = portletRequest.getScheme(); layoutFriendlyURL = "bookmarks.fba.org.uk"; // if (layoutFullURL.startsWith("http://")) { // strJournalURL = layoutFullURL; // } else { strJournalURL = strScheme + "://" + strHost + ":" + iServerPort + layoutFriendlyURL; // } } } } catch (PortalException ex) { Logger.getLogger(Liferay.class.getName()).log(Level.SEVERE, null, ex); } } catch (SystemException ex) { Logger.getLogger(Liferay.class.getName()).log(Level.SEVERE, null, ex); } } return strJournalURL; }