Author: ssmiweve
Date: 2009-09-25 22:08:56 +0200 (Fri, 25 Sep 2009)
New Revision: 7293
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/VeryFastTokenEvaluator.java
Log:
performance smart: remember from initialisation if this evaluator will ever be
used. allows the otherwise expensive isReponsible method to quickly return
false in any instalation where FAST query evaluation against is not configured.
(this is due to the FAST_LIST is inappropriately encapsulated within the
VeryFastTokenEvaluator.java).
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
2009-09-25 19:55:00 UTC (rev 7292)
+++
branches/2.18/generic.sesam/query-evaluation/src/main/java/no/sesat/search/query/token/FastQueryMatchingEvaluatorFactory.java
2009-09-25 20:08:56 UTC (rev 7293)
@@ -1,4 +1,4 @@
-/* Copyright (2005-2008) Schibsted ASA
+/* Copyright (2005-2009) Schibsted ASA
* This file is part of SESAT.
*
* SESAT is free software: you can redistribute it and/or modify
@@ -18,9 +18,6 @@
import javax.xml.parsers.ParserConfigurationException;
import no.sesat.commons.ioc.ContextWrapper;
-import no.sesat.search.site.Site;
-import no.sesat.search.site.SiteContext;
-
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
@@ -53,6 +50,10 @@
// Attributes -----------------------------------------------------
+ /** Because LIST_NAMES is encapsulated inside the VeryFastTokenEvaluator
+ * we keep a hint here in knowing if isReponsible() can simply and quickly
always return false.
+ */
+ private final boolean everApplicable;
private final Future fastEvaluatorCreator;
private VeryFastTokenEvaluator fastEvaluator;
@@ -63,7 +64,7 @@
super(cxt);
try {
- VeryFastTokenEvaluator.initImpl(cxt);
+ everApplicable = VeryFastTokenEvaluator.initImpl(cxt);
}catch (ParserConfigurationException ex) {
throw new
SiteKeyedFactoryInstantiationException(ERR_FAILED_CONSTRUCTING_FAST_EVALUATOR,
ex);
@@ -72,6 +73,7 @@
fastEvaluatorCreator = EXECUTOR.submit(new FastEvaluatorCreator(cxt));
}
+ @Override
public TokenEvaluator getEvaluator(final TokenPredicate token) throws
EvaluationException{
final Context cxt = getContext();
@@ -98,7 +100,7 @@
try {
- return getFastEvaluator().isResponsibleFor(token);
+ return everApplicable &&
getFastEvaluator().isResponsibleFor(token);
}catch (EvaluationException ex) {
LOG.error("failed using VeryFastTokenEvaluator", ex);
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
2009-09-25 19:55:00 UTC (rev 7292)
+++
branches/2.18/generic.sesam/query-evaluation/src/main/java/no/sesat/search/query/token/VeryFastTokenEvaluator.java
2009-09-25 20:08:56 UTC (rev 7293)
@@ -1,4 +1,4 @@
-/* Copyright (2005-2008) Schibsted ASA
+/* Copyright (2005-2009) Schibsted ASA
* This file is part of SESAT.
*
* SESAT is free software: you can redistribute it and/or modify
@@ -40,15 +40,12 @@
import no.sesat.commons.ioc.ContextWrapper;
import no.sesat.search.site.config.SiteConfiguration;
import no.sesat.search.site.config.DocumentLoader;
-
import no.sesat.search.http.HTTPClient;
import no.sesat.search.query.token.AbstractEvaluatorFactory.Context;
import static no.sesat.search.query.parser.AbstractQueryParser.SKIP_REGEX;
import static no.sesat.search.query.parser.AbstractQueryParser.OPERATOR_REGEX;
import no.sesat.search.site.Site;
import no.sesat.search.site.SiteContext;
-
-
import org.apache.log4j.Logger;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
@@ -139,6 +136,7 @@
// Public --------------------------------------------------------
+ @Override
public boolean evaluateToken(final TokenPredicate token, final String
term, final String query) {
boolean evaluation = false;
@@ -180,6 +178,7 @@
return evaluation;
}
+ @Override
public Set<String> getMatchValues(final TokenPredicate token, final String
term) {
final Set<String> values;
@@ -214,6 +213,7 @@
return Collections.unmodifiableSet(values);
}
+ @Override
public boolean isQueryDependant(final TokenPredicate predicate) {
return predicate.name().startsWith(EXACT_PREFIX.toUpperCase());
}
@@ -239,7 +239,7 @@
}
}
- static void initImpl(final Context cxt) throws
ParserConfigurationException {
+ static boolean initImpl(final Context cxt) throws
ParserConfigurationException {
final Site site = cxt.getSite();
final Site parent = site.getParent();
@@ -259,6 +259,7 @@
initImpl(ContextWrapper.wrap(
AbstractEvaluatorFactory.Context.class,
new SiteContext(){
+ @Override
public Site getSite(){
return parent;
}
@@ -318,8 +319,6 @@
Arrays.sort(listNameArr, null);
listNames.put(token, listNameArr);
}
-
-
}
}
LOG.info("Parsing " + VERYFAST_EVALUATOR_XMLFILE + "
finished");
@@ -327,6 +326,25 @@
LIST_NAMES_LOCK.writeLock().unlock();
}
}
+ try{
+ LIST_NAMES_LOCK.readLock().lock();
+
+ Site s = site;
+ boolean evaluatorUsedAnywhere = false;
+
+ while(!evaluatorUsedAnywhere && null != s){
+
+ evaluatorUsedAnywhere |= 0 < LIST_NAMES.get(s).values().size();
+ if(!evaluatorUsedAnywhere){
+ // prepare to go to parent
+ s = s.getParent();
+ }
+ }
+ return evaluatorUsedAnywhere;
+
+ }finally{
+ LIST_NAMES_LOCK.readLock().unlock();
+ }
}
/**
_______________________________________________
Kernel-commits mailing list
[email protected]
http://sesat.no/mailman/listinfo/kernel-commits