Author: ssmiweve
Date: 2008-12-04 14:50:01 +0100 (Thu, 04 Dec 2008)
New Revision: 7038

Modified:
   
branches/2.18/generic.sesam/query-evaluation/src/main/java/no/sesat/search/query/token/FastQueryMatchingEvaluatorFactory.java
   
branches/2.18/generic.sesam/query-evaluation/src/main/java/no/sesat/search/query/token/JepTokenEvaluator.java
   
branches/2.18/generic.sesam/query-evaluation/src/main/java/no/sesat/search/query/token/RegExpTokenEvaluator.java
   
branches/2.18/generic.sesam/query-evaluation/src/main/java/no/sesat/search/query/token/SolrEvaluatorFactory.java
   
branches/2.18/generic.sesam/query-evaluation/src/main/java/no/sesat/search/query/token/SolrTokenEvaluator.java
   
branches/2.18/generic.sesam/query-evaluation/src/main/java/no/sesat/search/query/token/VeryFastTokenEvaluator.java
   
branches/2.18/query-api/src/main/java/no/sesat/search/query/token/TokenEvaluationEngine.java
   
branches/2.18/query-api/src/main/java/no/sesat/search/query/token/TokenEvaluator.java
Log:
make the evaluation requests (solr + fast) lazy.
provide timeout value for solr evaluations.
move getMatchValues(..) up into TokenEvaluator


Modified: 
branches/2.18/generic.sesam/query-evaluation/src/main/java/no/sesat/search/query/token/FastQueryMatchingEvaluatorFactory.java
===================================================================
--- 
branches/2.18/generic.sesam/query-evaluation/src/main/java/no/sesat/search/query/token/FastQueryMatchingEvaluatorFactory.java
       2008-12-04 13:39:16 UTC (rev 7037)
+++ 
branches/2.18/generic.sesam/query-evaluation/src/main/java/no/sesat/search/query/token/FastQueryMatchingEvaluatorFactory.java
       2008-12-04 13:50:01 UTC (rev 7038)
@@ -114,7 +114,7 @@
         try {
             // when the root logger is set to DEBUG do not limit connection 
times
             if(Logger.getRootLogger().getLevel().isGreaterOrEqual(Level.INFO)){
-
+                // default timeout is one second. TODO make configuration.
                 fastEvaluatorCreator.get(1000, TimeUnit.MILLISECONDS);
             }else{
                 fastEvaluatorCreator.get();

Modified: 
branches/2.18/generic.sesam/query-evaluation/src/main/java/no/sesat/search/query/token/JepTokenEvaluator.java
===================================================================
--- 
branches/2.18/generic.sesam/query-evaluation/src/main/java/no/sesat/search/query/token/JepTokenEvaluator.java
       2008-12-04 13:39:16 UTC (rev 7037)
+++ 
branches/2.18/generic.sesam/query-evaluation/src/main/java/no/sesat/search/query/token/JepTokenEvaluator.java
       2008-12-04 13:50:01 UTC (rev 7038)
@@ -22,6 +22,8 @@
 
 package no.sesat.search.query.token;
 
+import java.util.Collections;
+import java.util.Set;
 import org.nfunk.jep.JEP;
 import org.nfunk.jep.type.Complex;
 
@@ -113,6 +115,10 @@
         return queryDependant;
     }
 
+    public Set<String> getMatchValues(final TokenPredicate token, final String 
term) {
+        return Collections.emptySet();
+    }
+
     // Y overrides ---------------------------------------------------
 
     // Package protected ---------------------------------------------

Modified: 
branches/2.18/generic.sesam/query-evaluation/src/main/java/no/sesat/search/query/token/RegExpTokenEvaluator.java
===================================================================
--- 
branches/2.18/generic.sesam/query-evaluation/src/main/java/no/sesat/search/query/token/RegExpTokenEvaluator.java
    2008-12-04 13:39:16 UTC (rev 7037)
+++ 
branches/2.18/generic.sesam/query-evaluation/src/main/java/no/sesat/search/query/token/RegExpTokenEvaluator.java
    2008-12-04 13:50:01 UTC (rev 7038)
@@ -18,6 +18,8 @@
 
 import java.util.ArrayList;
 import java.util.Collection;
+import java.util.Collections;
+import java.util.Set;
 import java.util.regex.Pattern;
 import java.util.regex.Matcher;
 import org.apache.log4j.Logger;
@@ -81,4 +83,9 @@
     public boolean isQueryDependant(final TokenPredicate predicate) {
         return queryDependant;
     }
+
+    public Set<String> getMatchValues(final TokenPredicate token, final String 
term) {
+        return Collections.emptySet();
+    }
+
 }

Modified: 
branches/2.18/generic.sesam/query-evaluation/src/main/java/no/sesat/search/query/token/SolrEvaluatorFactory.java
===================================================================
--- 
branches/2.18/generic.sesam/query-evaluation/src/main/java/no/sesat/search/query/token/SolrEvaluatorFactory.java
    2008-12-04 13:39:16 UTC (rev 7037)
+++ 
branches/2.18/generic.sesam/query-evaluation/src/main/java/no/sesat/search/query/token/SolrEvaluatorFactory.java
    2008-12-04 13:50:01 UTC (rev 7038)
@@ -289,7 +289,7 @@
 
             // when the root logger is set to DEBUG do not limit connection 
times
             if(Logger.getRootLogger().getLevel().isGreaterOrEqual(Level.INFO)){
-
+                // default timeout is one second. TODO make configuration.
                 solrEvaluatorCreator.get(1000, TimeUnit.MILLISECONDS);
             }else{
                 solrEvaluatorCreator.get();

Modified: 
branches/2.18/generic.sesam/query-evaluation/src/main/java/no/sesat/search/query/token/SolrTokenEvaluator.java
===================================================================
--- 
branches/2.18/generic.sesam/query-evaluation/src/main/java/no/sesat/search/query/token/SolrTokenEvaluator.java
      2008-12-04 13:39:16 UTC (rev 7037)
+++ 
branches/2.18/generic.sesam/query-evaluation/src/main/java/no/sesat/search/query/token/SolrTokenEvaluator.java
      2008-12-04 13:50:01 UTC (rev 7038)
@@ -31,6 +31,7 @@
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 import no.sesat.search.query.token.AbstractEvaluatorFactory.Context;
+import org.apache.log4j.Level;
 import static no.sesat.search.query.parser.AbstractQueryParser.SKIP_REGEX;
 import static no.sesat.search.query.parser.AbstractQueryParser.OPERATOR_REGEX;
 import org.apache.log4j.Logger;
@@ -69,7 +70,7 @@
 
     private final Context context;
     private SolrEvaluatorFactory factory;
-    private final Map<String, List<TokenMatch>> analysisResult;
+    private transient Map<String, List<TokenMatch>> analysisResult;
 
     // Static --------------------------------------------------------
 
@@ -85,13 +86,11 @@
      * @param factory
      * @throws EvaluationException
      */
-    public SolrTokenEvaluator(final Context cxt, final SolrEvaluatorFactory 
factory) throws EvaluationException{
+    SolrTokenEvaluator(final Context cxt, final SolrEvaluatorFactory factory) 
throws EvaluationException{
 
         context = cxt;
         this.factory = factory;
 
-        // Remove whitespace (except space itself) and operator characters.
-        analysisResult = query(cleanString(cxt.getQueryString()));
     }
 
     // Public --------------------------------------------------------
@@ -107,6 +106,8 @@
 
                 final String listname = listnames[i];
 
+                if(null == analysisResult){ analysisResult = 
query(cleanString(context.getQueryString())); }
+
                 if (analysisResult.containsKey(listname)) {
                     if (term == null) {
                         evaluation = true;
@@ -150,6 +151,9 @@
         if(null != listnames){
             for(int i = 0; i < listnames.length; i++){
                 final String listname = listnames[i];
+
+                if(null == analysisResult){ analysisResult = 
query(cleanString(context.getQueryString())); }
+
                 if (analysisResult.containsKey(listname)) {
 
                     // HACK since DefaultOperatorClause wraps its children in 
parenthesis
@@ -190,7 +194,7 @@
      * @param query
      */
     @SuppressWarnings("unchecked")
-    private Map<String, List<TokenMatch>> query(final String query) throws 
EvaluationException{
+    private synchronized Map<String, List<TokenMatch>> query(final String 
query){
 
         LOG.trace("queryFast( " + query + " )");
         Map<String, List<TokenMatch>> result = null;
@@ -214,6 +218,12 @@
                             .setQuery("list_entry_shingle:\"" + token + "\"")
                             .setRows(Integer.MAX_VALUE);
 
+                    // when the root logger is set to DEBUG do not limit 
connection times
+                    
if(Logger.getRootLogger().getLevel().isGreaterOrEqual(Level.INFO)){
+                        // default timeout is half second. TODO make 
configuration.
+                        solrQuery.setTimeAllowed(500);
+                    }
+
                     DUMP.info(solrQuery.toString());
 
                     // query
@@ -250,7 +260,7 @@
 
                 } catch (SolrServerException ex) {
                     LOG.error(ex.getMessage(), ex);
-                    throw new EvaluationException(ERR_QUERY_FAILED + url, ex);
+                    throw new EvaluationRuntimeException(new 
EvaluationException(ERR_QUERY_FAILED + url, ex));
 
                 }finally{
                     if(!updatedCache){

Modified: 
branches/2.18/generic.sesam/query-evaluation/src/main/java/no/sesat/search/query/token/VeryFastTokenEvaluator.java
===================================================================
--- 
branches/2.18/generic.sesam/query-evaluation/src/main/java/no/sesat/search/query/token/VeryFastTokenEvaluator.java
  2008-12-04 13:39:16 UTC (rev 7037)
+++ 
branches/2.18/generic.sesam/query-evaluation/src/main/java/no/sesat/search/query/token/VeryFastTokenEvaluator.java
  2008-12-04 13:50:01 UTC (rev 7038)
@@ -105,7 +105,7 @@
 
     private final Context context;
     private final Site site;
-    private final Map<String, List<TokenMatch>> analysisResult;
+    private transient Map<String, List<TokenMatch>> analysisResult;
 
     // Static --------------------------------------------------------
 
@@ -128,27 +128,10 @@
 
         init();
 
-        // Remove whitespace (except space itself) and operator characters.
-        analysisResult = queryFast(cleanString(context.getQueryString()));
-
     }
 
     // Public --------------------------------------------------------
 
-    /**
-     * Find out if given token is on or more of the following.
-     *      <li>GEO
-     *      <li>FIRSTNAME
-     *      <li>LASTNAME
-     *      <li>COMPANY
-     *      <li>KEYWORDS
-     *      <li>CATEGORY
-     * </ul>
-     *
-     * @param token  can be any of the above
-     * @param query
-     * @return true if the query contains any of the above
-     */
     public boolean evaluateToken(final TokenPredicate token, final String 
term, final String query) {
 
         boolean evaluation = false;
@@ -159,6 +142,8 @@
 
                 final String listname = listnames[i];
 
+                if(null == analysisResult){ analysisResult = 
queryFast(cleanString(context.getQueryString())); }
+
                 if (analysisResult.containsKey(listname)) {
                     if (term == null) {
                         evaluation = true;
@@ -186,14 +171,6 @@
         return evaluation;
     }
 
-
-    /**
-     * get all match values and values for given Fast list .
-     *
-     * @param token
-     * @param term
-     * @return a list of Tokens
-     */
     public Set<String> getMatchValues(final TokenPredicate token, final String 
term) {
 
         final Set<String> values = new HashSet<String>();
@@ -202,6 +179,9 @@
         if(null != listnames){
             for(int i = 0; i < listnames.length; i++){
                 final String listname = listnames[i];
+
+                if(null == analysisResult){ analysisResult = 
queryFast(cleanString(context.getQueryString())); }
+
                 if (analysisResult.containsKey(listname)) {
 
                     // HACK since DefaultOperatorClause wraps its children in 
parenthesis
@@ -221,11 +201,6 @@
         return Collections.unmodifiableSet(values);
     }
 
-    /**
-     *
-     * @param predicate
-     * @return
-     */
     public boolean isQueryDependant(final TokenPredicate predicate) {
         return predicate.name().startsWith(EXACT_PREFIX.toUpperCase());
     }
@@ -346,7 +321,7 @@
      * @param query
      */
     @SuppressWarnings("unchecked")
-    private Map<String, List<TokenMatch>> queryFast(final String query) throws 
EvaluationException{
+    private synchronized Map<String, List<TokenMatch>> queryFast(final String 
query){
 
         LOG.trace("queryFast( " + query + " )");
         Map<String, List<TokenMatch>> result = null;
@@ -426,11 +401,11 @@
                 } catch (IOException e1) {
                     LOG.error(ERR_QUERY_FAILED + url, e1);
                     result = (Map<String, 
List<TokenMatch>>)nre.getCacheContent();
-                    throw new EvaluationException(ERR_QUERY_FAILED + url, e1);
+                    throw new EvaluationRuntimeException(new 
EvaluationException(ERR_QUERY_FAILED + url, e1));
                 } catch (SAXException e1) {
                     LOG.error(ERR_PARSE_FAILED + url, e1);
                     result = (Map<String, 
List<TokenMatch>>)nre.getCacheContent();
-                    throw new EvaluationException(ERR_PARSE_FAILED + url, e1);
+                    throw new EvaluationRuntimeException(new 
EvaluationException(ERR_PARSE_FAILED + url, e1));
                 }finally{
                     if(!updatedCache){
                         CACHE_QUERY.cancelUpdate(query);

Modified: 
branches/2.18/query-api/src/main/java/no/sesat/search/query/token/TokenEvaluationEngine.java
===================================================================
--- 
branches/2.18/query-api/src/main/java/no/sesat/search/query/token/TokenEvaluationEngine.java
        2008-12-04 13:39:16 UTC (rev 7037)
+++ 
branches/2.18/query-api/src/main/java/no/sesat/search/query/token/TokenEvaluationEngine.java
        2008-12-04 13:50:01 UTC (rev 7038)
@@ -18,6 +18,7 @@
 package no.sesat.search.query.token;
 
 import java.io.Serializable;
+import java.util.Collections;
 import java.util.Set;
 import no.sesat.commons.ioc.BaseContext;
 import no.sesat.search.query.Clause;
@@ -58,10 +59,12 @@
         public boolean evaluateToken(final TokenPredicate token, final String 
term, final String query) {
             return false;
         }
-
         public boolean isQueryDependant(final TokenPredicate predicate) {
             return false;
         }
+        public Set<String> getMatchValues(final TokenPredicate token, final 
String term) {
+            return Collections.emptySet();
+        }
     };
 
     /**
@@ -71,10 +74,12 @@
         public boolean evaluateToken(final TokenPredicate token, final String 
term, final String query) {
             return true;
         }
-
         public boolean isQueryDependant(final TokenPredicate predicate) {
             return false;
         }
+        public Set<String> getMatchValues(final TokenPredicate token, final 
String term) {
+            return Collections.emptySet();
+        }
     };
 
     /**
@@ -88,6 +93,9 @@
         public boolean isQueryDependant(final TokenPredicate predicate) {
             return false;
         }
+        public Set<String> getMatchValues(final TokenPredicate token, final 
String term) {
+            return Collections.emptySet();
+        }
     };
 
     /**

Modified: 
branches/2.18/query-api/src/main/java/no/sesat/search/query/token/TokenEvaluator.java
===================================================================
--- 
branches/2.18/query-api/src/main/java/no/sesat/search/query/token/TokenEvaluator.java
       2008-12-04 13:39:16 UTC (rev 7037)
+++ 
branches/2.18/query-api/src/main/java/no/sesat/search/query/token/TokenEvaluator.java
       2008-12-04 13:50:01 UTC (rev 7038)
@@ -1,5 +1,5 @@
 /*
- * Copyright (2005-2007) Schibsted Søk AS
+ * Copyright (2005-2008) Schibsted Søk AS
  * This file is part of SESAT.
  *
  *   SESAT is free software: you can redistribute it and/or modify
@@ -16,13 +16,22 @@
  *   along with SESAT.  If not, see <http://www.gnu.org/licenses/>.
  */
 package no.sesat.search.query.token;
+import java.util.Set;
 
 
 
-/**
+/** TokenEvaluator works behind a TokenPredicate doing the actual work to 
prove the predicate true or false.
+ * This work is the evaluating process. Each TokenValuator is constructed and 
obtained through a corresponding
+ * AbstractEvaluatorFactory.
  *
+ * evaluateToken(TokenPredicate, String, String) is the primary method in the 
class,
+ * but evaluators may also indicate whether the position of words within the 
query influences evaluation
+ * by the isQueryDependant(TokenPredicate) method.
  *
- * @version <tt>$Revision$</tt>
+ * And synonyms may also be provided, extending predicates from true|false to 
being a richer meta data source.
+ *
+ *
+ * @version <tt>$Id$</tt>
  */
 public interface TokenEvaluator {
 
@@ -45,4 +54,12 @@
      * @return
      */
     boolean isQueryDependant(TokenPredicate predicate);
+
+    /** Each true evaluation may also provide a synonym (or "match value").
+     *
+     * @param token
+     * @param term
+     * @return a list of Tokens
+     */
+    Set<String> getMatchValues(final TokenPredicate token, final String term);
 }

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

Reply via email to