Update of 
/var/cvs/contributions/CMSContainer/cmsc/search/src/java/com/finalist/cmsc/services/search
In directory 
james.mmbase.org:/tmp/cvs-serv13475/cmsc/search/src/java/com/finalist/cmsc/services/search

Modified Files:
        SearchServiceMMBaseImpl.java RedirectServlet.java 
Log Message:
CMSC-1207 CollectionChannels are not always processed in the SearchService


See also: 
http://cvs.mmbase.org/viewcvs/contributions/CMSContainer/cmsc/search/src/java/com/finalist/cmsc/services/search
See also: http://www.mmbase.org/jira/browse/CMSC-1207


Index: SearchServiceMMBaseImpl.java
===================================================================
RCS file: 
/var/cvs/contributions/CMSContainer/cmsc/search/src/java/com/finalist/cmsc/services/search/SearchServiceMMBaseImpl.java,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -b -r1.28 -r1.29
--- SearchServiceMMBaseImpl.java        7 Aug 2008 10:03:49 -0000       1.28
+++ SearchServiceMMBaseImpl.java        29 Dec 2008 13:48:38 -0000      1.29
@@ -48,6 +48,7 @@
 
    protected Map<String, Integer> priorities = new HashMap<String, Integer>();
    protected boolean usePosition;
+   protected boolean preferContentChannels;
 
 
    @Override
@@ -74,6 +75,7 @@
       }
 
       usePosition = aProperties.getBoolean("filter.usePosition", false);
+      preferContentChannels = 
aProperties.getBoolean("filter.preferContentChannels", true);
    }
 
 
@@ -245,7 +247,7 @@
 
 
    protected List<PageInfo> findAllDetailPages(Node content, int pageId) {
-       List<Node> pages = findPagesForContent(content, null, pageId);
+       List<Node> pages = findPagesForContent(content, null, pageId, 
preferContentChannels);
       return convertToPageInfos(pages);
    }
 
@@ -337,17 +339,20 @@
 
    @Override
    public boolean hasContentPages(Node content) {
-      NodeList pages = findPagesForContent(content, null);
+      NodeList pages = findPagesForContent(content, null, 
preferContentChannels);
       return (pages != null && pages.size() > 0);
    }
 
-
    protected NodeList findPagesForContent(Node content, Node channel) {
-      return findPagesForContent(content, channel, ANY_PAGE);
+      return findPagesForContent(content, channel, preferContentChannels);
+   }
+   
+   protected NodeList findPagesForContent(Node content, Node channel, boolean 
preferContentChannels) {
+      return findPagesForContent(content, channel, ANY_PAGE, 
preferContentChannels);
    }
 
 
-   protected NodeList findPagesForContent(Node content, Node channel, int 
pageid) {
+   protected NodeList findPagesForContent(Node content, Node channel, int 
pageid, boolean preferContentChannels) {
       Cloud cloud;
       if (content != null) {
           cloud = content.getCloud();
@@ -369,37 +374,61 @@
       else {
          channels = RepositoryUtil.getContentChannelsForContent(content);
       }
-
+      NodeList pages = null;
+      if (preferContentChannels) {
       if (content != null) {
          channels.add(content);
       }
 
       Query query = createPagesForContentQuery(cloud, channels, pageid);
 
-      NodeList pages = cloud.getList(query);
+         pages = cloud.getList(query);
       if (pages.isEmpty()) {
          if (content != null) {
             channels.remove(content);
          }
-         NodeList collectionchannels = cloud.createNodeList();
-         for (Iterator<Node> iter = channels.iterator(); iter.hasNext();) {
-            Node contentchannel = iter.next();
-            NodeList cc = RepositoryUtil.getCollectionChannels(contentchannel);
-            if (!cc.isEmpty()) {
-               collectionchannels.addAll(cc);
-            }
-         }
+            NodeList collectionchannels = getCollectionsForChannels(cloud, 
channels);
          if (!collectionchannels.isEmpty()) {
             Query collectionquery = createPagesForContentQuery(cloud, 
collectionchannels, pageid);
             pages = cloud.getList(collectionquery);
          }
       }
+      }
+      else {
+         NodeList collectionchannels = getCollectionsForChannels(cloud, 
channels);
+         channels.addAll(collectionchannels);
+         
       if (content != null) {
-         filterPageQueryNodes(pages, content);
+            channels.add(content);
+         }
+   
+         Query query = createPagesForContentQuery(cloud, channels, pageid);
+         pages = cloud.getList(query);
       }
+      if (pages != null) {
 
+         if (content != null) {
+            filterPageQueryNodes(pages, content);
+         }
       return pages;
    }
+      else {
+         return cloud.createNodeList();
+      }
+   }
+
+
+   private NodeList getCollectionsForChannels(Cloud cloud, NodeList channels) {
+      NodeList collectionchannels = cloud.createNodeList();
+      for (Iterator<Node> iter = channels.iterator(); iter.hasNext();) {
+         Node contentchannel = iter.next();
+         NodeList cc = RepositoryUtil.getCollectionChannels(contentchannel);
+         if (!cc.isEmpty()) {
+            collectionchannels.addAll(cc);
+         }
+      }
+      return collectionchannels;
+   }
 
 
    protected Query createPagesForContentQuery(Cloud cloud, NodeList channels, 
int pageid) {
@@ -465,7 +494,7 @@
                       String value = ((NodeParameter) 
param).getValueAsString();
                       if (value != null) {
                          Node found = cloud.getNode(value);
-                         if (RepositoryUtil.isContentChannel(found)) {
+                         if (RepositoryUtil.isChannel(found)) {
                             NodeList elements = 
RepositoryUtil.getLinkedElements(found);
                             for (Iterator<Node> iterator = 
elements.iterator(); iterator.hasNext();) {
                                Node contentElement = iterator.next();
@@ -493,6 +522,9 @@
 
 
    protected boolean isDetailPortlet(Portlet portlet) {
+      if (portlet == null) {
+         return false;
+      }
       String contentchannel = portlet.getParameterValue(CONTENTCHANNEL);
       if (contentchannel != null) {
          String pageNumber = portlet.getParameterValue(PAGE);


Index: RedirectServlet.java
===================================================================
RCS file: 
/var/cvs/contributions/CMSContainer/cmsc/search/src/java/com/finalist/cmsc/services/search/RedirectServlet.java,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -b -r1.14 -r1.15
--- RedirectServlet.java        2 Jun 2008 21:56:34 -0000       1.14
+++ RedirectServlet.java        29 Dec 2008 13:48:38 -0000      1.15
@@ -127,9 +127,17 @@
                     if (hostIndex > -1) {
                         // The same host as the contenturl. strip servername 
and port
                         int firstSlash = redirect.indexOf("/", hostIndex + 
"://".length());
+                        if (firstSlash > -1) {
                         redirect = redirect.substring(firstSlash);
                     }
                     else {
+                           // firstSlash is -1 when there is a contentportlet 
on the homepage
+                           // and servername is true
+                           response.sendRedirect(redirect);
+                           return;
+                        }
+                    }
+                    else {
                         // can not convert so just redirect.
                         response.sendRedirect(redirect);
                         return;
_______________________________________________
Cvs mailing list
[email protected]
http://lists.mmbase.org/mailman/listinfo/cvs

Reply via email to