Author: ssmiweve
Date: 2008-02-11 23:47:30 +0100 (Mon, 11 Feb 2008)
New Revision: 6109

Modified:
   
branches/2.16/generic.sesam/search-command-control/default/src/main/java/no/sesat/search/mode/command/YahooIdpSearchCommand.java
Log:
SEARCH-4251 - Or (..) searches do not work against yahoo
SEARCH-1488 - Search for * should return all results for Netts?\195?\184k


Modified: 
branches/2.16/generic.sesam/search-command-control/default/src/main/java/no/sesat/search/mode/command/YahooIdpSearchCommand.java
===================================================================
--- 
branches/2.16/generic.sesam/search-command-control/default/src/main/java/no/sesat/search/mode/command/YahooIdpSearchCommand.java
    2008-02-11 19:16:40 UTC (rev 6108)
+++ 
branches/2.16/generic.sesam/search-command-control/default/src/main/java/no/sesat/search/mode/command/YahooIdpSearchCommand.java
    2008-02-11 22:47:30 UTC (rev 6109)
@@ -31,6 +31,7 @@
 import no.sesat.search.query.AndClause;
 import no.sesat.search.query.AndNotClause;
 import no.sesat.search.query.DefaultOperatorClause;
+import no.sesat.search.query.LeafClause;
 import no.sesat.search.query.NotClause;
 import no.sesat.search.query.OrClause;
 import no.sesat.search.query.PhraseClause;
@@ -72,9 +73,10 @@
     private static final String RESULT_ELEMENT = "RESULT";
     private static final String WORDCOUNTS_ELEMENT = "WORDCOUNTS";
 
-    private static final String ALLWORDS = "ALLWORDS(";
+    // private static final String ALLWORDS = "ALLWORDS("; // not used for 
now. could be as ANYWORDS optimisation
     private static final String ANYWORDS = "ANYWORDS(";
     private static final String PHRASEWORDS = "PHRASEWORDS(";
+    private static final String OMNISEARCH_HACK = "a b c d e f g h i j k l m n 
o p q r s t u v w x y z";
 
     /**
      * Create new overture command.
@@ -87,13 +89,13 @@
 
     /** [EMAIL PROTECTED] **/
     public ResultList<? extends ResultItem> execute() {
-        
+
         try {
-            
+
             final ResultList<ResultItem> searchResult = new 
BasicResultList<ResultItem>();
-                
-            if(getTransformedQuery().trim().length() > 0 
-                    || getAdditionalFilter().trim().length() > 0 
+
+            if(getTransformedQuery().trim().length() > 0
+                    || getAdditionalFilter().trim().length() > 0
                     || "*".equals(getQuery().getQueryString())){
 
                 final Document doc = getXmlResult();
@@ -112,7 +114,7 @@
                         totalHits = Integer.MAX_VALUE;
                     }
                     searchResult.addField("totalhits", ""+totalHits);
-                    
+
                     int deepHits;
                     try {
                         deepHits = 
Integer.parseInt(deepHitsE.getFirstChild().getNodeValue());
@@ -120,7 +122,7 @@
                     catch(NumberFormatException e) {
                         deepHits = Integer.MAX_VALUE;
                     }
-                    searchResult.addField("deephits", ""+deepHits);            
        
+                    searchResult.addField("deephits", ""+deepHits);
                     searchResult.setHitCount(deepHits);
 
                     if(searchResult.getHitCount() > totalHits) {
@@ -155,7 +157,7 @@
                 }
             }
             return searchResult;
-            
+
         } catch (SocketTimeoutException ste) {
 
             LOG.error(getSearchConfiguration().getName() +  " --> " + 
ste.getMessage());
@@ -163,7 +165,7 @@
 
         } catch (IOException e) {
             throw new SearchCommandException(e);
-            
+
         } catch (SAXException e) {
             throw new SearchCommandException(e);
         }
@@ -171,14 +173,14 @@
 
     /** TODO comment me. **/
     protected String createRequestURL() {
-        
+
         final YahooIdpCommandConfig conf = (YahooIdpCommandConfig) 
context.getSearchConfiguration();
 
         final String dateRange = '-' + new 
SimpleDateFormat(DATE_PATTERN).format(new Date());
 
-        final String wrappedTransformedQuery = ALLWORDS 
+        final String wrappedTransformedQuery = ANYWORDS
                 // support "*" searches that return everything in the index.
-                + ("*".equals(getQuery().getQueryString()) ? '*' : 
getTransformedQuery()) + ' '
+                + ("*".equals(getQuery().getQueryString()) ? OMNISEARCH_HACK : 
getTransformedQuery()) + ' '
                 // HACK since AbstractSearchCommand.FilterVisitor is built for 
FAST prepending filters with +
                 + getAdditionalFilter().replaceAll("\\+", "") + ')';
 
@@ -224,7 +226,7 @@
 
     /** TODO comment me. **/
     protected BasicResultItem createItem(final Element result) {
-        
+
         final BasicResultItem item = new BasicResultItem();
 
         for (final Map.Entry<String,String> entry : 
context.getSearchConfiguration().getResultFields().entrySet()){
@@ -248,7 +250,22 @@
         return tq;
     }
 
+    // third state variable. TRUE --> must have clause, FALSE --> must not 
have clause, null --> optional clause.
+    private Boolean clauseState = Boolean.TRUE;
+
     /** TODO comment me. **/
+    @Override
+    protected void visitImpl(final LeafClause clause) {
+
+        if(Boolean.TRUE == clauseState){
+            appendToQueryRepresentation('+');
+        }else if(Boolean.FALSE == clauseState){
+            appendToQueryRepresentation('-');
+        }
+        super.visitImpl(clause);
+    }
+
+    /** TODO comment me. **/
     protected void visitImpl(final PhraseClause clause) {
         if (clause.getField() == null) {
             appendToQueryRepresentation(PHRASEWORDS + 
getTransformedTerm(clause) + ')');
@@ -258,28 +275,33 @@
     /** TODO comment me. **/
     @Override
     protected void visitImpl(final AndClause clause) {
-        appendToQueryRepresentation(ALLWORDS);
+
+        clauseState = Boolean.TRUE;
         clause.getFirstClause().accept(this);
         appendToQueryRepresentation(' ');
+        clauseState = Boolean.TRUE;
         clause.getSecondClause().accept(this);
-        appendToQueryRepresentation(')');
     }
 
     /** TODO comment me. **/
     @Override
     protected void visitImpl(final OrClause clause) {
-        appendToQueryRepresentation(ANYWORDS);
+
+        clauseState = null;
         clause.getFirstClause().accept(this);
         appendToQueryRepresentation(' ');
+        clauseState = null;
         clause.getSecondClause().accept(this);
-        appendToQueryRepresentation(')');
     }
 
     /** TODO comment me. **/
     @Override
     protected void visitImpl(final DefaultOperatorClause clause) {
+
+        clauseState = Boolean.TRUE;
         clause.getFirstClause().accept(this);
         appendToQueryRepresentation(' ');
+        clauseState = Boolean.TRUE;
         clause.getSecondClause().accept(this);
     }
 
@@ -288,7 +310,7 @@
     protected void visitImpl(final NotClause clause) {
         final String childsTerm = getTransformedTerm(clause.getFirstClause());
         if (childsTerm != null && childsTerm.length() > 0) {
-            appendToQueryRepresentation("-");
+            clauseState = Boolean.FALSE;
             clause.getFirstClause().accept(this);
         }
     }
@@ -298,7 +320,7 @@
     protected void visitImpl(final AndNotClause clause) {
         final String childsTerm = getTransformedTerm(clause.getFirstClause());
         if (childsTerm != null && childsTerm.length() > 0) {
-            appendToQueryRepresentation("-");
+            clauseState = Boolean.FALSE;
             clause.getFirstClause().accept(this);
         }
     }

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

Reply via email to