Author: gttersen
Date: 2007-05-02 14:27:47 +0200 (Wed, 02 May 2007)
New Revision: 4936

Modified:
   
trunk/core-api/src/main/java/no/schibstedsok/searchportal/mode/command/ClusteringESPFastCommand.java
   
trunk/core-api/src/main/java/no/schibstedsok/searchportal/mode/command/NewsAggregatorSearchCommand.java
   
trunk/core-api/src/main/java/no/schibstedsok/searchportal/mode/command/NewsEspSearchCommand.java
   
trunk/core-api/src/main/java/no/schibstedsok/searchportal/mode/command/NewsMyNewsSearchCommand.java
Log:
newsAggregator changes

Modified: 
trunk/core-api/src/main/java/no/schibstedsok/searchportal/mode/command/ClusteringESPFastCommand.java
===================================================================
--- 
trunk/core-api/src/main/java/no/schibstedsok/searchportal/mode/command/ClusteringESPFastCommand.java
        2007-05-02 10:49:56 UTC (rev 4935)
+++ 
trunk/core-api/src/main/java/no/schibstedsok/searchportal/mode/command/ClusteringESPFastCommand.java
        2007-05-02 12:27:47 UTC (rev 4936)
@@ -144,7 +144,7 @@
             }
         }
         if (offset + collectedHits < result.getDocCount()) {
-            searchResult.addField(ClusteringESPFastCommand.PARAM_NEXT_OFFSET, 
Integer.toString(offset + collectedHits));
+            addNextOffsetField(offset + collectedHits, searchResult);
         }
         searchResult.setHitCount(result.getDocCount());
         return searchResult;

Modified: 
trunk/core-api/src/main/java/no/schibstedsok/searchportal/mode/command/NewsAggregatorSearchCommand.java
===================================================================
--- 
trunk/core-api/src/main/java/no/schibstedsok/searchportal/mode/command/NewsAggregatorSearchCommand.java
     2007-05-02 10:49:56 UTC (rev 4935)
+++ 
trunk/core-api/src/main/java/no/schibstedsok/searchportal/mode/command/NewsAggregatorSearchCommand.java
     2007-05-02 12:27:47 UTC (rev 4936)
@@ -90,7 +90,7 @@
         try {
             final NewsAggregatorXmlParser newsAggregatorXmlParser = new 
NewsAggregatorXmlParser();
             final InputStream inputStream = getInputStream(config, xmlFile);
-            SearchResult searchResult = 
newsAggregatorXmlParser.parseCluster(config, inputStream, 
clusterId.getString(), this);
+            SearchResult searchResult = 
newsAggregatorXmlParser.parseCluster(config, inputStream, 
clusterId.getString(), getOffset(), this);
             if (searchResult != null && searchResult.getHitCount() > 0) {
                 return searchResult;
             }
@@ -174,7 +174,7 @@
             return saxBuilder.build(inputStream);
         }
 
-        public FastSearchResult parseCluster(NewsAggregatorCommandConfig 
config, InputStream inputStream, String clusterId, NewsAggregatorSearchCommand 
searchCommand) throws JDOMException, IOException {
+        public FastSearchResult parseCluster(NewsAggregatorCommandConfig 
config, InputStream inputStream, String clusterId, int offset, 
NewsAggregatorSearchCommand searchCommand) throws JDOMException, IOException {
             try {
                 LOG.debug("Parsing cluster: " + clusterId);
                 final FastSearchResult searchResult = new 
FastSearchResult(searchCommand);
@@ -185,7 +185,7 @@
                     LOG.debug("Looking at element: " + cluster.getName() + ", 
clusterId=" + cluster.getAttributeValue(ATTRIBUTE_CLUSTERID));
                     if 
(cluster.getAttributeValue(ATTRIBUTE_CLUSTERID).equals(clusterId)) {
                         LOG.debug("Found correct cluster. Handling.");
-                        handleFlatCluster(config, cluster, searchCommand, 
searchResult);
+                        handleFlatCluster(config, cluster, searchCommand, 
searchResult, offset);
                         handleRelated(config, 
cluster.getChild(ELEMENT_RELATED), searchResult);
                         break;
                     }
@@ -235,7 +235,7 @@
                 final String clusters = 
countsElement.getAttributeValue(ATTRIBUTE_CLUSTER_COUNT);
                 if (clusters != null && clusters.length() > 0) {
                     if (offset + config.getResultsToReturn() < 
Integer.parseInt(clusters)) {
-                        
searchResult.addField(ClusteringESPFastCommand.PARAM_NEXT_OFFSET, 
Integer.toString(offset + config.getResultsToReturn()));
+                        addNextOffsetField(offset + 
config.getResultsToReturn(), searchResult);
                     }
                 }
             }
@@ -280,19 +280,27 @@
             }
         }
 
-        private void handleFlatCluster(NewsAggregatorCommandConfig config, 
Element cluster, SearchCommand searchCommand, SearchResult searchResult) {
+        private void handleFlatCluster(NewsAggregatorCommandConfig config, 
Element cluster, SearchCommand searchCommand, SearchResult searchResult, int 
offset) {
             if (cluster != null) {
                 final Element entryCollectionElement = 
cluster.getChild(ELEMENT_ENTRY_COLLECTION);
                 if (entryCollectionElement != null) {
+                    int offsetCount = 0;
                     final List<Element> entryList = 
entryCollectionElement.getChildren();
                     searchResult.setHitCount(entryList.size());
 
                     final HashMap<String, SearchResultItem> collapseMap = new 
HashMap<String, SearchResultItem>();
-                    for (Element entry : entryList) {
+                    offset = config.isIgnoreOffset() ? 0 : offset;
+                    for (int i = offset; i < entryList.size(); i++) {
+                        Element entry = entryList.get(i);
                         final SearchResultItem searchResultItem = new 
BasicSearchResultItem();
                         handleEntry(entry, searchResultItem);
-                        addResult(config, searchResultItem, searchResult, 
searchCommand, collapseMap);
+                        if (addResult(config, searchResultItem, searchResult, 
searchCommand, collapseMap)) {
+                            offsetCount++;
+                        }
                     }
+                    if (offsetCount < entryList.size()) {
+                        addNextOffsetField(offsetCount, searchResult);
+                    }
                 }
             }
         }
@@ -343,11 +351,11 @@
         }
 
 
-        private void addResult(NewsAggregatorCommandConfig config,
-                               SearchResultItem nestedResultItem,
-                               SearchResult nestedSearchResult,
-                               SearchCommand searchCommand,
-                               HashMap<String, SearchResultItem> collapseMap) {
+        private boolean addResult(NewsAggregatorCommandConfig config,
+                                  SearchResultItem nestedResultItem,
+                                  SearchResult nestedSearchResult,
+                                  SearchCommand searchCommand,
+                                  HashMap<String, SearchResultItem> 
collapseMap) {
             // Check if entry is duplicate and should be a subresult
             SearchResultItem collapseParent = null;
             String collapseId = nestedResultItem.getField(ELEMENT_COLLAPSEID);
@@ -355,11 +363,16 @@
                 collapseParent = collapseMap.get(collapseId);
             }
             if (collapseParent == null) {
-                // No duplicate in results or should not be collapsed
-                nestedSearchResult.addResult(nestedResultItem);
-                if (collapseMap != null) {
-                    collapseMap.put(collapseId, nestedResultItem);
+                // Skipping add if max returned results has been reached.
+                if (nestedSearchResult.getResults().size() < 
config.getResultsToReturn()) {
+                    // No duplicate in results or should not be collapsed
+                    nestedSearchResult.addResult(nestedResultItem);
+                    if (collapseMap != null) {
+                        collapseMap.put(collapseId, nestedResultItem);
+                    }
+                    return true;
                 }
+                return false;
             } else {
                 // duplicate item, adding as a subresult to first item.
                 SearchResult collapsedResults = 
collapseParent.getNestedSearchResult(config.getNestedResultsField());
@@ -368,6 +381,7 @@
                     
collapseParent.addNestedSearchResult(config.getNestedResultsField(), 
collapsedResults);
                 }
                 collapsedResults.addResult(nestedResultItem);
+                return true;
             }
         }
     }

Modified: 
trunk/core-api/src/main/java/no/schibstedsok/searchportal/mode/command/NewsEspSearchCommand.java
===================================================================
--- 
trunk/core-api/src/main/java/no/schibstedsok/searchportal/mode/command/NewsEspSearchCommand.java
    2007-05-02 10:49:56 UTC (rev 4935)
+++ 
trunk/core-api/src/main/java/no/schibstedsok/searchportal/mode/command/NewsEspSearchCommand.java
    2007-05-02 12:27:47 UTC (rev 4936)
@@ -36,6 +36,9 @@
         super(cxt);
     }
 
+    protected static void addNextOffsetField(int nextOffset, SearchResult 
searchResult) {
+        searchResult.addField(NewsEspSearchCommand.PARAM_NEXT_OFFSET, 
Integer.toString(nextOffset));
+    }
 
     @Override
     protected void modifyQuery(IQuery query) {
@@ -88,49 +91,63 @@
         }
     }
 
+    @Override
+    protected void visitImpl(final Object clause) {
+        LOG.debug("Visiting me with: " + clause + ", isroot=" + 
(getQuery().getRootClause() == clause));
+        super.visitImpl(clause);
+    }
+
     protected void visitImpl(final Clause clause) {
+        LOG.debug("Visiting me with: " + clause + ", isroot=" + 
(getQuery().getRootClause() == clause));
         super.visitImpl(clause);
         addMedium(clause);
     }
 
     @Override
     protected void visitImpl(final LeafClause clause) {
+        LOG.debug("Visiting me with: " + clause + ", isroot=" + 
(getQuery().getRootClause() == clause));
         super.visitImpl(clause);
         addMedium(clause);
     }
 
     @Override
     protected void visitImpl(final OperationClause clause) {
+        LOG.debug("Visiting me with: " + clause + ", isroot=" + 
(getQuery().getRootClause() == clause));
         super.visitImpl(clause);
         addMedium(clause);
     }
 
     @Override
     protected void visitImpl(final AndClause clause) {
+        LOG.debug("Visiting me with: " + clause + ", isroot=" + 
(getQuery().getRootClause() == clause));
         super.visitImpl(clause);
         addMedium(clause);
     }
 
     @Override
     protected void visitImpl(final OrClause clause) {
+        LOG.debug("Visiting me with: " + clause + ", isroot=" + 
(getQuery().getRootClause() == clause));
         super.visitImpl(clause);
         addMedium(clause);
     }
 
     @Override
     protected void visitImpl(final DefaultOperatorClause clause) {
+        LOG.debug("Visiting me with: " + clause + ", isroot=" + 
(getQuery().getRootClause() == clause));
         super.visitImpl(clause);
         addMedium(clause);
     }
 
     @Override
     protected void visitImpl(final NotClause clause) {
+        LOG.debug("Visiting me with: " + clause + ", isroot=" + 
(getQuery().getRootClause() == clause));
         super.visitImpl(clause);
         addMedium(clause);
     }
 
     @Override
     protected void visitImpl(final AndNotClause clause) {
+        LOG.debug("Visiting me with: " + clause + ", isroot=" + 
(getQuery().getRootClause() == clause));
         super.visitImpl(clause);
         addMedium(clause);
     }
@@ -178,7 +195,7 @@
             }
         }
         if (offset + collectedHits < result.getDocCount()) {
-            searchResult.addField(NewsEspSearchCommand.PARAM_NEXT_OFFSET, 
Integer.toString(offset + collectedHits));
+            addNextOffsetField(offset + collectedHits, searchResult);
         }
         return searchResult;
     }

Modified: 
trunk/core-api/src/main/java/no/schibstedsok/searchportal/mode/command/NewsMyNewsSearchCommand.java
===================================================================
--- 
trunk/core-api/src/main/java/no/schibstedsok/searchportal/mode/command/NewsMyNewsSearchCommand.java
 2007-05-02 10:49:56 UTC (rev 4935)
+++ 
trunk/core-api/src/main/java/no/schibstedsok/searchportal/mode/command/NewsMyNewsSearchCommand.java
 2007-05-02 12:27:47 UTC (rev 4936)
@@ -101,7 +101,7 @@
         int offset = getOffset();
         if (offset + returnedResults < searchResult.getHitCount()) {
             LOG.debug("Setting next offset to: " + (offset + returnedResults));
-            searchResult.addField(NewsEspSearchCommand.PARAM_NEXT_OFFSET, 
Integer.toString(offset + returnedResults));
+            setNextOffset(searchResult, offset + returnedResults);
         }
     }
 

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

Reply via email to