Author: gttersen
Date: 2007-04-26 19:48:12 +0200 (Thu, 26 Apr 2007)
New Revision: 4893

Added:
   
trunk/core-api/src/main/java/no/schibstedsok/searchportal/result/handler/DocumentSummaryResultHandler.java
   
trunk/result-handler-config-spi/src/main/java/no/schibstedsok/searchportal/result/handler/DocumentSummaryResultHandlerConfig.java
Modified:
   
trunk/core-api/src/main/java/no/schibstedsok/searchportal/result/handler/AddCategoryNavigationResultHandler.java
   
trunk/core-api/src/main/java/no/schibstedsok/searchportal/result/handler/AddLastWeekModifierResultHandler.java
   
trunk/result-handler-config-spi/src/main/java/no/schibstedsok/searchportal/result/handler/AddCategoryNavigationResultHandlerConfig.java
   
trunk/result-handler-config-spi/src/main/java/no/schibstedsok/searchportal/result/handler/AddLastWeekModifierResultHandlerConfig.java
Log:
Fixes for newsAggregator

Modified: 
trunk/core-api/src/main/java/no/schibstedsok/searchportal/result/handler/AddCategoryNavigationResultHandler.java
===================================================================
--- 
trunk/core-api/src/main/java/no/schibstedsok/searchportal/result/handler/AddCategoryNavigationResultHandler.java
    2007-04-26 11:05:35 UTC (rev 4892)
+++ 
trunk/core-api/src/main/java/no/schibstedsok/searchportal/result/handler/AddCategoryNavigationResultHandler.java
    2007-04-26 17:48:12 UTC (rev 4893)
@@ -20,12 +20,11 @@
 import java.util.List;
 
 /**
- * 
- * @author 
+ * @author Geir H. Pettersen (T-Rank)
  * @version $Id$
  */
 public final class AddCategoryNavigationResultHandler implements ResultHandler 
{
-    
+
     private static final String CMD_ELEMENT_CATEGORY = "category";
     private static final String CMD_ATTR_DISPLAY_NAME = "display-name";
     private static final String CMD_ATTR_ID = "id";
@@ -36,18 +35,16 @@
     private final AddCategoryNavigationResultHandlerConfig config;
 
     /**
-     *
      * @param config
      */
-    public AddCategoryNavigationResultHandler(final ResultHandlerConfig 
config){
+    public AddCategoryNavigationResultHandler(final ResultHandlerConfig 
config) {
         this.config = (AddCategoryNavigationResultHandlerConfig) config;
     }
-    
 
+
     /**
-     * 
-     * @param cxt 
-     * @param datamodel 
+     * @param cxt
+     * @param datamodel
      */
     public void handleResult(Context cxt, DataModel datamodel) {
         try {
@@ -104,9 +101,8 @@
     }
 
     /**
-     * 
-     * @param categoriesElement 
-     * @return 
+     * @param categoriesElement
+     * @return
      */
     public List<Category> parseCategories(Element categoriesElement) {
         List<Element> categoryElements = getDirectChildren(categoriesElement, 
CMD_ELEMENT_CATEGORY);

Modified: 
trunk/core-api/src/main/java/no/schibstedsok/searchportal/result/handler/AddLastWeekModifierResultHandler.java
===================================================================
--- 
trunk/core-api/src/main/java/no/schibstedsok/searchportal/result/handler/AddLastWeekModifierResultHandler.java
      2007-04-26 11:05:35 UTC (rev 4892)
+++ 
trunk/core-api/src/main/java/no/schibstedsok/searchportal/result/handler/AddLastWeekModifierResultHandler.java
      2007-04-26 17:48:12 UTC (rev 4893)
@@ -19,27 +19,29 @@
  * <p/>
  * <b>Note:</b> The implementation of this depends on that the day modifiers 
are sorted descending (last date first)
  * <b>Note:</b> This will only work on searchResults that are actually 
FastSearchResult
- * 
+ *
+ * @author Geir H. Pettersen (T-Rank)
  * @version $Id$
  */
 public final class AddLastWeekModifierResultHandler implements ResultHandler {
-    
+
     private static final int DAYS_IN_WEEK = 7;
     private static final Logger LOG = 
Logger.getLogger(AddLastWeekModifierResultHandler.class);
-    
+
     private final AddLastWeekModifierResultHandlerConfig config;
-    
+
     /**
-     * 
-     * @param config 
+     * @param config
      */
-    public AddLastWeekModifierResultHandler(final ResultHandlerConfig config){
-        this.config = (AddLastWeekModifierResultHandlerConfig)config;
+    public AddLastWeekModifierResultHandler(final ResultHandlerConfig config) {
+        this.config = (AddLastWeekModifierResultHandlerConfig) config;
     }
 
-    /** [EMAIL PROTECTED] **/
+    /**
+     * [EMAIL PROTECTED] *
+     */
     public void handleResult(final Context cxt, final DataModel datamodel) {
-        
+
         try {
             final SearchResult searchResult = cxt.getSearchResult();
             if (searchResult instanceof FastSearchResult) {
@@ -71,7 +73,7 @@
                 Modifier newModifier = new Modifier(fromDate, weekCount, null);
                 fastResult.addModifier(config.getTargetNavigatorField(), 
newModifier);
             } else {
-                LOG.error("Can not use " + 
AddLastWeekModifierResultHandler.class.getName() 
+                LOG.error("Can not use " + 
AddLastWeekModifierResultHandler.class.getName()
                         + " on a generic searchResult. Must be a " + 
FastSearchResult.class.getName());
             }
         } catch (ParseException e) {

Added: 
trunk/core-api/src/main/java/no/schibstedsok/searchportal/result/handler/DocumentSummaryResultHandler.java
===================================================================
--- 
trunk/core-api/src/main/java/no/schibstedsok/searchportal/result/handler/DocumentSummaryResultHandler.java
                          (rev 0)
+++ 
trunk/core-api/src/main/java/no/schibstedsok/searchportal/result/handler/DocumentSummaryResultHandler.java
  2007-04-26 17:48:12 UTC (rev 4893)
@@ -0,0 +1,52 @@
+// Copyright (2007) Schibsted Søk AS
+package no.schibstedsok.searchportal.result.handler;
+
+import no.schibstedsok.searchportal.datamodel.DataModel;
+import no.schibstedsok.searchportal.result.SearchResult;
+import no.schibstedsok.searchportal.result.SearchResultItem;
+
+/**
+ * Used to create a document summary. Basically concatinates two fields if 
both are peresent and not empty(For all
+ * results) If not bothe fields are there it will populate the target field 
with a fallback field.
+ *
+ * @author Geir H. Pettersen (T-Rank)
+ */
+public class DocumentSummaryResultHandler implements ResultHandler {
+    private DocumentSummaryResultHandlerConfig config;
+
+    /**
+     * @param config the config
+     */
+    public DocumentSummaryResultHandler(final ResultHandlerConfig config) {
+        this.config = (DocumentSummaryResultHandlerConfig) config;
+
+    }
+
+    /**
+     * [EMAIL PROTECTED] *
+     */
+    public void handleResult(Context cxt, DataModel datamodel) {
+        setDocumentSummary(cxt.getSearchResult());
+    }
+
+    private void setDocumentSummary(SearchResult searchResult) {
+        if (searchResult != null && searchResult.getResults().size() > 0) {
+            for (SearchResultItem searchResultItem : 
searchResult.getResults()) {
+                if (config.getRecursiveField() != null) {
+                    
setDocumentSummary(searchResultItem.getNestedSearchResult(config.getRecursiveField()));
+                }
+                final String firstSummaryFieldValue = 
searchResultItem.getField(config.getFirstSummaryField());
+                final String secondSummaryFieldValue = 
searchResultItem.getField(config.getSecondSummaryField());
+                StringBuilder targetFieldValue = new StringBuilder();
+                if (firstSummaryFieldValue != null && secondSummaryFieldValue 
!= null && firstSummaryFieldValue.length() > 0 && 
secondSummaryFieldValue.length() > 0) {
+                    targetFieldValue.append(firstSummaryFieldValue);
+                    targetFieldValue.append(config.getFieldSeparator());
+                    targetFieldValue.append(secondSummaryFieldValue);
+                } else {
+                    
targetFieldValue.append(searchResultItem.getField(config.getFallbackField()));
+                }
+                searchResultItem.addField(config.getTargetField(), 
targetFieldValue.toString());
+            }
+        }
+    }
+}

Modified: 
trunk/result-handler-config-spi/src/main/java/no/schibstedsok/searchportal/result/handler/AddCategoryNavigationResultHandlerConfig.java
===================================================================
--- 
trunk/result-handler-config-spi/src/main/java/no/schibstedsok/searchportal/result/handler/AddCategoryNavigationResultHandlerConfig.java
     2007-04-26 11:05:35 UTC (rev 4892)
+++ 
trunk/result-handler-config-spi/src/main/java/no/schibstedsok/searchportal/result/handler/AddCategoryNavigationResultHandlerConfig.java
     2007-04-26 17:48:12 UTC (rev 4893)
@@ -3,12 +3,10 @@
 
 import 
no.schibstedsok.searchportal.result.handler.AbstractResultHandlerConfig.Controller;
 import org.apache.log4j.Logger;
-
 import org.w3c.dom.Element;
 
 /**
- * 
- * @author 
+ * @author Geir H. Pettersen (T-Rank)
  * @version $Id$
  */
 @Controller("AddCategoryNavigationResultHandler")
@@ -19,39 +17,35 @@
     private String categoryFields;
 
     /**
-     * 
-     * @return 
+     * @return
      */
     public String getCategoriesXml() {
         return categoriesXml;
     }
 
     /**
-     * 
-     * @param categoriesXml 
+     * @param categoriesXml
      */
     public void setCategoriesXml(String categoriesXml) {
         this.categoriesXml = categoriesXml;
     }
 
     /**
-     * 
-     * @return 
+     * @return
      */
     public String getCategoryFields() {
         return categoryFields;
     }
 
     /**
-     * 
-     * @param categoryFields 
+     * @param categoryFields
      */
     public void setCategoryFields(String categoryFields) {
         this.categoryFields = categoryFields;
     }
 
     public AddCategoryNavigationResultHandlerConfig readResultHandler(Element 
element) {
-        
+
         super.readResultHandler(element);
         setCategoryFields(element.getAttribute("category-fields"));
         final String categoryXml = element.getAttribute("categories-xml");

Modified: 
trunk/result-handler-config-spi/src/main/java/no/schibstedsok/searchportal/result/handler/AddLastWeekModifierResultHandlerConfig.java
===================================================================
--- 
trunk/result-handler-config-spi/src/main/java/no/schibstedsok/searchportal/result/handler/AddLastWeekModifierResultHandlerConfig.java
       2007-04-26 11:05:35 UTC (rev 4892)
+++ 
trunk/result-handler-config-spi/src/main/java/no/schibstedsok/searchportal/result/handler/AddLastWeekModifierResultHandlerConfig.java
       2007-04-26 17:48:12 UTC (rev 4893)
@@ -10,78 +10,71 @@
  * <p/>
  * <b>Note:</b> The implementation of this depends on that the day modifiers 
are sorted descending (last date first)
  * <b>Note:</b> This will only work on searchResults that are actually 
FastSearchResult
- * 
+ *
+ * @author Geir H. Pettersen (T-Rank)
  * @version $Id$
  */
 @Controller("AddLastWeekModifierResultHandler")
 public final class AddLastWeekModifierResultHandlerConfig extends 
AbstractResultHandlerConfig {
-    
+
     private static final Logger LOG = 
Logger.getLogger(AddLastWeekModifierResultHandlerConfig.class);
-    
+
     private String dayFormat = "yyyy-MM-dd";
     private String timeZone = "UTC";
     private String dayModifierKey;
     private String targetNavigatorField;
 
     /**
-     * 
-     * @return 
+     * @return
      */
     public String getDayFormat() {
         return dayFormat;
     }
 
     /**
-     * 
-     * @param dayFormat 
+     * @param dayFormat
      */
     public void setDayFormat(String dayFormat) {
         this.dayFormat = dayFormat;
     }
 
     /**
-     * 
-     * @return 
+     * @return
      */
     public String getDayModifierKey() {
         return dayModifierKey;
     }
 
     /**
-     * 
-     * @param dayModifierKey 
+     * @param dayModifierKey
      */
     public void setDayModifierKey(String dayModifierKey) {
         this.dayModifierKey = dayModifierKey;
     }
 
     /**
-     * 
-     * @return 
+     * @return
      */
     public String getTargetNavigatorField() {
         return targetNavigatorField;
     }
 
     /**
-     * 
-     * @param targetNavigatorField 
+     * @param targetNavigatorField
      */
     public void setTargetNavigatorField(String targetNavigatorField) {
         this.targetNavigatorField = targetNavigatorField;
     }
 
     /**
-     * 
-     * @return 
+     * @return
      */
     public String getTimeZone() {
         return timeZone;
     }
 
     /**
-     * 
-     * @param timeZone 
+     * @param timeZone
      */
     public void setTimeZone(String timeZone) {
         this.timeZone = timeZone;
@@ -89,7 +82,7 @@
 
     @Override
     public AbstractResultHandlerConfig readResultHandler(final Element 
element) {
-        
+
         super.readResultHandler(element);
 
         setDayModifierKey(element.getAttribute("day-modifier-key"));
@@ -105,6 +98,6 @@
 
         return this;
     }
-    
-    
+
+
 }

Added: 
trunk/result-handler-config-spi/src/main/java/no/schibstedsok/searchportal/result/handler/DocumentSummaryResultHandlerConfig.java
===================================================================
--- 
trunk/result-handler-config-spi/src/main/java/no/schibstedsok/searchportal/result/handler/DocumentSummaryResultHandlerConfig.java
                           (rev 0)
+++ 
trunk/result-handler-config-spi/src/main/java/no/schibstedsok/searchportal/result/handler/DocumentSummaryResultHandlerConfig.java
   2007-04-26 17:48:12 UTC (rev 4893)
@@ -0,0 +1,79 @@
+// Copyright (2007) Schibsted Søk AS
+package no.schibstedsok.searchportal.result.handler;
+
+import 
no.schibstedsok.searchportal.result.handler.AbstractResultHandlerConfig.Controller;
+import org.w3c.dom.Element;
+
+/**
+ * Used to create a document summary. Basically concatinates two fields if 
both are peresent and not empty(For all
+ * results) If not bothe fields are there it will populate the target field 
with a fallback field.
+ *
+ * @author Geir H. Pettersen (T-Rank)
+ */
[EMAIL PROTECTED]("DocumentSummaryResultHandler")
+public class DocumentSummaryResultHandlerConfig extends 
AbstractResultHandlerConfig {
+    private String firstSummaryField;
+    private String secondSummaryField;
+    private String fallbackField;
+    private String targetField;
+    private String recursiveField;
+    private String fieldSeparator;
+
+    /**
+     * @return the firrst summary field to cocncatenate
+     */
+    public String getFirstSummaryField() {
+        return firstSummaryField;
+    }
+
+    /**
+     * @return the second summary field to concatenate
+     */
+    public String getSecondSummaryField() {
+        return secondSummaryField;
+    }
+
+    /**
+     * @return the field to fall back to if not both summary fields are 
populated
+     */
+    public String getFallbackField() {
+        return fallbackField;
+    }
+
+    /**
+     * @return the target field to populate
+     */
+    public String getTargetField() {
+        return targetField;
+    }
+
+    /**
+     * @return if defined, the field that contains subresults to process
+     */
+    public String getRecursiveField() {
+        return recursiveField;
+    }
+
+
+    /**
+     * @return the text to separate the conactenated fields
+     */
+    public String getFieldSeparator() {
+        return fieldSeparator;
+    }
+
+    @Override
+    public AbstractResultHandlerConfig readResultHandler(final Element 
element) {
+        firstSummaryField = element.getAttribute("first-summary-field");
+        secondSummaryField = element.getAttribute("second-summary-field");
+        fallbackField = element.getAttribute("fallback-field");
+        targetField = element.getAttribute("target-field");
+        recursiveField = element.getAttribute("recursive-field");
+        if (recursiveField != null && recursiveField.length() == 0) {
+            recursiveField = null;
+        }
+        fieldSeparator = element.getAttribute("field-separator");
+        return this;
+    }
+
+}

_______________________________________________
Kernel-commits mailing list
[email protected]
http://sesat.no/mailman/listinfo/kernel-commits

Reply via email to