Author: daniele
Date: 2007-02-08 12:26:29 +0100 (Thu, 08 Feb 2007)
New Revision: 4420
Modified:
trunk/core-api/src/main/java/no/schibstedsok/searchportal/mode/command/CatalogueAdsSearchCommand.java
trunk/core-api/src/main/java/no/schibstedsok/searchportal/mode/command/CatalogueSearchCommand.java
trunk/core-api/src/main/java/no/schibstedsok/searchportal/result/ProductResultItem.java
trunk/core-api/src/main/java/no/schibstedsok/searchportal/result/handler/CatalogueResultHandler.java
trunk/war/pom.xml
Log:
bugfix for catalogue queries
Modified:
trunk/core-api/src/main/java/no/schibstedsok/searchportal/mode/command/CatalogueAdsSearchCommand.java
===================================================================
---
trunk/core-api/src/main/java/no/schibstedsok/searchportal/mode/command/CatalogueAdsSearchCommand.java
2007-02-08 10:53:36 UTC (rev 4419)
+++
trunk/core-api/src/main/java/no/schibstedsok/searchportal/mode/command/CatalogueAdsSearchCommand.java
2007-02-08 11:26:29 UTC (rev 4420)
@@ -16,6 +16,7 @@
import no.schibstedsok.searchportal.query.LeafClause;
import no.schibstedsok.searchportal.query.NotClause;
import no.schibstedsok.searchportal.query.Query;
+import no.schibstedsok.searchportal.result.SearchResult;
import org.apache.log4j.Logger;
@@ -51,8 +52,17 @@
queryTwo = "ingensteds";
}
+ LOG.info("Search configuration name
"+getSearchConfiguration().getName());
}
+ @Override
+ public SearchResult execute() {
+ SearchResult r = null;
+
+ // TODO Auto-generated method stub
+ r = super.execute();
+ return r;
+ }
/**
* Legg til iypcfspkeywords forran alle ord.
Modified:
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
2007-02-08 10:53:36 UTC (rev 4419)
+++
trunk/core-api/src/main/java/no/schibstedsok/searchportal/mode/command/CatalogueSearchCommand.java
2007-02-08 11:26:29 UTC (rev 4420)
@@ -17,6 +17,7 @@
import no.schibstedsok.searchportal.query.DefaultOperatorClause;
import no.schibstedsok.searchportal.query.LeafClause;
import no.schibstedsok.searchportal.query.NotClause;
+import no.schibstedsok.searchportal.query.OperationClause;
import no.schibstedsok.searchportal.query.OrClause;
import no.schibstedsok.searchportal.query.Query;
import no.schibstedsok.searchportal.result.BasicSearchResultItem;
@@ -36,14 +37,14 @@
private String queryTwo = null;
private String queryName = "";
private boolean searchForName = false;
-
+ private List<String> terms = new ArrayList<String>();
+
+
/** Creates a new catalogue search command.
* TODO. Rewrite from scratch. This is insane.
**/
public CatalogueSearchCommand(final Context cxt, final Map parameters) {
super(cxt, parameters);
- LOG.info("CatalogueSearchCommand constructor.");
- LOG.info("Where:"+getSingleParameter("where"));
// hvis "where" parametern er sendt inn, så tar vi og leser inn query
fra
// den.
@@ -52,31 +53,21 @@
final Query query = rq.getQuery();
queryTwo = query.getQueryString();
-
}
}
/** TODO comment me. **/
public SearchResult execute() {
- LOG.info("execute()");
+ LOG.debug("execute()");
-
-
// kør vanligt søk, keywords.
searchForName=false;
- LOG.info("Søk med keyword query is :" + getTransformedQuery());
SearchResult result = super.execute();
-
searchForName=true;
- // kjør query tranformation en gang til, fordi flagget over
- // gør at resultatet blir annet enn første gangen.
- super.performQueryTransformation();
-
// søk etter firmanavn
- LOG.info("Søk med firmanavn query is :" + getTransformedQuery());
SearchResult nameQueryResult = super.execute();
// legg til navnsøk.
@@ -126,16 +117,74 @@
*/
protected void visitImpl(final LeafClause clause) {
String transformed = getTransformedTerm(clause);
+ terms.add(transformed);
+ }
+
+
+ @Override
+ public String getTransformedQuery() {
+ String query="";
- // to ulike søk utføres av denne komponenten, søk med keywords og søk
med firmanavn.
- if(!searchForName){
- appendToQueryRepresentation("(lemiypcfkeywords:"+transformed+"
ANY lemiypcfkeywordslow:"+transformed+")");
+ if(!searchForName){
+ String query1="(";
+ String query2="(";
+ // (lemiypcfkeywords:ord1 AND lemiypcfkeywords:ord2 AND
lemiypcfkeywords:ord3) ANY
+ // (lemiypcfkeywordslow:ord1 AND lemiypcfkeywordslow:ord2 AND
lemiypcfkeywordslow:ord3)
+
+ Iterator<String> it = terms.iterator();
+ for(;it.hasNext();){
+ String t = it.next();
+ query1 += "lemiypcfkeywords:"+t;
+ query2 += "lemiypcfkeywordslow:"+t;
+
+ // hvis det finnes flere
+ if(it.hasNext()){
+ query1 += " "+QL_AND+" ";
+ query2 += " "+QL_AND+" ";
+ }
+ }
+
+ // close queries.
+ query1 += ") ANY";
+ query2 += ")";
+ query = query1 + query2;
+
}else{
- appendToQueryRepresentation("(iypcfnavn:"+transformed+" ANDNOT
(lemiypcfkeywords:"+transformed+" OR lemiypcfkeywordslow:"+transformed+"))");
-
- }
+ String query1 = " (";
+ String query2 = " (";
+ String query3 = " (";
+
+ // eksempel på query.
+ // query1 = (iypcfphnavn:ord1 AND iypcfphnavn:ord2 AND
iypcfphnavn:ord3) ANDNOT (
+ // query2 = (lemiypcfkeywords:ord1 AND lemiypcfkeywords:ord2
AND lemiypcfkeywords:ord3) OR
+ // query3 = (lemiypcfkeywordslow:ord1 AND
lemiypcfkeywordslow:ord2 AND lemiypcfkeywordslow:ord3))
+
+ Iterator<String> it = terms.iterator();
+ for(;it.hasNext();){
+ String t = it.next();
+ query1 += "iypcfphnavn:"+t;
+ query2 += "lemiypcfkeywords:"+t;
+ query3 += "lemiypcfkeywordslow:"+t;
+
+ // hvis det finnes flere
+ if(it.hasNext()){
+ query1 += " "+QL_AND+" ";
+ query2 += " "+QL_AND+" ";
+ query3 += " "+QL_AND+" ";
+ }
+ }
+
+ // close queries.
+ query1 += ") ANDNOT (";
+ query2 += ") OR";
+ query3 += "))";
+ query=query1+query2+query3;
+ }
+
+ return query;
}
+
@Override
protected String getSortBy() {
// hvis man søker etter firmanavn, sorterer vi etter "iyprpnavn"
@@ -146,4 +195,5 @@
}
return sortBy;
}
+
}
Modified:
trunk/core-api/src/main/java/no/schibstedsok/searchportal/result/ProductResultItem.java
===================================================================
---
trunk/core-api/src/main/java/no/schibstedsok/searchportal/result/ProductResultItem.java
2007-02-08 10:53:36 UTC (rev 4419)
+++
trunk/core-api/src/main/java/no/schibstedsok/searchportal/result/ProductResultItem.java
2007-02-08 11:26:29 UTC (rev 4420)
@@ -1,7 +1,11 @@
package no.schibstedsok.searchportal.result;
+import java.util.Collection;
+
public interface ProductResultItem {
void addField(String field, String value);
String getField(String field);
+ public Collection getMultivaluedField(final String field);
+ public void addToMultivaluedField(final String field, final String value);
}
Modified:
trunk/core-api/src/main/java/no/schibstedsok/searchportal/result/handler/CatalogueResultHandler.java
===================================================================
---
trunk/core-api/src/main/java/no/schibstedsok/searchportal/result/handler/CatalogueResultHandler.java
2007-02-08 10:53:36 UTC (rev 4419)
+++
trunk/core-api/src/main/java/no/schibstedsok/searchportal/result/handler/CatalogueResultHandler.java
2007-02-08 11:26:29 UTC (rev 4420)
@@ -1,152 +1,41 @@
// Copyright (2006) Schibsted Søk AS
package no.schibstedsok.searchportal.result.handler;
-
-import java.sql.Connection;
-import java.sql.DriverManager;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.util.Iterator;
import java.util.Map;
-import javax.naming.NamingException;
-
import no.schibstedsok.commons.ioc.ContextWrapper;
-import no.schibstedsok.searchportal.mode.config.FastSearchConfiguration;
-import no.schibstedsok.searchportal.result.CatalogueSearchResultItem;
-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.site.config.SiteConfiguration;
import org.apache.log4j.Logger;
-
/**
- * Resulthandler to fetch sales from the catalogue sales system.
- * This class is called after a search command with <catalogue/>
- * resulthandler tag is defined. It loops through all result
- * items and load data with sql/jdbc from the sales system.
+ * Resulthandler to fetch sales from the catalogue sales system. This class is
+ * called after a search command with <catalogue/> resulthandler tag is
defined.
+ * It loops through all result items and load data with sql/jdbc from the sales
+ * system.
*
- * @todo Replace all JDBC/SQL code with call to Webservice in
- * sales system.
+ * @todo Add code to Jboss EJB3 stateless bean in salesadmin.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Daniel Engfeldt</a>
* @version <tt>$Revision: 3436 $</tt>
*/
public final class CatalogueResultHandler implements ResultHandler {
-
- private static final Logger LOG =
Logger.getLogger(CatalogueResultHandler.class);
- private String url = null;
- private String username = null;
- private String password = null;
-
- public void handleResult(final Context cxt, final Map parameters) {
- LOG.info("Starter Catalogue ResultHandler.");
-
- final SiteConfiguration siteConf
- =
SiteConfiguration.valueOf(ContextWrapper.wrap(SiteConfiguration.Context.class,
cxt));
- url = siteConf.getProperty("catalogue_ds.db");
- username = siteConf.getProperty("catalogue_ds.username");
- password = siteConf.getProperty("catalogue_ds.password");
+ private static final Logger LOG = Logger
+ .getLogger(CatalogueResultHandler.class);
- final SearchResult result = cxt.getSearchResult();
- fetchProducts(result);
- }
+ /**
+ * Handle the search result.
+ * @param cxt the context in which the resulthandler is executed in.
+ * @param parameters sent to the resulthandler.
+ */
+ public void handleResult(final Context cxt, final Map parameters) {
+ LOG.info("Starter Catalogue ResultHandler.");
-
- /**
- * This function gets all products for the resultList.
- *
- * @param result
- */
- private void fetchProducts(SearchResult result) {
- LOG.info("fetchProducts");
-
- // if result is missing, just exit this method
- if(result == null)
- return;
-
-
- //jdbc objects.
- Connection con = null;
- PreparedStatement stmt = null;
- ResultSet res = null;
-
- Iterator iter = result.getResults().listIterator();
-
- //placeholder for products
- ProductResult products = new ProductSearchResult();
- try {
-
-
- Class.forName("com.mysql.jdbc.Driver");
-
- con
- = DriverManager.getConnection(url,username,password);
-
- 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");
-
- while (iter.hasNext()) {
- CatalogueSearchResultItem resultItem =
(CatalogueSearchResultItem) iter.next();
+ final SiteConfiguration siteConf = SiteConfiguration
+
.valueOf(ContextWrapper.wrap(SiteConfiguration.Context.class,
+ cxt));
-
-
stmt.setString(1,resultItem.getField("iyporgnr"));
- LOG.info("Hent produkter for firma med
organisasjonsnr: "+resultItem.getField("iyporgnr"));
-
- res = stmt.executeQuery();
- LOG.info("sql er kjørt");
-
- if(res.next()){
- LOG.info("Finne produkter for
firma, les inn data.");
- ProductResultItem
infoPageProduct = new ProductSearchResultItem();
-
-
- //infoPageProducts goes on the
infopage
- if(res.getString("text1") !=
null){
-
infoPageProduct.addField("text1", res.getString("text1"));
- LOG.info("lagt inn
text1 felt i produktet: "+infoPageProduct.getField("text1"));
- }
- //infoPageProducts goes on the
infopage
- if(res.getString("textShort")
!= null){
-
infoPageProduct.addField("textShort", res.getString("textShort"));
- LOG.info("lagt inn
textShort felt i produktet: "+infoPageProduct.getField("textShort"));
- }
-
-
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.");
- }
-
- } // end while.
-
- } catch (SQLException e) {
- LOG.error("SQLException, Feil ved uthenting av
produkter",e);
- }catch(ClassNotFoundException e){
- LOG.error("ClassNotFoundException, Feil ved
uthenting av jdbc driver",e);
- }finally {
- try {if (res != null) res.close();} catch
(SQLException e) { LOG.error("Could not close ResultSet",e);}
- try {if (stmt != null) stmt.close();} catch
(SQLException e) { LOG.error("Could not close Statement",e);}
- try {if (con != null) con.close();} catch
(SQLException e) { LOG.error("Could not close Connection",e);}
-
- }
-
-
-
- }
-
-
-
+ }
}
Modified: trunk/war/pom.xml
===================================================================
--- trunk/war/pom.xml 2007-02-08 10:53:36 UTC (rev 4419)
+++ trunk/war/pom.xml 2007-02-08 11:26:29 UTC (rev 4420)
@@ -140,13 +140,6 @@
<groupId>axis</groupId>
<artifactId>axis-saaj</artifactId>
</dependency>
-
- <dependency>
- <groupId>mysql</groupId>
- <artifactId>mysql-connector-java</artifactId>
- <version>5.0.4</version>
- </dependency>
-
</dependencies>
<profiles>
<profile>
_______________________________________________
Kernel-commits mailing list
[email protected]
http://sesat.no/mailman/listinfo/kernel-commits