roller-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From snoopd...@apache.org
Subject svn commit: r386740 - in /incubator/roller/trunk: src/org/roller/presentation/search/SearchAction.java src/org/roller/presentation/search/SearchResultsPageModel.java src/org/roller/presentation/search/SearchServlet.java web/theme/searchResults.jsp
Date Fri, 17 Mar 2006 22:13:34 GMT
Author: snoopdave
Date: Fri Mar 17 14:13:33 2006
New Revision: 386740

URL: http://svn.apache.org/viewcvs?rev=386740&view=rev
Log:
Fix for ROL-1086, fixes to search model and site wide search JSP

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=386740&r1=386739&r2=386740&view=diff
==============================================================================
--- incubator/roller/trunk/src/org/roller/presentation/search/SearchAction.java (original)
+++ incubator/roller/trunk/src/org/roller/presentation/search/SearchAction.java Fri Mar 17
14:13:33 2006
@@ -48,7 +48,7 @@
             HttpServletResponse response,
             ActionMapping mapping) throws RollerException, IOException {        
             super(titleKey, request, response, mapping);
-            setSearchModel(new SearchResultsPageModel(request));
+            setSearchModel(new SearchResultsPageModel(request, false));
         }
 
         public SearchResultsPageModel getSearchModel() {

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=386740&r1=386739&r2=386740&view=diff
==============================================================================
--- incubator/roller/trunk/src/org/roller/presentation/search/SearchResultsPageModel.java
(original)
+++ incubator/roller/trunk/src/org/roller/presentation/search/SearchResultsPageModel.java
Fri Mar 17 14:13:33 2006
@@ -26,6 +26,7 @@
 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;
@@ -51,6 +52,7 @@
     private Set      categories = new TreeSet();
     private boolean  websiteSpecificSearch = false;
     private String   errorMessage = null;
+    private boolean  useWrappers = false;
     
     /* How many results to display */
     private static int LIMIT = 10;
@@ -63,7 +65,8 @@
     private static ResourceBundle bundle = 
         ResourceBundle.getBundle("ApplicationResources");          
 
-    public SearchResultsPageModel(HttpServletRequest request) {        
+    public SearchResultsPageModel(HttpServletRequest request, boolean wrappers) { 
+        useWrappers = wrappers;
         try {            
             RollerRequest rreq = RollerRequest.getRollerRequest(request);
             setWebsiteSpecificSearch(checkForWebsite(request));
@@ -193,15 +196,34 @@
             
             // maybe null if search result returned inactive user
             // or entry's user is not the requested user.
-            if (entry != null) {
-                addToSearchResults(searchResults, WeblogEntryDataWrapper.wrap(entry));
-            }
+            if (entry != null && useWrappers) {
+                addEntryWrapperToSearchResults(searchResults, WeblogEntryDataWrapper.wrap(entry));
+            } 
+            else if (entry != null && !useWrappers) {
+                addEntryToSearchResults(searchResults, entry);
+            } 
         }
         rreq.getRequest().setAttribute("categories", categories);
         return searchResults;
     }
     
-    private void addToSearchResults(
+    private void addEntryToSearchResults(
+            TreeMap searchResults, WeblogEntryData entry) {
+        // convert entry's each date to midnight (00m 00h 00s)
+        Date midnight = DateUtil.getStartOfDay( entry.getPubTime() );
+        
+        // ensure we do not get duplicates from Lucene by
+        // using a Set Collection.  Entries sorted by pubTime.
+        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() );
+            searchResults.put(midnight, set);
+        }
+        set.add(entry);
+    }
+    
+    private void addEntryWrapperToSearchResults(
             TreeMap searchResults, WeblogEntryDataWrapper entry) {
         // convert entry's each date to midnight (00m 00h 00s)
         Date midnight = DateUtil.getStartOfDay( entry.getPubTime() );

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=386740&r1=386739&r2=386740&view=diff
==============================================================================
--- incubator/roller/trunk/src/org/roller/presentation/search/SearchServlet.java (original)
+++ incubator/roller/trunk/src/org/roller/presentation/search/SearchServlet.java Fri Mar 17
14:13:33 2006
@@ -52,36 +52,10 @@
         
         // search model executes search, makes results available to page
         SearchResultsPageModel model = 
-            new SearchResultsPageModel(rreq.getRequest());
+            new SearchResultsPageModel(rreq.getRequest(), true);
         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.
-     */
-    private Template generalSearchResults(
-            HttpServletRequest request, 
-            HttpServletResponse response, Context ctx) {
-        Template outty = null;
-        Exception pageException = null;
-        try {
-            ContextLoader.setupContext(
-                ctx, RollerRequest.getRollerRequest(request), response );
-            outty = getTemplate( "searchresults.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;
-    }
-    
 }
 
 

Modified: incubator/roller/trunk/web/theme/searchResults.jsp
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/web/theme/searchResults.jsp?rev=386740&r1=386739&r2=386740&view=diff
==============================================================================
--- incubator/roller/trunk/web/theme/searchResults.jsp (original)
+++ incubator/roller/trunk/web/theme/searchResults.jsp Fri Mar 17 14:13:33 2006
@@ -1,18 +1,18 @@
 <%@ include file="/taglibs.jsp" %>
 
 <%
-org.roller.presentation.search.SearchAction.PageModel pageModel =
+org.roller.presentation.search.SearchAction.PageModel model =
    (org.roller.presentation.search.SearchAction.PageModel)
       request.getAttribute("model");       
 org.roller.presentation.search.SearchResultsPageModel searchResults =
-    pageModel.getSearchModel();
+    model.getSearchModel();
 request.setAttribute("searchResults", searchResults);
 %>
 
 <%-- Display the search pager --%>
     
 <c:choose>
-   <c:when test="${empty pageModel.website}">
+   <c:when test="${empty model.website}">
       <c:set var="siteText" value="this site" />
    </c:when>
    <c:otherwise>
@@ -42,12 +42,12 @@
        <fmt:param value="${searchResults.hits}" />
     </fmt:message>    
     <c:url var="googleUrl" 
-         value="http://google.com/search?q=${searchResults.term}%20site:${pageModel.baseURL}"
/>    
+         value="http://google.com/search?q=${searchResults.term}%20site:${model.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="${pageModel.baseURL}" />/sitesearch.do'
+    <form method="get" action='<c:out value="${model.baseURL}" />/sitesearch.do'
         style="margin: 5px">
         <input type="text" id="q" name="q" size="31"
             maxlength="255" value='<c:out value="${searchResults.term}" />'
@@ -105,14 +105,14 @@
         <div class="daybox" style="margin: 0px 5px 0px 10px">
         <c:forEach var="post" items="${dayMap}">
 
-            <a href='<c:out value="${pageModel.baseURL}" /><c:out value="${post.permaLink}"
/>' class="entryTitle">
+            <a href='<c:out value="${model.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="${pageModel.baseURL}" />/page/<c:out value="${post.website.handle}"
/>'>
+                <a href='<c:out value="${model.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