Author: ssmiweve
Date: 2008-11-16 23:09:16 +0100 (Sun, 16 Nov 2008)
New Revision: 6940

Added:
   
trunk/query-api/src/main/java/no/sesat/search/query/token/DeadTokenEvaluationEngineImpl.java
Modified:
   trunk/core-api/src/main/java/no/sesat/search/run/RunningQueryImpl.java
   trunk/generic.sesam/war/src/main/conf/modes.xml
   trunk/mojo/src/main/java/no/sesat/mojo/modes/Builder.java
   
trunk/query-api/src/main/java/no/sesat/search/query/token/TokenEvaluationEngine.java
Log:
Performance improvements.
Make it possible to turn off query evaluation. in this case the 
DeadTokenEvaluationEngineImpl is used which throws a EvaluationRuntimeException 
is thrown on any evaluation attempt (which prevents a false evaluation result 
from 
being cached).
part of this was accidently committed in r6936 (SearchMode + SearchModeFactory)
SEARCH-5168


Modified: trunk/core-api/src/main/java/no/sesat/search/run/RunningQueryImpl.java
===================================================================
--- trunk/core-api/src/main/java/no/sesat/search/run/RunningQueryImpl.java      
2008-11-16 22:02:30 UTC (rev 6939)
+++ trunk/core-api/src/main/java/no/sesat/search/run/RunningQueryImpl.java      
2008-11-16 22:09:16 UTC (rev 6940)
@@ -19,6 +19,7 @@
 package no.sesat.search.run;
 
 
+import no.sesat.search.query.token.DeadTokenEvaluationEngineImpl;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
@@ -44,9 +45,11 @@
 import no.sesat.search.datamodel.generic.StringDataObject;
 import no.sesat.search.datamodel.navigation.NavigationDataObject;
 import no.sesat.search.datamodel.query.QueryDataObject;
+import no.sesat.search.query.Clause;
 import no.sesat.search.query.analyser.AnalysisRule;
 import no.sesat.search.query.analyser.AnalysisRuleFactory;
 import no.sesat.search.query.QueryStringContext;
+import no.sesat.search.query.token.EvaluationException;
 import no.sesat.search.query.token.TokenEvaluationEngine;
 import no.sesat.search.query.token.TokenEvaluationEngineImpl;
 import no.sesat.search.mode.command.SearchCommand;
@@ -60,6 +63,8 @@
 import no.sesat.search.query.parser.QueryParser;
 import no.sesat.search.query.parser.QueryParserImpl;
 import no.sesat.search.query.token.TokenEvaluationEngineContext;
+import no.sesat.search.query.token.TokenEvaluator;
+import no.sesat.search.query.token.TokenPredicate;
 import no.sesat.search.result.NavigationItem;
 import no.sesat.search.result.ResultItem;
 import no.sesat.search.result.ResultList;
@@ -155,24 +160,31 @@
             }
         };
 
-        final TokenEvaluationEngine.Context tokenEvalFactoryCxt =
-                ContextWrapper.wrap(
-                    TokenEvaluationEngine.Context.class,
-                    context,
-                    new QueryStringContext() {
-                        public String getQueryString() {
-                            return queryStr;
-                        }
-                    },
-                    new BaseContext(){
-                        public String getUniqueId(){
-                            return datamodel.getParameters().getUniqueId();
-                        }
-                    },
-                    siteCxt);
+        if(cxt.getSearchMode().isEvaluation()){
 
-        engine = new TokenEvaluationEngineImpl(tokenEvalFactoryCxt);
+            final TokenEvaluationEngine.Context tokenEvalFactoryCxt =
+                    ContextWrapper.wrap(
+                        TokenEvaluationEngine.Context.class,
+                        context,
+                        new QueryStringContext() {
+                            public String getQueryString() {
+                                return queryStr;
+                            }
+                        },
+                        new BaseContext(){
+                            public String getUniqueId(){
+                                return datamodel.getParameters().getUniqueId();
+                            }
+                        },
+                        siteCxt);
 
+            engine = new TokenEvaluationEngineImpl(tokenEvalFactoryCxt);
+
+        }else{
+            // use a dead token evaluation engine. false and stale evaluation 
so it is not cached.
+            engine = new DeadTokenEvaluationEngineImpl(queryStr, 
siteCxt.getSite());
+        }
+
         // queryStr parser
         final QueryParser parser = new QueryParserImpl(new 
AbstractQueryParserContext() {
             public TokenEvaluationEngine getTokenEvaluationEngine() {

Modified: trunk/generic.sesam/war/src/main/conf/modes.xml
===================================================================
--- trunk/generic.sesam/war/src/main/conf/modes.xml     2008-11-16 22:02:30 UTC 
(rev 6939)
+++ trunk/generic.sesam/war/src/main/conf/modes.xml     2008-11-16 22:09:16 UTC 
(rev 6940)
@@ -340,7 +340,7 @@
     <!-- General common modes -->
 
         <!-- Realtime Suggestions -->
-    <mode id="solrSuggestions" auto-broadening="false" inherit="default-mode">
+    <mode id="solrSuggestions" auto-broadening="false" evaluation="false" 
inherit="default-mode">
         <!-- Note the default-solr.1 default value in generic.sesam will not 
work outside of schibsted søk. -->
         <solr-command id="solrSuggestions"
                 result-fields="list_name,list_entry"

Modified: trunk/mojo/src/main/java/no/sesat/mojo/modes/Builder.java
===================================================================
--- trunk/mojo/src/main/java/no/sesat/mojo/modes/Builder.java   2008-11-16 
22:02:30 UTC (rev 6939)
+++ trunk/mojo/src/main/java/no/sesat/mojo/modes/Builder.java   2008-11-16 
22:09:16 UTC (rev 6940)
@@ -181,6 +181,7 @@
         // TODO replace with introspection
         mode.getAttributes().add(new ConfigAttribute("id"));
         mode.getAttributes().add(new ConfigAttribute("inherit"));
+        mode.getAttributes().add(new ConfigAttribute("evaluation"));
         mode.getAttributes().add(new ConfigAttribute("analysis"));
         mode.getAttributes().add(new ConfigAttribute("executor"));
         mode.getAttributes().add(new ConfigAttribute("auto-broadening"));

Added: 
trunk/query-api/src/main/java/no/sesat/search/query/token/DeadTokenEvaluationEngineImpl.java
===================================================================
--- 
trunk/query-api/src/main/java/no/sesat/search/query/token/DeadTokenEvaluationEngineImpl.java
                                (rev 0)
+++ 
trunk/query-api/src/main/java/no/sesat/search/query/token/DeadTokenEvaluationEngineImpl.java
        2008-11-16 22:09:16 UTC (rev 6940)
@@ -0,0 +1,79 @@
+/*
+ * Copyright (2008) Schibsted Søk AS
+ * This file is part of SESAT.
+ *
+ *   SESAT is free software: you can redistribute it and/or modify
+ *   it under the terms of the GNU Affero General Public License as published 
by
+ *   the Free Software Foundation, either version 3 of the License, or
+ *   (at your option) any later version.
+ *
+ *   SESAT is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU Affero General Public License for more details.
+ *
+ *   You should have received a copy of the GNU Affero General Public License
+ *   along with SESAT.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package no.sesat.search.query.token;
+
+import no.sesat.search.query.Clause;
+import no.sesat.search.query.Query;
+import no.sesat.search.site.Site;
+
+/** A dead evaluation engine. Used when evaluation is turned off.
+ * Rather than solely relying on the ALWAYS_FALSE_EVALUTOR
+ * evaluate(..) always throws a EvaluationRuntimeException that is treated as 
a false evaluation
+ *  but also prevents the evaluation for being cached by clauses (which are 
implemented within the flyweight pattern).
+ *
+ * @version $Id$
+ */
+public final class DeadTokenEvaluationEngineImpl implements 
TokenEvaluationEngine {
+
+    private final String queryStr;
+
+    private final Site site;
+
+    public DeadTokenEvaluationEngineImpl(final String queryStr, final Site 
site) {
+        this.queryStr = queryStr;
+        this.site = site;
+    }
+
+    private State state;
+
+    public TokenEvaluator getEvaluator(TokenPredicate token) throws 
EvaluationException {
+        return DEAD_EVALUATOR;
+    }
+
+    public String getQueryString() {
+        return queryStr;
+    }
+
+    public Site getSite() {
+        return site;
+    }
+
+    public boolean evaluate(TokenPredicate token) {
+        return false;
+    }
+
+    public boolean evaluateTerm(TokenPredicate predicate, String term) {
+        return false;
+    }
+
+    public boolean evaluateClause(TokenPredicate predicate, Clause clause) {
+        return false;
+    }
+
+    public boolean evaluateQuery(TokenPredicate predicate, Query query) {
+        return false;
+    }
+
+    public State getState() {
+        return state;
+    }
+
+    public void setState(State state) {
+        this.state = state;
+    }
+}


Property changes on: 
trunk/query-api/src/main/java/no/sesat/search/query/token/DeadTokenEvaluationEngineImpl.java
___________________________________________________________________
Name: svn:keywords
   + Id

Modified: 
trunk/query-api/src/main/java/no/sesat/search/query/token/TokenEvaluationEngine.java
===================================================================
--- 
trunk/query-api/src/main/java/no/sesat/search/query/token/TokenEvaluationEngine.java
        2008-11-16 22:02:30 UTC (rev 6939)
+++ 
trunk/query-api/src/main/java/no/sesat/search/query/token/TokenEvaluationEngine.java
        2008-11-16 22:09:16 UTC (rev 6940)
@@ -78,6 +78,19 @@
     };
 
     /**
+     * Evaluator that will throws an EvaluationException under all 
circumstances.
+     */
+    static final TokenEvaluator DEAD_EVALUATOR = new TokenEvaluator() {
+        public boolean evaluateToken(final TokenPredicate token, final String 
term, final String query) {
+            throw new EvaluationRuntimeException(
+                    new EvaluationException("DEAD_EVALUATOR", null));
+        }
+        public boolean isQueryDependant(final TokenPredicate predicate) {
+            return false;
+        }
+    };
+
+    /**
      * Holder for evaluation state during the engine's evaluation.
      * Evaluation on any term, clause, or query requires state of the current 
term and query,
      *  and of the already matched known and possible predicates.

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

Reply via email to