Author: daniele
Date: 2007-03-21 15:23:22 +0100 (Wed, 21 Mar 2007)
New Revision: 4599
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
Log:
Some small tweaks of the generated query to handle special characters like dot
and hyphens
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-03-21 12:51:39 UTC (rev 4598)
+++
trunk/core-api/src/main/java/no/schibstedsok/searchportal/mode/command/CatalogueAdsSearchCommand.java
2007-03-21 14:23:22 UTC (rev 4599)
@@ -134,12 +134,21 @@
SearchResult secondQueryResult = null;
+ // if the query type is domestic, then we dont need to run more than
+ // the domestic search and return the results the way they were
returned
+ // by Fast.
+ if(queryGeoString.equals(DOMESTIC_SEARCH)){
+ whichQueryToRun = QueryType.INGENSTEDS;
+ firstQueryResult = super.execute();
+ return firstQueryResult;
+ }
+
whichQueryToRun = QueryType.GEO;
firstQueryResult = super.execute();
LOG.info("Found "+firstQueryResult.getHitCount()+" sponsed links");
- if (firstQueryResult.getHitCount() < 5 &&
!queryGeoString.equals(DOMESTIC_SEARCH)) {
+ if (firstQueryResult.getHitCount() < 5) {
// Build the search result to return from this method
// during processing in this array.
@@ -229,16 +238,23 @@
originalQuery = super.getTransformedQuery().replaceAll(" ",
"").toLowerCase();
String query = null;
+ String completeQuery = null;
if (whichQueryToRun == QueryType.GEO) {
query = super.getTransformedQuery().replaceAll(" ", "")
+ queryGeoString.replaceAll(" ", "");
+
+
} else {
query = super.getTransformedQuery().replaceAll(" ", "")
+ DOMESTIC_SEARCH;
+
}
- return "iypspkeywords5:" + query + " OR iypspkeywords4:" + query + "
OR iypspkeywords3:" + query
- + " OR iypspkeywords2:" + query + " OR iypspkeywords1:" +
query;
+
+ completeQuery = "iypcfspkeywords5:" + query + " OR iypcfspkeywords4:"
+ query + " OR iypcfspkeywords3:" + query
+ + " OR iypcfspkeywords2:" + query + " OR iypcfspkeywords1:" +
query;
+
+ return completeQuery;
}
/**
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-03-21 12:51:39 UTC (rev 4598)
+++
trunk/core-api/src/main/java/no/schibstedsok/searchportal/mode/command/CatalogueSearchCommand.java
2007-03-21 14:23:22 UTC (rev 4599)
@@ -8,6 +8,8 @@
import java.util.Iterator;
import java.util.List;
import java.util.Map;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
import no.schibstedsok.commons.ioc.BaseContext;
import no.schibstedsok.commons.ioc.ContextWrapper;
import no.schibstedsok.searchportal.datamodel.DataModel;
@@ -31,6 +33,7 @@
import no.schibstedsok.searchportal.result.SearchResult;
import org.apache.log4j.Logger;
+import org.omg.CORBA.MARSHAL;
/**
* The CatalogueSearchCommand is responsible for the query to search for
@@ -171,6 +174,9 @@
* Put the result into two different attributes, catalogueWhat and
* catalogueWhere to be used in the frontend.
*
+ * If the split results in empty Who and Where from split, use the
+ * original untransformed query.
+ *
* Populate the knownGeo and knownGeoString which is used by the visitXxx
* methods to known which terms to ignore when constructing the
* query for this searchcommand.
@@ -194,8 +200,17 @@
final WhoWhereSplit splitQuery = splitter.getWhoWhereSplit();
- getParameters().put(PARAMETER_NAME_WHAT, splitQuery.getWho());
- getParameters().put(PARAMETER_NAME_WHERE, splitQuery.getWhere());
+ if((splitQuery.getWho()==null || splitQuery.getWho().length()==0)
+ && (splitQuery.getWhere()==null ||
splitQuery.getWhere().length()==0)){
+ getParameters().put(PARAMETER_NAME_WHAT,
getParameters().get("q"));
+ getParameters().put(PARAMETER_NAME_WHERE, "");
+
+
+ }else{
+ getParameters().put(PARAMETER_NAME_WHAT, splitQuery.getWho());
+ getParameters().put(PARAMETER_NAME_WHERE,
splitQuery.getWhere());
+
+ }
String[] where = splitQuery.getWhere().split(" ");
@@ -222,7 +237,7 @@
SearchResult result = super.execute();
List<CatalogueSearchResultItem> nyResultListe = new
ArrayList<CatalogueSearchResultItem>();
-
+
Iterator iter = result.getResults().listIterator();
while (iter.hasNext()) {
BasicSearchResultItem basicResultItem = (BasicSearchResultItem)
iter
@@ -260,7 +275,7 @@
boolean hasQueryString= (query!=null && query.length()>0);
boolean hasGeoQueryString = (queryGeoString != null &&
queryGeoString.length() > 0);
-
+
// two possible paths, with both what and where in query,
// or just where. If nothing in either, something is wrong.
if (hasQueryString && hasGeoQueryString){
@@ -275,7 +290,7 @@
query = queryGeoString;
} else if (hasQueryString && !hasGeoQueryString) {
-
+
// just what,
// dosent need to do anything with the query, should just leave
// the query as it is after transformation.
@@ -311,31 +326,65 @@
return sortBy;
}
+
/**
+ * Create query syntax for a phrase term.
+ * @param term the term to make query syntax for.
+ * @return created phrase query fragment for one term.
+ */
+ private String createPhraseQuerySyntax(final String term) {
+ StringBuffer sb = new StringBuffer();
+ sb.append("(");
+ sb.append("iypcfnavn:" + term + " ANY ");
+ sb.append("lemiypcfkeywords:" + term + " ANY ");
+ sb.append("lemiypcfkeywordslow:" + term);
+ sb.append(")");
+ return sb.toString();
+ }
+
+ /**
* Create the query syntax for a search term.
*
* If the query is defined to split known geographic locations from
* the keywords, ignore the term.
*
+ * Check if there is any special characters in the query, if there
+ * is, wrap term in " " characters and use none-phonetic composite field
+ * in index for part of query.
+ *
* If the term is '*', also ignore it.
* @param clause the clause to process.
*/
@Override
protected void visitImpl(final LeafClause clause) {
boolean useTerm = true;
-
+ boolean hasNotWordCharacters = false;
+
if(split && knownGeo.contains(clause.getTerm())){
useTerm=false;
}
+
+ Pattern p = Pattern.compile(".*\\.|.*\\-");
+ Matcher m = p.matcher(getTransformedTerms().get(clause));
+
+ hasNotWordCharacters = m.matches();
+
if(useTerm){
- if (!getTransformedTerms().get(clause).equals("*")) {
+
+ if(hasNotWordCharacters){
+
+ appendToQueryRepresentation(
+
createPhraseQuerySyntax("\""+getTransformedTerms().get(clause) + "\""));
+
+ }else if(!getTransformedTerms().get(clause).equals("*")) {
StringBuilder sb = new StringBuilder();
sb.append("(");
- sb.append("iypcfphnavn:" + getTransformedTerms().get(clause)
- + " ANY ");
+
+ sb.append("iypcfphnavn:"+getTransformedTerms().get(clause) + "
ANY ");
+
sb.append("lemiypcfkeywords:" +
getTransformedTerms().get(clause)
- + " ANY ");
+ + " ANY ");
sb.append("lemiypcfkeywordslow:"
+ getTransformedTerms().get(clause));
sb.append(")");
@@ -363,16 +412,8 @@
if(useTerm){
if (!getTransformedTerms().get(clause).equals("*")) {
- StringBuilder sb = new StringBuilder();
- sb.append("(");
- sb.append("iypcfnavn:" + getTransformedTerms().get(clause)
- + " ANY ");
- sb.append("lemiypcfkeywords:" +
getTransformedTerms().get(clause)
- + " ANY ");
- sb.append("lemiypcfkeywordslow:"
- + getTransformedTerms().get(clause));
- sb.append(")");
- appendToQueryRepresentation(sb.toString());
+ appendToQueryRepresentation(
+
createPhraseQuerySyntax(getTransformedTerms().get(clause)));
}
}
}
@@ -440,7 +481,7 @@
*
*/
private final class GeoVisitor extends AbstractReflectionVisitor {
-
+
/** the composite field in the index to search in. */
private static final String GEO_COMPOSITE_FIELD_NAME = "iypcfgeo:";
@@ -456,7 +497,6 @@
return sb.toString();
}
-
protected void visitImpl(final LeafClause clause) {
if (clause.getTerm() != null && clause.getTerm().length() > 0) {
sb.append(GEO_COMPOSITE_FIELD_NAME + clause.getTerm());
_______________________________________________
Kernel-commits mailing list
[email protected]
http://sesat.no/mailman/listinfo/kernel-commits