roller-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From snoopd...@apache.org
Subject svn commit: r376161 - in /incubator/roller/trunk: src/org/roller/presentation/search/ web/WEB-INF/classes/ web/theme/
Date Thu, 09 Feb 2006 02:59:31 GMT
Author: snoopdave
Date: Wed Feb  8 18:59:30 2006
New Revision: 376161

URL: http://svn.apache.org/viewcvs?rev=376161&view=rev
Log:
Fixes ROL-1040: in-line search results broken

Removed:
    incubator/roller/trunk/web/WEB-INF/classes/searchdisabled.vm
    incubator/roller/trunk/web/WEB-INF/classes/searchresults.vm
    incubator/roller/trunk/web/WEB-INF/classes/searchresults_day.vm
Modified:
    incubator/roller/trunk/src/org/roller/presentation/search/SearchAction.java
    incubator/roller/trunk/src/org/roller/presentation/search/SearchResultsPageModel.java
    incubator/roller/trunk/src/org/roller/presentation/search/SearchServlet.java
    incubator/roller/trunk/web/theme/searchResults.jsp

Modified: incubator/roller/trunk/src/org/roller/presentation/search/SearchAction.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/src/org/roller/presentation/search/SearchAction.java?rev=376161&r1=376160&r2=376161&view=diff
==============================================================================
--- incubator/roller/trunk/src/org/roller/presentation/search/SearchAction.java (original)
+++ incubator/roller/trunk/src/org/roller/presentation/search/SearchAction.java Wed Feb  8
18:59:30 2006
@@ -5,13 +5,16 @@
  */
 package org.roller.presentation.search;
 
+import java.io.IOException;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import org.apache.struts.action.Action;
 import org.apache.struts.action.ActionForm;
 import org.apache.struts.action.ActionForward;
 import org.apache.struts.action.ActionMapping;
+import org.roller.RollerException;
 import org.roller.config.RollerConfig;
+import org.roller.presentation.BasePageModel;
 
 /**
  * Executes site wide search.
@@ -32,9 +35,28 @@
             return mapping.findForward("main");
         }           
         // search model executes search, makes results available to page
-        SearchResultsPageModel model = new SearchResultsPageModel(
-                "search.title", request, response, mapping);
-        request.setAttribute("searchResults", model);
+        PageModel model = new PageModel("search.title", request, response, mapping);
+        request.setAttribute("model", model);
         return mapping.findForward("search.page");
+    }
+    
+    public class PageModel extends BasePageModel {
+        private SearchResultsPageModel searchModel = null;
+        public PageModel(
+            String titleKey,
+            HttpServletRequest request,
+            HttpServletResponse response,
+            ActionMapping mapping) throws RollerException, IOException {        
+            super(titleKey, request, response, mapping);
+            setSearchModel(new SearchResultsPageModel(request));
+        }
+
+        public SearchResultsPageModel getSearchModel() {
+            return searchModel;
+        }
+
+        public void setSearchModel(SearchResultsPageModel searchModel) {
+            this.searchModel = searchModel;
+        }
     }
 }

Modified: incubator/roller/trunk/src/org/roller/presentation/search/SearchResultsPageModel.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/src/org/roller/presentation/search/SearchResultsPageModel.java?rev=376161&r1=376160&r2=376161&view=diff
==============================================================================
--- incubator/roller/trunk/src/org/roller/presentation/search/SearchResultsPageModel.java
(original)
+++ incubator/roller/trunk/src/org/roller/presentation/search/SearchResultsPageModel.java
Wed Feb  8 18:59:30 2006
@@ -13,13 +13,11 @@
 import java.util.TreeMap;
 import java.util.TreeSet;
 import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
 import org.apache.commons.collections.comparators.ReverseComparator;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.lucene.document.Document;
 import org.apache.lucene.search.Hits;
-import org.apache.struts.action.ActionMapping;
 import org.roller.RollerException;
 import org.roller.business.search.FieldConstants;
 import org.roller.business.search.operations.SearchOperation;
@@ -28,20 +26,22 @@
 import org.roller.model.RollerFactory;
 import org.roller.model.UserManager;
 import org.roller.model.WeblogManager;
-import org.roller.pojos.WeblogEntryComparator;
 import org.roller.pojos.WeblogEntryData;
+import org.roller.pojos.WeblogEntryWrapperComparator;
 import org.roller.pojos.WebsiteData;
-import org.roller.presentation.BasePageModel;
+import org.roller.pojos.wrapper.WeblogEntryDataWrapper;
 import org.roller.presentation.RollerRequest;
 import org.roller.util.DateUtil;
 import org.roller.util.StringUtils;
 
+
+
 /**
  * Encapsulate seach result in page model so it can be used from Velocity or JSP.
  * @author Min (original code)
  * @author Dave Johnson (encapsulation)
  */
-public class SearchResultsPageModel extends BasePageModel {
+public class SearchResultsPageModel {
     
     private String   term = "";
     private Integer  hits = new Integer(0);
@@ -63,53 +63,54 @@
     private static ResourceBundle bundle = 
         ResourceBundle.getBundle("ApplicationResources");          
 
-    public SearchResultsPageModel(
-        String titleKey,
-        HttpServletRequest request,
-        HttpServletResponse response,
-        ActionMapping mapping) throws RollerException, IOException {
-        
-        super(titleKey, request, response, mapping);
+    public SearchResultsPageModel(HttpServletRequest request) {        
+        try {            
+            RollerRequest rreq = RollerRequest.getRollerRequest(request);
+            setWebsiteSpecificSearch(checkForWebsite(request));
+            
+            SearchOperation search =
+                new SearchOperation(RollerFactory.getRoller().getIndexManager());
+            search.setTerm(request.getParameter("q"));
+            setTerm(request.getParameter("q"));
+
+            WebsiteData website = null;
+            if (isWebsiteSpecificSearch()) {
+                website = rreq.getWebsite();
+                search.setWebsiteHandle(rreq.getWebsite().getHandle());
+            }
 
-        setWebsiteSpecificSearch(checkForWebsite(request));
-        RollerRequest rreq = RollerRequest.getRollerRequest(request);
-        
-        SearchOperation search =
-            new SearchOperation(RollerFactory.getRoller().getIndexManager());
-        search.setTerm(request.getParameter("q"));
-        setTerm(request.getParameter("q"));
-
-        WebsiteData website = null;
-        if (isWebsiteSpecificSearch()) {
-            website = rreq.getWebsite();
-            search.setWebsiteHandle(rreq.getWebsite().getHandle());
-        }
-
-        if (StringUtils.isNotEmpty(request.getParameter("c"))) {
-            search.setCategory(request.getParameter("c"));
-        }
-
-        // execute search
-        executeSearch(RollerFactory.getRoller(), search);
-
-        if (search.getResultsCount() == -1) {
-            // this means there has been a parsing (or IO) error
-            setErrorMessage(bundle.getString("error.searchProblem"));
-        } else {
-            // Convert the Hits into WeblogEntryData instances.
-            Hits hits = search.getResults();
-            setResults(convertHitsToEntries(rreq, website, hits));
-            setOffset((Integer)request.getAttribute("offset"));
-            setLimit((Integer)request.getAttribute("limit"));
-            if (request.getAttribute("categories") != null) {
-                Set cats = (Set)request.getAttribute("categories");
-                if (cats.size() > 0) {
-                    setCategories(cats);
+            if (StringUtils.isNotEmpty(request.getParameter("c"))) {
+                search.setCategory(request.getParameter("c"));
+            }
+
+            // execute search
+            executeSearch(RollerFactory.getRoller(), search);
+
+            if (search.getResultsCount() == -1) {
+                // this means there has been a parsing (or IO) error
+                setErrorMessage(bundle.getString("error.searchProblem"));
+            } else {
+                // Convert the Hits into WeblogEntryData instances.
+                Hits hits = search.getResults();
+                setResults(convertHitsToEntries(rreq, website, hits));
+                setOffset((Integer)request.getAttribute("offset"));
+                setLimit((Integer)request.getAttribute("limit"));
+                if (request.getAttribute("categories") != null) {
+                    Set cats = (Set)request.getAttribute("categories");
+                    if (cats.size() > 0) {
+                        setCategories(cats);
+                    }
                 }
             }
+            setHits(new Integer(search.getResultsCount()));
+            
+        } catch (IOException ex) {
+            mLogger.error("ERROR: initializing search page model");
+        } catch (RollerException ex) {
+            mLogger.error("ERROR: initializing search page model");
         }
-        setHits(new Integer(search.getResultsCount()));
     }
+    
     private void executeSearch(Roller roller, SearchOperation search)
         throws RollerException {
         IndexManager indexMgr = roller.getIndexManager();
@@ -118,6 +119,7 @@
             mLogger.debug("numresults = " + search.getResultsCount());
         }
     }
+    
     /** Look in PathInfo so req.getRemoteUser() doesn't interfere. */
     private boolean checkForWebsite(HttpServletRequest request) {
         if (StringUtils.isNotEmpty(
@@ -133,7 +135,8 @@
         }
         return false;
     }
-   /**
+  
+    /**
      * Iterate over Hits and build sets of WeblogEntryData
      * objects, placed into Date buckets (in reverse order).
      * @param rreq
@@ -191,14 +194,15 @@
             // maybe null if search result returned inactive user
             // or entry's user is not the requested user.
             if (entry != null) {
-                addToSearchResults(searchResults, entry);
+                addToSearchResults(searchResults, WeblogEntryDataWrapper.wrap(entry));
             }
         }
         rreq.getRequest().setAttribute("categories", categories);
         return searchResults;
     }
+    
     private void addToSearchResults(
-            TreeMap searchResults, WeblogEntryData entry) {
+            TreeMap searchResults, WeblogEntryDataWrapper entry) {
         // convert entry's each date to midnight (00m 00h 00s)
         Date midnight = DateUtil.getStartOfDay( entry.getPubTime() );
         
@@ -207,11 +211,12 @@
         TreeSet set = (TreeSet) searchResults.get(midnight);
         if (set == null) {
             // date is not mapped yet, so we need a new Set
-            set = new TreeSet( new WeblogEntryComparator() );
+            set = new TreeSet( new WeblogEntryWrapperComparator() );
             searchResults.put(midnight, set);
         }
         set.add(entry);
     }
+    
     private int useOffset(HttpServletRequest request) {
         int offset = OFFSET;
         if (request.getParameter("o") != null) {
@@ -223,6 +228,7 @@
         }
         return offset;
     }
+    
     private int useLimit(HttpServletRequest request) {
         int limit = LIMIT;
         if (request.getParameter("n") != null) {

Modified: incubator/roller/trunk/src/org/roller/presentation/search/SearchServlet.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/src/org/roller/presentation/search/SearchServlet.java?rev=376161&r1=376160&r2=376161&view=diff
==============================================================================
--- incubator/roller/trunk/src/org/roller/presentation/search/SearchServlet.java (original)
+++ incubator/roller/trunk/src/org/roller/presentation/search/SearchServlet.java Wed Feb 
8 18:59:30 2006
@@ -8,12 +8,12 @@
 import org.apache.commons.logging.LogFactory;
 import org.apache.velocity.Template;
 import org.apache.velocity.context.Context;
-import org.apache.velocity.servlet.VelocityServlet;
+import org.apache.velocity.exception.ResourceNotFoundException;
+import org.roller.RollerException;
 import org.roller.config.RollerConfig;
 import org.roller.presentation.RollerRequest;
 import org.roller.presentation.velocity.ContextLoader;
-import org.roller.util.StringUtils;
-
+import org.roller.presentation.velocity.PageServlet;
 
 /**
  * This servlet retrieves (and displays) search results.
@@ -22,7 +22,7 @@
  * @web.servlet-init-param name="properties" value="/WEB-INF/velocity.properties"
  * @web.servlet-mapping url-pattern="/search/*"
  */
-public class SearchServlet extends VelocityServlet {
+public class SearchServlet extends PageServlet {
     
     static final long serialVersionUID = -2150090108300585670L;
     
@@ -39,57 +39,24 @@
         this.searchEnabled = RollerConfig.getBooleanProperty("search.enabled");
     }
     
-    
-    public Template handleRequest(HttpServletRequest request,
-            HttpServletResponse response, Context ctx) {
-
-        Template outty = null;
-        try {
-            if(! this.searchEnabled) {
-                Exception pageException = null;
-                try {
-                    ContextLoader.setupContext(
-                        ctx, RollerRequest.getRollerRequest(request), response );
-                    outty = getTemplate( "searchdisabled.vm", "UTF-8" );
-                } catch (Exception e) {
-                   pageException = e;
-                   response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
-                }
-
-                if (pageException != null) {
-                    mLogger.error("EXCEPTION: in RollerServlet", pageException);
-                    request.setAttribute("DisplayException", pageException);
-                }
-                return outty;
-            }
-
-            // do no work if query term is empty
-            if (StringUtils.isEmpty(request.getParameter("q"))) {
-                return generalSearchResults(request, response, ctx);
-            }
-
-            // search model executes search, makes results available to page
-            SearchResultsPageModel model = 
-                    new SearchResultsPageModel("", request, response, null);
-            ctx.put("searchResults", model);
-
-            // load standard Velocity stff
-            ContextLoader.setupContext(
-                ctx, RollerRequest.getRollerRequest(request), response );
-
-            request.setAttribute("zzz_VelocityContext_zzz", ctx); // for testing
-            
-            outty = getTemplate( "searchresults.vm", "UTF-8" );
+    /**
+     * Prepare the requested page for execution by setting content type
+     * and populating velocity context.
+     */
+    protected Template prepareForPageExecution(
+            Context ctx,
+            RollerRequest rreq,
+            HttpServletResponse response,
+            org.roller.pojos.Template page)             
+        throws ResourceNotFoundException, RollerException {
         
-        } catch (Exception e) {
-            response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
-            request.setAttribute("DisplayException", e);
-            mLogger.error("EXCEPTION: in SearchServlet", e);
-        }      
-        return outty;
+        // search model executes search, makes results available to page
+        SearchResultsPageModel model = 
+            new SearchResultsPageModel(rreq.getRequest());
+        ctx.put("searchResults", model);
+        return super.prepareForPageExecution(ctx, rreq, response, page);
     }
-    
-    
+        
     /**
      * If this is not a user-specific search, we need to display the
      * "generic" search results list.

Modified: incubator/roller/trunk/web/theme/searchResults.jsp
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/web/theme/searchResults.jsp?rev=376161&r1=376160&r2=376161&view=diff
==============================================================================
--- incubator/roller/trunk/web/theme/searchResults.jsp (original)
+++ incubator/roller/trunk/web/theme/searchResults.jsp Wed Feb  8 18:59:30 2006
@@ -1,15 +1,18 @@
 <%@ include file="/taglibs.jsp" %>
 
 <%
+org.roller.presentation.search.SearchAction.PageModel pageModel =
+   (org.roller.presentation.search.SearchAction.PageModel)
+      request.getAttribute("model");       
 org.roller.presentation.search.SearchResultsPageModel searchResults =
-   (org.roller.presentation.search.SearchResultsPageModel)
-      request.getAttribute("searchResults");       
+    pageModel.getSearchModel();
+request.setAttribute("searchResults", searchResults);
 %>
 
 <%-- Display the search pager --%>
     
 <c:choose>
-   <c:when test="${empty searchResults.website}">
+   <c:when test="${empty pageModel.website}">
       <c:set var="siteText" value="this site" />
    </c:when>
    <c:otherwise>
@@ -39,12 +42,12 @@
        <fmt:param value="${searchResults.hits}" />
     </fmt:message>    
     <c:url var="googleUrl" 
-         value="http://google.com/search?q=${searchResults.term}%20site:${searchResults.baseURL}"
/>    
+         value="http://google.com/search?q=${searchResults.term}%20site:${pageModel.baseURL}"
/>    
     <a href='<c:out value="${googleUrl}" />'
         class="google"><fmt:message key="macro.searchresults.hits_2" /></a>
 
     <%-- Form to search again --%>
-    <form method="get" action='<c:out value="${searchResults.baseURL}" />/sitesearch.do'
+    <form method="get" action='<c:out value="${pageModel.baseURL}" />/sitesearch.do'
         style="margin: 5px">
         <input type="text" id="q" name="q" size="31"
             maxlength="255" value='<c:out value="${searchResults.term}" />'
@@ -102,14 +105,14 @@
         <div class="daybox" style="margin: 0px 5px 0px 10px">
         <c:forEach var="post" items="${dayMap}">
 
-            <a href='<c:out value="${searchResults.baseURL}" /><c:out value="${post.permaLink}"
/>' class="entryTitle">
+            <a href='<c:out value="${pageModel.baseURL}" /><c:out value="${post.permaLink}"
/>' class="entryTitle">
                 <str:truncateNicely upper="90" >
                    <c:out value="${post.displayTitle}" />
                 </str:truncateNicely></a>
             </a><br />
 
             <span class="entryDetails">
-                <a href='<c:out value="${searchResults.baseURL}" />/page/<c:out
value="${post.website.handle}" />'>
+                <a href='<c:out value="${pageModel.baseURL}" />/page/<c:out value="${post.website.handle}"
/>'>
                 <str:truncateNicely upper="50" >
                    <c:out value="${post.website.name}" />
                 </str:truncateNicely></a> |



Mime
View raw message