portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tay...@apache.org
Subject svn commit: r1735359 - in /portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/search: PortletToPageMap.java SearchPortlet.java
Date Thu, 17 Mar 2016 02:04:33 GMT
Author: taylor
Date: Thu Mar 17 02:04:33 2016
New Revision: 1735359

URL: http://svn.apache.org/viewvc?rev=1735359&view=rev
Log:
JS2-1348: improving search algorithm to better filter portlets and skip system portlets.

Modified:
    portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/search/PortletToPageMap.java
    portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/search/SearchPortlet.java

Modified: portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/search/PortletToPageMap.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/search/PortletToPageMap.java?rev=1735359&r1=1735358&r2=1735359&view=diff
==============================================================================
--- portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/search/PortletToPageMap.java
(original)
+++ portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/search/PortletToPageMap.java
Thu Mar 17 02:04:33 2016
@@ -16,6 +16,7 @@
  */
 package org.apache.jetspeed.portlets.search;
 
+import java.io.Serializable;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
@@ -24,7 +25,7 @@ import java.util.concurrent.ConcurrentHa
 /**
  * Created by dtaylor on 12/5/15.
  */
-public class PortletToPageMap {
+public class PortletToPageMap  implements Serializable {
     private Map<String, List<String>> portletMap;
     private Map<String, List<String>> contentMap;
 

Modified: portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/search/SearchPortlet.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/search/SearchPortlet.java?rev=1735359&r1=1735358&r2=1735359&view=diff
==============================================================================
--- portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/search/SearchPortlet.java
(original)
+++ portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/search/SearchPortlet.java
Thu Mar 17 02:04:33 2016
@@ -126,27 +126,32 @@ public class SearchPortlet extends Gener
                 if (index > -1) {
                     String key = result.getTitle().substring(index);
                     if (key != null) {
-                        List<String> links = getPortletToPageMap().getContent(key);
+                        List<String> links = getPortletToPageMap(request.getPortletSession()).getContent(key);
                         String link = getBestLink(links);
-                        searchInfoResults.add(new SearchInfo(key, result.getType(), link,
result.getScore(), result.getDescription(),
-                                admin.getPortalURL(request, actionResponse, link)));
+                        if (link != null) {
+                            searchInfoResults.add(new SearchInfo(key, result.getType(), link,
result.getScore(), result.getDescription(),
+                                    admin.getPortalURL(request, actionResponse, link)));
+                        }
                     }
                 }
             } else {
                 String key = result.getKey().substring(result.getKey().indexOf("::") + 2);
-                List<String> links = getPortletToPageMap().getPortlet(key);
-                String link = getBestLink(links);
-                boolean error = false;
-                try {
-                    Page page = pageManager.getPage(link);
-                    page.checkAccess(JetspeedActions.VIEW);
-                }
-                catch(Exception e) {
-                    error = true;
-                }
-                if (!error) {
-                    searchInfoResults.add(new SearchInfo(result.getTitle(), result.getType(),
key, result.getScore(), result.getDescription(),
-                            admin.getPortalURL(request, actionResponse, link)));
+                List<String> links = getPortletToPageMap(request.getPortletSession()).getPortlet(key);
+                if (links != null) {
+                    String link = getBestLink(links);
+                    if (link != null) {
+                        boolean error = false;
+                        try {
+                            Page page = pageManager.getPage(link);
+                            page.checkAccess(JetspeedActions.VIEW);
+                        } catch (Exception e) {
+                            error = true;
+                        }
+                        if (!error) {
+                            searchInfoResults.add(new SearchInfo(result.getTitle(), result.getType(),
key, result.getScore(), result.getDescription(),
+                                    admin.getPortalURL(request, actionResponse, link)));
+                        }
+                    }
                 }
             }
         }
@@ -156,30 +161,29 @@ public class SearchPortlet extends Gener
         actionResponse.sendRedirect(redirect);
     }
 
-    private static PortletToPageMap map = null;
-
-    private PortletToPageMap getPortletToPageMap() {
-        if (map == null) {
-            System.out.println(".... starting loading of portlet page map");
-            long start = System.currentTimeMillis();
-            map = buildPortletToPageMap();
-            System.out.println(".... completed loading of " + map.portletSize() + " portlet
page map in " + (System.currentTimeMillis() - start) + " ms");
-        }
-        return map;
-    }
+    private final static String SEARCH_CACHE = "J2_SEARCH_CACHE";
 
     /**
      * Build a map of portlets to pages where they exist
      *
      * @return
      */
-    private synchronized PortletToPageMap buildPortletToPageMap() {
-        PortletToPageMap map = new PortletToPageMap();
-        try {
-            Folder root = pageManager.getFolder("/");
-            traverse(root, map);
-        } catch (Exception e) {
-            e.printStackTrace();
+    private PortletToPageMap getPortletToPageMap(PortletSession session) {
+
+        PortletToPageMap map = (PortletToPageMap) session.getAttribute(SEARCH_CACHE);
+        long start = System.currentTimeMillis();
+        if (map == null) {
+            //System.out.println(".... starting loading of portlet page map");
+            map = new PortletToPageMap();
+            try {
+                Folder root = pageManager.getFolder("/");
+                traverse(root, map);
+            } catch (Exception e) {
+                e.printStackTrace();
+            }
+            session.setAttribute(SEARCH_CACHE, map);
+            //System.out.println(".... completed loading of " + map.portletSize() + " portlet
page map in " + (System.currentTimeMillis() - start) + " ms");
+            return map;
         }
         return map;
     }
@@ -253,9 +257,9 @@ public class SearchPortlet extends Gener
         if (links == null || links.size() == 0) {
             return configuration.getString("/" + PortalConfigurationConstants.PSML_PAGE_DEFAULT,
"/default-page.psml");
         }
-        String best = links.get(0);
-        for (String link: links) {
-            if (link.startsWith("/_")) {
+        String best = null;
+        for (String link : links) {
+            if (link.startsWith("/_") || link.startsWith("/system")) {
                 continue;
             }
             best = link;



---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@portals.apache.org
For additional commands, e-mail: jetspeed-dev-help@portals.apache.org


Mime
View raw message