Author: daniele
Date: 2006-12-20 10:57:34 +0100 (Wed, 20 Dec 2006)
New Revision: 4209

Added:
   
trunk/core-api/src/main/java/no/schibstedsok/searchportal/mode/command/CatalogueSearchCommand.java
   
trunk/core-api/src/main/java/no/schibstedsok/searchportal/mode/config/CatalogueSearchConfiguration.java
   
trunk/core-api/src/main/java/no/schibstedsok/searchportal/result/CatalogueSearchResultItem.java
   
trunk/core-api/src/main/java/no/schibstedsok/searchportal/result/ProductResult.java
   
trunk/core-api/src/main/java/no/schibstedsok/searchportal/result/ProductResultItem.java
   
trunk/core-api/src/main/java/no/schibstedsok/searchportal/result/ProductSearchResult.java
   
trunk/core-api/src/main/java/no/schibstedsok/searchportal/result/ProductSearchResultItem.java
Modified:
   
trunk/core-api/src/main/java/no/schibstedsok/searchportal/mode/SearchModeFactory.java
Log:
search command and frills required by katalog.sesam.no


Modified: 
trunk/core-api/src/main/java/no/schibstedsok/searchportal/mode/SearchModeFactory.java
===================================================================
--- 
trunk/core-api/src/main/java/no/schibstedsok/searchportal/mode/SearchModeFactory.java
       2006-12-20 08:30:00 UTC (rev 4208)
+++ 
trunk/core-api/src/main/java/no/schibstedsok/searchportal/mode/SearchModeFactory.java
       2006-12-20 09:57:34 UTC (rev 4209)
@@ -8,6 +8,7 @@
 import 
no.schibstedsok.searchportal.mode.config.AbstractYahooSearchConfiguration;
 import 
no.schibstedsok.searchportal.mode.config.BlendingNewsSearchConfiguration;
 import no.schibstedsok.searchportal.mode.config.BlogSearchConfiguration;
+import no.schibstedsok.searchportal.mode.config.CatalogueSearchConfiguration;
 import no.schibstedsok.searchportal.mode.config.DailyWordConfiguration;
 import no.schibstedsok.searchportal.mode.config.ESPFastSearchConfiguration;
 import no.schibstedsok.searchportal.mode.config.FastSearchConfiguration;
@@ -357,7 +358,8 @@
         WHITEPAGES_COMMAND(WhiteSearchConfiguration.class),
         DAILY_WORD_COMMAND(DailyWordConfiguration.class),
         BLOG_COMMAND(BlogSearchConfiguration.class),
-        PRISJAKT_COMMAND(PrisjaktSearchConfiguration.class);
+        PRISJAKT_COMMAND(PrisjaktSearchConfiguration.class),
+        CATALOGUE_COMMAND(CatalogueSearchConfiguration.class);
 
 
         private final Class<? extends SearchConfiguration> clazz;
@@ -622,6 +624,11 @@
                 if(sc instanceof YellowSearchConfiguration){
                     final YellowSearchConfiguration ysc = 
(YellowSearchConfiguration) sc;
                 }
+
+                if(sc instanceof CatalogueSearchConfiguration){
+                    final CatalogueSearchConfiguration ysc = 
(CatalogueSearchConfiguration) sc;
+                }                
+                
                 if(sc instanceof YellowGeoSearchConfiguration){
                     final YellowGeoSearchConfiguration ysc = 
(YellowGeoSearchConfiguration) sc;
                 }                

Added: 
trunk/core-api/src/main/java/no/schibstedsok/searchportal/mode/command/CatalogueSearchCommand.java
===================================================================
--- 
trunk/core-api/src/main/java/no/schibstedsok/searchportal/mode/command/CatalogueSearchCommand.java
                          (rev 0)
+++ 
trunk/core-api/src/main/java/no/schibstedsok/searchportal/mode/command/CatalogueSearchCommand.java
  2006-12-20 09:57:34 UTC (rev 4209)
@@ -0,0 +1,440 @@
+/*
+ * Copyright (2005-2006) Schibsted Søk AS
+ */
+package no.schibstedsok.searchportal.mode.command;
+
+
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+import javax.sql.DataSource;
+
+import no.schibstedsok.searchportal.query.IntegerClause;
+import no.schibstedsok.searchportal.query.LeafClause;
+import no.schibstedsok.searchportal.query.PhoneNumberClause;
+import no.schibstedsok.searchportal.query.Visitor;
+import no.schibstedsok.searchportal.query.XorClause;
+import no.schibstedsok.searchportal.query.token.TokenEvaluationEngine;
+import no.schibstedsok.searchportal.query.token.TokenMatch;
+import no.schibstedsok.searchportal.query.token.TokenPredicate;
+import no.schibstedsok.searchportal.result.BasicSearchResultItem;
+import no.schibstedsok.searchportal.result.CatalogueSearchResultItem;
+import no.schibstedsok.searchportal.result.FastSearchResult;
+import no.schibstedsok.searchportal.result.ProductResult;
+import no.schibstedsok.searchportal.result.ProductResultItem;
+import no.schibstedsok.searchportal.result.ProductSearchResult;
+import no.schibstedsok.searchportal.result.ProductSearchResultItem;
+import no.schibstedsok.searchportal.result.SearchResult;
+import no.schibstedsok.searchportal.result.YellowSearchResult;
+
+import org.apache.log4j.Logger;
+
+/**
+ * TODO. Rewrite from scratch. This class is insane.
+ * 
+ * COMMENT: Jag har tagit utgångspunkt i YellowCommand. Det är massa i denna 
klass
+ * som jag inte har koll på i detalj!
+ * 
+ * top3 är gamla (dagens) import av produkter från IK som ska bytas ut. 
+ *
+ * Begreppet local är jag osäker på?
+ * 
+ * 
+ */
+public class CatalogueSearchCommand extends AbstractSimpleFastSearchCommand {
+
+    private static final Logger LOG = 
Logger.getLogger(CatalogueSearchCommand.class);
+
+    private boolean ignoreGeoNav = false;
+
+    private boolean isLocal;
+
+    private boolean isTop3 = false;
+
+    private boolean ypkeywordsgeo = false;
+
+    private StringBuilder filterBuilder = null;
+
+    boolean exactCompany;
+    boolean companyRank = false;
+
+    private boolean correct = false;
+
+    /** Creates a new catalogue search command.
+     * TODO. Rewrite from scratch. This is insane.
+     **/
+    public CatalogueSearchCommand(final Context cxt, final Map parameters) {
+        super(cxt, parameters);
+    }
+
+    /** TODO comment me. **/
+    protected Map getNavigators() {
+
+        if (ignoreGeoNav && super.getNavigators() != null) {
+            final Map m = new HashMap();
+            m.putAll(super.getNavigators());
+            m.remove("geographic");
+            return m;
+        }
+
+        return super.getNavigators();
+    }
+
+    /** TODO comment me. **/
+    public SearchResult execute() {
+        LOG.error("Execute");
+
+        boolean viewAll = false;
+
+        if (getParameters().containsKey("ypviewall")) {
+            viewAll = true;
+        }
+
+
+        if (isLocalSearch() && !viewAll) {
+            correct = false;
+            ignoreGeoNav = true;
+            isLocal = false;
+            ypkeywordsgeo = true;
+            final FastSearchResult nationalHits = (FastSearchResult) 
super.execute();
+            ypkeywordsgeo = false;
+
+            correct = false;
+            ignoreGeoNav = false;
+            isTop3 = true;
+            final FastSearchResult top3 = (FastSearchResult) super.execute();
+            isTop3 = false;
+
+            // Perform local search.
+            correct = true;
+            ignoreGeoNav = false;
+            isLocal = true;
+            final FastSearchResult localResult = (FastSearchResult) 
super.execute();
+
+            final YellowSearchResult result = new YellowSearchResult(this, 
localResult, nationalHits, top3, isLocalSearch() && !viewAll);
+
+            final String yprank = companyRank ? "company" : "default";
+            result.addField("yprank", yprank);
+
+            return result;
+        } else if (!viewAll) {
+            isLocal = false;
+            isTop3 = true;
+            correct = false;
+            final FastSearchResult top3 = (FastSearchResult) super.execute();
+            isTop3 = false;
+            ypkeywordsgeo = true;
+            correct = true;
+            final FastSearchResult nationalHits = (FastSearchResult) 
super.execute();
+            ypkeywordsgeo = false;
+
+            final YellowSearchResult result = new YellowSearchResult(this, 
null, nationalHits, top3, false);
+            
+            fetchProducts(result);
+            final String yprank = companyRank ? "company" : "default";
+            result.addField("yprank", yprank);
+
+            return result;
+        } else {
+            correct = true;
+            ypkeywordsgeo = false;
+            isLocal = true;
+            ignoreGeoNav = true;
+            final FastSearchResult localResult = (FastSearchResult) 
super.execute();
+            ignoreGeoNav = false;
+            isLocal = false;
+
+            isTop3 = true;
+            correct = false;
+            final FastSearchResult top3 = (FastSearchResult) super.execute();
+            isTop3 = false;
+
+            isLocal = false;
+            ypkeywordsgeo = true;
+            correct = false;
+            final FastSearchResult nationalHits = (FastSearchResult) 
super.execute();
+            ypkeywordsgeo = false;
+
+            final String yprank = companyRank ? "company" : "default";
+
+            final YellowSearchResult result = new YellowSearchResult(this, 
localResult, nationalHits, top3, false);
+
+            result.addField("yprank", yprank);
+            return result;
+        }
+    }
+
+    private boolean isLocalSearch() {
+        return getRunningQuery().getGeographicMatches().size() > 0;
+    }
+
+
+    private TokenMatch getLastGeoMatch() {
+        final List<TokenMatch> matches = 
getRunningQuery().getGeographicMatches();
+
+        if (matches.size() > 0) {
+            return matches.get(matches.size() - 1);
+        } else {
+            return null;
+        }
+    }
+
+
+    /** TODO comment me. **/
+    public String getTransformedQuery() {
+
+        final String t = super.getTransformedQuery();
+
+        final TokenEvaluationEngine engine = 
context.getTokenEvaluationEngine();
+
+        exactCompany = engine.evaluateQuery(TokenPredicate.EXACT_COMPANYRANK, 
context.getQuery());
+
+        companyRank = exactCompany && !isTop3 && 
!getParameter("yprank").equals("standard") || 
getParameter("yprank").equals("company");
+
+        if (companyRank) {
+            return t.replaceAll("yellowphon", "yellownamephon");
+        }
+
+        if (isTop3) {
+            return t.replaceAll("yellowphon:", "").replaceAll("-", " ");
+        }
+
+        if (isLocal) {
+            return t.replaceAll("-", " ");
+        } else {
+            return t.replaceAll("yellowphon", "yellowgeophon").replaceAll("-", 
" ");
+        }
+    }
+
+
+    /** TODO comment me. **/
+    protected boolean isCorrectionEnabled() {
+        return correct;
+    }
+
+    /** TODO comment me. **/
+    protected int getResultsToReturn() {
+        if (isTop3) {
+            return 3;
+        } else {
+            return super.getResultsToReturn();
+        }
+    }
+
+    /** TODO comment me. **/
+    protected String getAdditionalFilter() {
+
+        synchronized (this) {
+            if (filterBuilder == null) {
+                filterBuilder = new StringBuilder(super.getAdditionalFilter());
+            }
+
+            return ypkeywordsgeo && getLastGeoMatch() != null
+                    ? filterBuilder.toString() + " +ypkeywordsgeo:" + 
getLastGeoMatch().getMatch()
+                    : filterBuilder.toString();
+        }
+    }
+
+    /** TODO comment me. **/
+    protected String getSortBy() {
+
+        final TokenEvaluationEngine engine = 
context.getTokenEvaluationEngine();
+
+        if (engine.evaluateQuery(TokenPredicate.EXACT_COMPANYRANK, 
context.getQuery())) {
+            return "yellowname";
+        }
+
+        return (isLocal ? "yellowpages2new +ypnavn" : "yellowpages2geo 
+ypnavn");
+    }
+
+    /** TODO comment me. **/
+    public String getQueryInfo() {
+        return getTransformedQuery() + " " + getSortBy() + " " + 
getAdditionalFilter();
+    }
+
+
+    // Query Builder
+
+    private static final String PREFIX_INTEGER="yellowpages:";
+    private static final String PREFIX_PHONETIC="yellowphon:";
+
+    /**
+     * Adds non phonetic prefix to integer terms.
+     *
+     * @param clause The clause to prefix.
+     */
+    protected void visitImpl(final IntegerClause clause) {
+        if (!getTransformedTerm(clause).equals("")) {
+            appendToQueryRepresentation(PREFIX_INTEGER);
+        }
+
+        super.visitImpl(clause);
+    }
+
+    /**
+     * Adds non phonetic prefix to phone number terms.
+     *
+     * @param clause The clause to prefix.
+     */
+    protected void visitImpl(final PhoneNumberClause clause) {
+        if (!getTransformedTerm(clause).equals("")) {
+            appendToQueryRepresentation(PREFIX_INTEGER);
+        }
+        super.visitImpl(clause);
+    }
+
+    /**
+     * Adds phonetic prefix to a leaf clause.
+     * Remove dots from words. (people, street, suburb, or city names do not 
have dots.)
+     *
+     * @param clause The clause to prefix.
+     */
+    protected void visitImpl(final LeafClause clause) {
+        
+        if (clause.getField() == null) {
+            if (!getTransformedTerm(clause).equals("")) {
+                appendToQueryRepresentation(PREFIX_PHONETIC 
+                        + getTransformedTerm(clause).replaceAll("\\.", " "));
+            }
+            
+        }else if(null == getFieldFilter(clause)){
+            
+            if (!getTransformedTerm(clause).equals("")) {
+                // we also accept terms with fields that haven't been 
permitted for the searchConfiguration
+                appendToQueryRepresentation(PREFIX_PHONETIC 
+                        + clause.getField() + "\\:" + 
getTransformedTerm(clause).replaceAll("\\.", " "));
+                
+            }
+
+        }
+    }
+
+    /**
+     * An implementation that ignores phrase searches.
+     *
+     * Visits only the left clause, unless that clause is a clause, in which
+     * case only the right clause is visited. Phrase searches are not possible
+     * against the yellow index.
+     */
+    protected void visitXorClause(final Visitor visitor, final XorClause 
clause) {
+        
+        // If we have a match on an international phone number, but it is not 
recognized as
+        // a local phone number, force it to use the original number string.
+        if (clause.getHint() == XorClause.Hint.PHONE_NUMBER_ON_LEFT
+                && 
!clause.getFirstClause().getKnownPredicates().contains(TokenPredicate.PHONENUMBER))
 {
+            
+            clause.getSecondClause().accept(visitor);
+            
+        } else if(XorClause.Hint.PHRASE_ON_LEFT == clause.getHint()){
+            clause.getSecondClause().accept(visitor);
+            
+        } else {
+            super.visitXorClause(visitor, clause);
+        }
+    }
+    
+    /**
+     * This function gets all products for the resultList.
+     * 
+     * @param result
+     */
+    private void fetchProducts(YellowSearchResult result) {
+        LOG.info("fetchProducts");
+                       
+               if(result == null)
+               return;
+       
+               
+               List<CatalogueSearchResultItem> nyResultListe = new 
ArrayList<CatalogueSearchResultItem>();
+               
+       //TODO: get all keys to lookup and execute one call instead of 
iterating like this...
+       Iterator iter = result.getResults().listIterator();
+       
+               //placeholder for products
+               ProductResult products = new ProductSearchResult();     
+       
+       while (iter.hasNext()) {
+               BasicSearchResultItem basicResultItem = (BasicSearchResultItem) 
iter.next();
+
+               CatalogueSearchResultItem resultItem = new 
CatalogueSearchResultItem();
+               for(Object o : basicResultItem.getFieldNames()){
+                       String s = (String) o;
+                       String v = basicResultItem.getField(s);
+                       resultItem.addField(s,v);
+               }
+               
+               nyResultListe.add(resultItem);
+               
+               //jdbc version
+               Connection con = null;
+               try {
+                       InitialContext ctxt = new InitialContext();
+                       DataSource ds = (DataSource) ctxt.lookup("java:ag");
+                       
+                       con = ds.getConnection();
+                               
+                               PreparedStatement stmt = con
+                                               .prepareStatement("select 
S.companyId, C.organizationNo, C.businessName, S.textShort, S.text1" +
+                                                                               
  " from AG_SALE S, AG_COMPANY C " +
+                                                                               
  " where C.companyId = S.companyId and C.organizationNo = ? and toDate > now() 
and S.text1 is not null");
+                               
stmt.setString(1,resultItem.getField("yporgnummer"));
+                               LOG.info("Hent produkter for firma med 
organisasjonsnr. "+resultItem.getField("yporgnummer"));
+                               
+                               ResultSet res = stmt.executeQuery();
+                               
+                               if(res.next()){
+                                       
+                                       //listingProducts goes on the result 
listing page
+                                       if(res.getString("textShort") != null){
+                                               ProductResultItem 
listingProduct = new ProductSearchResultItem();
+                                               
listingProduct.addField("shortText", res.getString("textShort"));
+                                               
products.addListingResult(listingProduct);
+                                       }
+
+                                       //infoPageProducts goes on the infopage
+                                       if(res.getString("text1") != null){
+                                               ProductResultItem 
infoPageProduct = new ProductSearchResultItem();
+                                               
infoPageProduct.addField("text1", res.getString("text1"));
+                                               
products.addInfoPageResult(infoPageProduct);
+                                       }
+
+                                       //add the products to the searchResult
+                                       if(products.hasInfoPageProducts() || 
products.hasListingProducts())
+                                               
resultItem.addProducts(products);
+
+                               }else{
+                               LOG.info("ingen produkter funnet for firma.");
+                               }
+                               
+                               
+                       } catch (SQLException e) {
+                               e.printStackTrace();
+                       } catch (NamingException e) {
+                               e.printStackTrace();
+                       } finally{
+                               try {
+                                       con.close();
+                               } catch (SQLException e) {
+                                       e.printStackTrace();
+                               }
+                       }
+               
+                       
+               }
+       
+       // bytt ut den gamle mot den nye listen.
+       result.getResults().clear();
+       result.getResults().addAll(nyResultListe);
+    }
+     
+
+}


Property changes on: 
trunk/core-api/src/main/java/no/schibstedsok/searchportal/mode/command/CatalogueSearchCommand.java
___________________________________________________________________
Name: svn:executable
   + *

Added: 
trunk/core-api/src/main/java/no/schibstedsok/searchportal/mode/config/CatalogueSearchConfiguration.java
===================================================================
--- 
trunk/core-api/src/main/java/no/schibstedsok/searchportal/mode/config/CatalogueSearchConfiguration.java
                             (rev 0)
+++ 
trunk/core-api/src/main/java/no/schibstedsok/searchportal/mode/config/CatalogueSearchConfiguration.java
     2006-12-20 09:57:34 UTC (rev 4209)
@@ -0,0 +1,23 @@
+/*
+ * Copyright (2005-2006) Schibsted Søk AS
+ */
+package no.schibstedsok.searchportal.mode.config;
+
+/**
+ *
+ * An implementation of Search Configuration for yellow searches.
+ *
+ * @author <a href="[EMAIL PROTECTED]">Lars Johansson</a>
+ * @version $Revision: 1 $
+ */
+public class CatalogueSearchConfiguration extends FastSearchConfiguration {
+
+    public CatalogueSearchConfiguration(){
+        super(null);
+    }
+
+    public CatalogueSearchConfiguration(final SearchConfiguration asc){
+        super(asc);
+    }
+
+}


Property changes on: 
trunk/core-api/src/main/java/no/schibstedsok/searchportal/mode/config/CatalogueSearchConfiguration.java
___________________________________________________________________
Name: svn:executable
   + *

Added: 
trunk/core-api/src/main/java/no/schibstedsok/searchportal/result/CatalogueSearchResultItem.java
===================================================================
--- 
trunk/core-api/src/main/java/no/schibstedsok/searchportal/result/CatalogueSearchResultItem.java
                             (rev 0)
+++ 
trunk/core-api/src/main/java/no/schibstedsok/searchportal/result/CatalogueSearchResultItem.java
     2006-12-20 09:57:34 UTC (rev 4209)
@@ -0,0 +1,26 @@
+// Copyright (2006) Schibsted Søk AS
+package no.schibstedsok.searchportal.result;
+
+/**
+ * A simple implementation of a search result item that may contain products.
+ *
+ * @author <a href="mailto:[EMAIL PROTECTED]">Lars Johansson</a>
+ * @version <tt>$Revision: 1 $</tt>
+ */
+public class CatalogueSearchResultItem extends BasicSearchResultItem {
+
+    private ProductResult products = null;
+
+    public void addProducts(ProductResult products) {
+       this.products = products;
+    }
+    
+    public boolean hasProducts(){
+       return this.products != null ? true : false;
+    }
+    
+    public ProductResult getProducts(){
+       return this.products;
+    }
+    
+}


Property changes on: 
trunk/core-api/src/main/java/no/schibstedsok/searchportal/result/CatalogueSearchResultItem.java
___________________________________________________________________
Name: svn:executable
   + *

Added: 
trunk/core-api/src/main/java/no/schibstedsok/searchportal/result/ProductResult.java
===================================================================
--- 
trunk/core-api/src/main/java/no/schibstedsok/searchportal/result/ProductResult.java
                         (rev 0)
+++ 
trunk/core-api/src/main/java/no/schibstedsok/searchportal/result/ProductResult.java
 2006-12-20 09:57:34 UTC (rev 4209)
@@ -0,0 +1,22 @@
+package no.schibstedsok.searchportal.result;
+
+import java.util.List;
+
+
+/*
+ * @version <tt>$Revision: 1 $</tt>
+ * @author <a href="mailto:[EMAIL PROTECTED]">Lars Johansson</a>
+ *
+ */
+public interface ProductResult {
+
+    List<ProductResultItem> getInfoPageProducts();
+    List<ProductResultItem> getListingProducts();
+
+    void addInfoPageResult(ProductResultItem item);
+    void addListingResult(ProductResultItem item);
+
+    boolean hasInfoPageProducts();
+    boolean hasListingProducts();
+
+}


Property changes on: 
trunk/core-api/src/main/java/no/schibstedsok/searchportal/result/ProductResult.java
___________________________________________________________________
Name: svn:executable
   + *

Added: 
trunk/core-api/src/main/java/no/schibstedsok/searchportal/result/ProductResultItem.java
===================================================================
--- 
trunk/core-api/src/main/java/no/schibstedsok/searchportal/result/ProductResultItem.java
                             (rev 0)
+++ 
trunk/core-api/src/main/java/no/schibstedsok/searchportal/result/ProductResultItem.java
     2006-12-20 09:57:34 UTC (rev 4209)
@@ -0,0 +1,7 @@
+package no.schibstedsok.searchportal.result;
+
+public interface ProductResultItem {
+
+       void addField(String field, String value);
+    String getField(String field);
+}


Property changes on: 
trunk/core-api/src/main/java/no/schibstedsok/searchportal/result/ProductResultItem.java
___________________________________________________________________
Name: svn:executable
   + *

Added: 
trunk/core-api/src/main/java/no/schibstedsok/searchportal/result/ProductSearchResult.java
===================================================================
--- 
trunk/core-api/src/main/java/no/schibstedsok/searchportal/result/ProductSearchResult.java
                           (rev 0)
+++ 
trunk/core-api/src/main/java/no/schibstedsok/searchportal/result/ProductSearchResult.java
   2006-12-20 09:57:34 UTC (rev 4209)
@@ -0,0 +1,46 @@
+// Copyright (2006) Schibsted Søk AS
+package no.schibstedsok.searchportal.result;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.log4j.Logger;
+
+/**
+ * @author <a href="mailto:[EMAIL PROTECTED]">Lars Johansson</a>
+ * @version <tt>$Revision: 1 $</tt>
+ */
+public class ProductSearchResult implements ProductResult {
+
+    private static final Logger LOG = 
Logger.getLogger(ProductSearchResult.class);
+
+    private final List<ProductResultItem> listingResults = new 
ArrayList<ProductResultItem>();
+    private final List<ProductResultItem> infoPageResults = new 
ArrayList<ProductResultItem>();
+    
+       public void addInfoPageResult(ProductResultItem item) {
+               infoPageResults.add(item);
+       }
+
+       public void addListingResult(ProductResultItem item) {
+               listingResults.add(item);
+       }
+
+       public List<ProductResultItem> getInfoPageProducts() {
+               return infoPageResults;
+       }
+
+       public List<ProductResultItem> getListingProducts() {
+               return listingResults;
+       }
+
+       public boolean hasInfoPageProducts() {
+               return infoPageResults.size() > 0 ? true: false;
+       }
+
+       public boolean hasListingProducts() {
+               return listingResults.size() > 0 ? true: false;
+       }
+
+}
+
+


Property changes on: 
trunk/core-api/src/main/java/no/schibstedsok/searchportal/result/ProductSearchResult.java
___________________________________________________________________
Name: svn:executable
   + *

Added: 
trunk/core-api/src/main/java/no/schibstedsok/searchportal/result/ProductSearchResultItem.java
===================================================================
--- 
trunk/core-api/src/main/java/no/schibstedsok/searchportal/result/ProductSearchResultItem.java
                               (rev 0)
+++ 
trunk/core-api/src/main/java/no/schibstedsok/searchportal/result/ProductSearchResultItem.java
       2006-12-20 09:57:34 UTC (rev 4209)
@@ -0,0 +1,82 @@
+// Copyright (2006) Schibsted Søk AS
+package no.schibstedsok.searchportal.result;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+
+/**
+ * A simple implementation of a product result item.
+ *
+ * @author <a href="mailto:[EMAIL PROTECTED]">Lars Johansson</a>
+ * @version <tt>$Revision: 1 $</tt>
+ */
+public class ProductSearchResultItem implements ProductResultItem {
+
+    private HashMap fields = new HashMap();
+
+    public void addField(final String field, final String value) {
+        fields.put(field, value);
+    }
+
+    public String getField(final String field) {
+        final String fieldValue = (String) fields.get(field);
+        return fieldValue;
+    }
+
+    public Object getFieldAsObject(final String field) {
+        return fields.get(field);
+    }
+
+    public Integer getInteger(final String field) {
+        final String fieldValue = (String) fields.get(field);
+
+        if (fieldValue != null) {
+            return Integer.valueOf(Integer.parseInt(fieldValue));
+        } else {
+            return null;
+        }
+    }
+
+    public String getField(final String field, final int maxLength) {
+        final String fieldValue = (String) fields.get(field);
+
+        if (fieldValue != null) {
+            if (fieldValue.equals("  ")) {
+                return null;
+            } else {
+                return StringChopper.chop(fieldValue, maxLength);
+            }
+        }
+        return fieldValue;
+    }
+
+    public Collection getFieldNames() {
+        return fields.keySet();
+    }
+
+    public Collection getMultivaluedField(final String field) {
+        return (Collection) fields.get(field);
+    }
+
+    public void addToMultivaluedField(final String field, final String value) {
+        if (! fields.containsKey(field)) {
+            fields.put(field, new ArrayList());
+        }
+
+        final Collection previousValues = (Collection) fields.get(field);
+        previousValues.add(value);
+    }
+
+    //TODO:
+    public boolean equals(final Object obj) {
+        return super.equals(obj);
+    }
+
+    //TODO:
+    public int hashCode() {
+
+        return super.hashCode();
+    }
+
+}


Property changes on: 
trunk/core-api/src/main/java/no/schibstedsok/searchportal/result/ProductSearchResultItem.java
___________________________________________________________________
Name: svn:executable
   + *

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

Reply via email to