Author: ssmiweve
Date: 2008-08-26 23:55:54 +0200 (Tue, 26 Aug 2008)
New Revision: 6792

Modified:
   
branches/2.17/generic.sesam/run-handler-control/src/main/java/no/sesat/search/run/handler/CopySearchRunHandler.java
   
branches/2.17/result-spi/src/main/java/no/sesat/search/result/BasicResultList.java
Log:
https://jira.sesam.no/jira/browse/SVERIGE-1349
 live collection was passed through from one SearchDataObject to the next :-(
 a better copy constructors implemented in BasicResultList,
  and CopySearchRunHandler handles copying what the copy constructor cannot.


Modified: 
branches/2.17/generic.sesam/run-handler-control/src/main/java/no/sesat/search/run/handler/CopySearchRunHandler.java
===================================================================
--- 
branches/2.17/generic.sesam/run-handler-control/src/main/java/no/sesat/search/run/handler/CopySearchRunHandler.java
 2008-08-25 14:04:23 UTC (rev 6791)
+++ 
branches/2.17/generic.sesam/run-handler-control/src/main/java/no/sesat/search/run/handler/CopySearchRunHandler.java
 2008-08-26 21:55:54 UTC (rev 6792)
@@ -26,6 +26,10 @@
 import no.sesat.search.datamodel.DataModelFactory;
 import no.sesat.search.datamodel.generic.DataObject;
 import no.sesat.search.datamodel.search.SearchDataObject;
+import no.sesat.search.result.BasicResultItem;
+import no.sesat.search.result.BasicResultList;
+import no.sesat.search.result.ResultItem;
+import no.sesat.search.result.ResultList;
 import no.sesat.search.site.Site;
 import no.sesat.search.site.SiteKeyedFactoryInstantiationException;
 import org.apache.log4j.Logger;
@@ -35,6 +39,12 @@
 /**
  * Copy a SearchDataObject (with a new name).
  *
+ * The results is an instance of BasicResultList<BasicResultItem> with
+ *  the list re-constructed with BasicResultList's copy constructor, and
+ *   each item re-constructed with BasicResultItem's copy constructor.
+ * Be warned as particular functionality belonging to an implementation of 
ResultList or ResultItem
+ *  other than BasicResultList and BasicResultItem may be lost.
+ *
  * @version $Id$
  *
  */
@@ -62,7 +72,7 @@
 
 
     public CopySearchRunHandler(final RunHandlerConfig rhc) {
-       config =  (CopySearchRunHandlerConfig) rhc;
+        config =  (CopySearchRunHandlerConfig) rhc;
     }
 
 
@@ -74,13 +84,17 @@
 
         final SearchDataObject from = datamodel.getSearch(config.getFrom());
 
+        final ResultList<ResultItem> resultList = new 
BasicResultList<ResultItem>(from.getResults());
+        for(ResultItem item : from.getResults().getResults()){
+            resultList.addResult(new BasicResultItem(item));
+        }
 
         final SearchDataObject searchDO = factory.instantiate(
                 SearchDataObject.class,
                 datamodel,
                 new DataObject.Property("configuration", 
from.getConfiguration()),
                 new DataObject.Property("query", from.getQuery()),
-                new DataObject.Property("results", from.getResults()));
+                new DataObject.Property("results", resultList));
 
         datamodel.setSearch(config.getTo(), searchDO);
     }

Modified: 
branches/2.17/result-spi/src/main/java/no/sesat/search/result/BasicResultList.java
===================================================================
--- 
branches/2.17/result-spi/src/main/java/no/sesat/search/result/BasicResultList.java
  2008-08-25 14:04:23 UTC (rev 6791)
+++ 
branches/2.17/result-spi/src/main/java/no/sesat/search/result/BasicResultList.java
  2008-08-26 21:55:54 UTC (rev 6792)
@@ -30,10 +30,10 @@
 
 /**
  * A simple implementation of a search result.
- * Is not multi-thread safe. 
+ * Is not multi-thread safe.
  * All fields (of all types) handled by superclass BasicSearchResultItem.
  *
- * @param T the type of ResultItem the ResultList contains.
+ * @param <T> the type of ResultItem the ResultList contains.
  * @author <a href="mailto:[EMAIL PROTECTED]">Magnus Eklund</a>
  * @version <tt>$Id$</tt>
  */
@@ -42,46 +42,61 @@
     private static final Logger LOG = Logger.getLogger(BasicResultList.class);
 
     private int hitCount = -1;
-    
+
     private final List<T> results = new ArrayList<T>();
-    
-    private final Map<String,List<WeightedSuggestion>> spellingSuggestions 
+
+    private final Map<String,List<WeightedSuggestion>> spellingSuggestions
             = new HashMap<String,List<WeightedSuggestion>>();
-    
+
     private final List<Suggestion> querySuggestions = new 
ArrayList<Suggestion>();
 
-    private final List<WeightedSuggestion> relevantQueries = new 
ArrayList<WeightedSuggestion>(); 
-    
+    private final List<WeightedSuggestion> relevantQueries = new 
ArrayList<WeightedSuggestion>();
+
     /** Plain constructor.
-     * 
+     *
      */
     public BasicResultList(){}
-    
+
     protected BasicResultList(final String title, final String url, final int 
hitCount){
         super(title, url);
         this.hitCount = hitCount;
     }
-    
-    /** Copy constructor. 
+
+    /** Copy constructor.
      * Does not copy results, spellingSuggestions, querySuggestions, or 
relevantQueries.
      *
-     * ** @param copy 
+     * @param copy
      */
     public BasicResultList(final ResultItem copy){
         super(copy);
     }
 
-    /** [EMAIL PROTECTED] **/
+    /** Copy constructor.
+     * Does not copy results.
+     *
+     * @param copy
+     */
+    public BasicResultList(final ResultList<ResultItem> copy){
+        super(copy);
+
+
+        hitCount = copy.getHitCount();
+        for(WeightedSuggestion ws : copy.getSpellingSuggestions()){
+            // careful here. we're calling a possibly overridden method.
+            addSpellingSuggestion(ws);
+        }
+        querySuggestions.addAll(copy.getQuerySuggestions());
+        relevantQueries.addAll(copy.getRelevantQueries());
+    }
+
     public void setHitCount(final int docCount) {
         this.hitCount = docCount;
     }
 
-    /** [EMAIL PROTECTED] **/
     public int getHitCount() {
         return hitCount;
     }
 
-    /** [EMAIL PROTECTED] **/
     public void addResult(final T item) {
         results.add(item);
     }
@@ -89,15 +104,15 @@
     public void addResults(List<? extends T> items){
         results.addAll(items);
     }
-    
+
     public void replaceResult(final T original, final T theNew){
-        
+
         if(original != theNew){
             // if the instances vary then replace
             results.set(results.indexOf(original), theNew);
         }
     }
-    
+
     public void removeResult(final T item){
         results.remove(item);
     }
@@ -110,9 +125,8 @@
         Collections.sort(results, comparator);
     }
 
-    /** [EMAIL PROTECTED] **/
     public void addSpellingSuggestion(final WeightedSuggestion suggestion) {
-        
+
         if (spellingSuggestions.containsKey(suggestion.getOriginal())) {
             final List<WeightedSuggestion> exising = 
spellingSuggestions.get(suggestion.getOriginal());
             exising.add(suggestion);
@@ -129,14 +143,14 @@
 
     /** [EMAIL PROTECTED] **/
     public List<WeightedSuggestion> getSpellingSuggestions() {
-        
+
         final List<WeightedSuggestion> result = new 
ArrayList<WeightedSuggestion>();
         for(List<WeightedSuggestion> v : spellingSuggestions.values()){
             result.addAll(v);
         }
         return result;
     }
-    
+
     /** [EMAIL PROTECTED] **/
     public Map<String,List<WeightedSuggestion>> getSpellingSuggestionsMap() {
         return spellingSuggestions;
@@ -152,11 +166,11 @@
         querySuggestions.add(query);
     }
 
-    /** [EMAIL PROTECTED] **/          
+    /** [EMAIL PROTECTED] **/
     public List<T> getResults() {
         return Collections.unmodifiableList(results);
     }
-    
+
     /** JavaBean compatability for JSPs. **/
     public int getResultsSize(){
         return results.size();
@@ -165,28 +179,28 @@
     /** [EMAIL PROTECTED] **/
     @Override
     public BasicResultList<T> addField(final String field, final String value) 
{
-        
+
         super.addField(field, value);
         return this;
     }
 
     @Override
     public BasicResultList<T> addObjectField(final String field, final 
Serializable value) {
-        
+
         super.addObjectField(field, value);
         return this;
-    }    
+    }
 
     @Override
     public BasicResultList<T> addToMultivaluedField(final String field, final 
String value) {
-        
+
         super.addToMultivaluedField(field, value);
         return this;
     }
-    
+
     /**
-     * 
-     * @param query 
+     *
+     * @param query
      */
     public void addRelevantQuery(final WeightedSuggestion query) {
         relevantQueries.add(query);
@@ -198,7 +212,7 @@
      * @return the relevantQueries.
      */
     public List<WeightedSuggestion> getRelevantQueries() {
-        
+
         Collections.sort(relevantQueries);
         return Collections.unmodifiableList(relevantQueries);
     }

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

Reply via email to