Author: ssmiweve
Date: 2008-12-23 15:11:56 +0100 (Tue, 23 Dec 2008)
New Revision: 7114
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/SolrTokenEvaluator.java
branches/2.18/generic.sesam/query-evaluation/src/main/java/no/sesat/search/query/token/VeryFastTokenEvaluator.java
Log:
instead of lazy initialisation (which didn't work)
use some optimisation to know if the restful request is worth making
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-23 09:52:44 UTC (rev 7113)
+++
branches/2.18/generic.sesam/query-evaluation/src/main/java/no/sesat/search/query/token/SolrEvaluatorFactory.java
2008-12-23 14:11:56 UTC (rev 7114)
@@ -194,6 +194,28 @@
return listNames;
}
+ boolean responsible(){
+
+ boolean responsible = false;
+ try{
+ LIST_NAMES_LOCK.readLock().lock();
+ Site loopSite = this.site;
+
+ while(null != loopSite){
+
+ // find listnames used for this token predicate
+ responsible = !LIST_NAMES.get(loopSite).isEmpty();
+ if(responsible){ break; }
+
+ // prepare to go to parent
+ loopSite = loopSite.getParent();
+ }
+ }finally{
+ LIST_NAMES_LOCK.readLock().unlock();
+ }
+ return responsible;
+ }
+
// private -----------------------------------------------------
private static void init(final Context cxt) throws
ParserConfigurationException{
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-23 09:52:44 UTC (rev 7113)
+++
branches/2.18/generic.sesam/query-evaluation/src/main/java/no/sesat/search/query/token/SolrTokenEvaluator.java
2008-12-23 14:11:56 UTC (rev 7114)
@@ -78,18 +78,22 @@
// Constructors --------------------------------------------------
- /**
+ /** Only possible constructor.
*
- * @param cxt
- * @param factory
- * @throws EvaluationException
+ * @param cxt the required context
+ * @param factory the factory constructing this.
+ * @throws EvaluationException if the evaluation, request to the solr
index, fails.
*/
SolrTokenEvaluator(final Context cxt, final SolrEvaluatorFactory factory)
throws EvaluationException{
context = cxt;
this.factory = factory;
- analysisResult = query(cleanString(context.getQueryString()));
+ // the responsible() method checks if we are responsible for any
tokenPredicate at all.
+ // if we are not then the restful request in query(..) is a waste of
time and resource.
+ analysisResult = factory.responsible()
+ ? query(cleanString(context.getQueryString()))
+ : Collections.<String, List<TokenMatch>>emptyMap();
}
// Public --------------------------------------------------------
@@ -98,36 +102,40 @@
public boolean evaluateToken(final TokenPredicate token, final String
term, final String query) {
boolean evaluation = false;
- final String[] listnames = factory.getListNames(token);
- if(null != listnames){
- for(int i = 0; !evaluation && i < listnames.length; ++i){
+ if(!analysisResult.isEmpty()){
- final String listname = listnames[i];
+ final String[] listnames = factory.getListNames(token);
- if (analysisResult.containsKey(listname)) {
- if (term == null) {
- evaluation = true;
- } else {
+ if(null != listnames){
+ for(int i = 0; !evaluation && i < listnames.length; ++i){
- // HACK since DefaultOperatorClause wraps its children
in parenthesis
- final String hackTerm =
cleanString(term.replaceAll("\\(|\\)",""));
+ final String listname = listnames[i];
- for (TokenMatch occurance :
analysisResult.get(listname)) {
+ if (analysisResult.containsKey(listname)) {
+ if (term == null) {
+ evaluation = true;
+ } else {
- final Matcher m = occurance.getMatcher(hackTerm);
- evaluation = m.find() && m.start() == 0 && m.end()
== hackTerm.length();
+ // HACK since DefaultOperatorClause wraps its
children in parenthesis
+ final String hackTerm =
cleanString(term.replaceAll("\\(|\\)",""));
- if (evaluation) {
- break;
+ for (TokenMatch occurance :
analysisResult.get(listname)) {
+
+ final Matcher m =
occurance.getMatcher(hackTerm);
+ evaluation = m.find() && m.start() == 0 &&
m.end() == hackTerm.length();
+
+ if (evaluation) {
+ break;
+ }
}
}
+
}
-
}
+ }else{
+ LOG.info(context.getSite() + " does not define lists behind
the token predicate " + token);
}
- }else{
- LOG.info(context.getSite() + " does not define lists behind the
token predicate " + token);
}
return evaluation;
}
@@ -142,28 +150,35 @@
*/
public Set<String> getMatchValues(final TokenPredicate token, final String
term) {
- final Set<String> values = new HashSet<String>();
+ final Set<String> values;
- final String[] listnames = factory.getListNames(token);
- if(null != listnames){
- for(int i = 0; i < listnames.length; i++){
- final String listname = listnames[i];
+ if(!analysisResult.isEmpty()){
- if (analysisResult.containsKey(listname)) {
+ values = new HashSet<String>();
- // HACK since DefaultOperatorClause wraps its children in
parenthesis
- final String hackTerm =
cleanString(term.replaceAll("\\(|\\)",""));
+ final String[] listnames = factory.getListNames(token);
+ if(null != listnames){
+ for(int i = 0; i < listnames.length; i++){
+ final String listname = listnames[i];
- for (TokenMatch occurance : analysisResult.get(listname)) {
+ if (analysisResult.containsKey(listname)) {
- final Matcher m = occurance.getMatcher(hackTerm);
+ // HACK since DefaultOperatorClause wraps its children
in parenthesis
+ final String hackTerm =
cleanString(term.replaceAll("\\(|\\)",""));
- if (m.find() && m.start() == 0 && m.end() ==
hackTerm.length()) {
- values.add(occurance.getValue());
+ for (TokenMatch occurance :
analysisResult.get(listname)) {
+
+ final Matcher m = occurance.getMatcher(hackTerm);
+
+ if (m.find() && m.start() == 0 && m.end() ==
hackTerm.length()) {
+ values.add(occurance.getValue());
+ }
}
}
}
}
+ }else{
+ values = Collections.<String>emptySet();
}
return Collections.unmodifiableSet(values);
}
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-23 09:52:44 UTC (rev 7113)
+++
branches/2.18/generic.sesam/query-evaluation/src/main/java/no/sesat/search/query/token/VeryFastTokenEvaluator.java
2008-12-23 14:11:56 UTC (rev 7114)
@@ -58,7 +58,7 @@
/**
* VeryFastTokenEvaluator is part of no.sesat.search.query.
*
- * @todo sesat-ise. bring out to generic.sesam. make CGI_PATH easily
configurable. configurable cache settings.
+ * @todo make CGI_PATH easily configurable. configurable cache settings.
*
*
*
@@ -89,8 +89,8 @@
/** General properties to regular expressions configured. **/
private static final int REG_EXP_OPTIONS = Pattern.CASE_INSENSITIVE |
Pattern.UNICODE_CASE;
- // TODO this will leak when sites are redeploy without Sesat being
restarted.
- // todo move deserialisation & this map to
FastQueryMatchingEvaluatorFactory
+ // @todo this will leak when sites are redeploy without Sesat being
restarted.
+ // @todo move deserialisation & this map to
FastQueryMatchingEvaluatorFactory
private static final Map<Site,Map<TokenPredicate,String[]>> LIST_NAMES
= new HashMap<Site,Map<TokenPredicate,String[]>>();
private static final ReentrantReadWriteLock LIST_NAMES_LOCK = new
ReentrantReadWriteLock();
@@ -115,10 +115,12 @@
// Constructors -------------------------------------------------
- /**
- * Search fast and initialize analysis result.
- * @param cxt
- */
+ /** Only possible constructor.
+ *
+ * @param cxt the required context
+ * @param factory the factory constructing this.
+ * @throws EvaluationException if the evaluation, request to the fast
query matching index, fails.
+ **/
VeryFastTokenEvaluator(final Context cxt) throws EvaluationException{
// pre-condition check
@@ -128,7 +130,11 @@
init();
- analysisResult = queryFast(cleanString(context.getQueryString()));
+ // the responsible() method checks if we are responsible for any
tokenPredicate at all.
+ // if we are not then the restful request in query(..) is a waste of
time and resource.
+ analysisResult = responsible()
+ ? queryFast(cleanString(context.getQueryString()))
+ : Collections.<String, List<TokenMatch>>emptyMap();
}
// Public --------------------------------------------------------
@@ -136,64 +142,74 @@
public boolean evaluateToken(final TokenPredicate token, final String
term, final String query) {
boolean evaluation = false;
- final String[] listnames = getListNames(token);
- if(null != listnames){
- for(int i = 0; !evaluation && i < listnames.length; ++i){
+ if(!analysisResult.isEmpty()){
- final String listname = listnames[i];
+ final String[] listnames = getListNames(token);
- if (analysisResult.containsKey(listname)) {
- if (term == null) {
- evaluation = true;
- } else {
+ if(null != listnames){
+ for(int i = 0; !evaluation && i < listnames.length; ++i){
- // HACK since DefaultOperatorClause wraps its children
in parenthesis
- final String hackTerm =
cleanString(term.replaceAll("\\(|\\)",""));
+ final String listname = listnames[i];
- for (TokenMatch occurance :
analysisResult.get(listname)) {
+ if (analysisResult.containsKey(listname)) {
+ if (term == null) {
+ evaluation = true;
+ } else {
- final Matcher m = occurance.getMatcher(hackTerm);
- evaluation = m.find() && m.start() == 0 && m.end()
== hackTerm.length();
+ // HACK since DefaultOperatorClause wraps its
children in parenthesis
+ final String hackTerm =
cleanString(term.replaceAll("\\(|\\)",""));
- if (evaluation) {
- break;
+ for (TokenMatch occurance :
analysisResult.get(listname)) {
+
+ final Matcher m =
occurance.getMatcher(hackTerm);
+ evaluation = m.find() && m.start() == 0 &&
m.end() == hackTerm.length();
+
+ if (evaluation) {
+ break;
+ }
}
}
+
}
-
}
+ }else{
+ LOG.info(site + " does not define lists behind the token
predicate " + token);
}
- }else{
- LOG.info(site + " does not define lists behind the token predicate
" + token);
}
return evaluation;
}
public Set<String> getMatchValues(final TokenPredicate token, final String
term) {
- final Set<String> values = new HashSet<String>();
+ final Set<String> values;
- final String[] listnames = getListNames(token);
- if(null != listnames){
- for(int i = 0; i < listnames.length; i++){
- final String listname = listnames[i];
+ if(!analysisResult.isEmpty()){
+ values = new HashSet<String>();
- if (analysisResult.containsKey(listname)) {
+ final String[] listnames = getListNames(token);
+ if(null != listnames){
+ for(int i = 0; i < listnames.length; i++){
+ final String listname = listnames[i];
- // HACK since DefaultOperatorClause wraps its children in
parenthesis
- final String hackTerm =
cleanString(term.replaceAll("\\(|\\)",""));
+ if (analysisResult.containsKey(listname)) {
- for (TokenMatch occurance : analysisResult.get(listname)) {
+ // HACK since DefaultOperatorClause wraps its children
in parenthesis
+ final String hackTerm =
cleanString(term.replaceAll("\\(|\\)",""));
- final Matcher m = occurance.getMatcher(hackTerm);
+ for (TokenMatch occurance :
analysisResult.get(listname)) {
- if (m.find() && m.start() == 0 && m.end() ==
hackTerm.length()) {
- values.add(occurance.getValue());
+ final Matcher m = occurance.getMatcher(hackTerm);
+
+ if (m.find() && m.start() == 0 && m.end() ==
hackTerm.length()) {
+ values.add(occurance.getValue());
+ }
}
}
}
}
+ }else{
+ values = Collections.<String>emptySet();
}
return Collections.unmodifiableSet(values);
}
@@ -232,7 +248,7 @@
try{
LIST_NAMES_LOCK.readLock().lock();
- // initialise the parent site's configuration
+ // initialise the parent loopSite's configuration
parentUninitialised = (null != parent && null ==
LIST_NAMES.get(parent));
}finally{
@@ -256,10 +272,10 @@
LIST_NAMES_LOCK.writeLock().lock();
- // create map entry for this site
+ // create map entry for this loopSite
LIST_NAMES.put(site, new
HashMap<TokenPredicate,String[]>());
- // initialise this site's configuration
+ // initialise this loopSite's configuration
final DocumentBuilderFactory factory =
DocumentBuilderFactory.newInstance();
final DocumentBuilder builder =
factory.newDocumentBuilder();
final DocumentLoader loader = cxt.newDocumentLoader(cxt,
VERYFAST_EVALUATOR_XMLFILE, builder);
@@ -475,8 +491,6 @@
private String[] getListNames(final TokenPredicate token){
-
-
String[] listNames = null;
try{
LIST_NAMES_LOCK.readLock().lock();
@@ -509,5 +523,27 @@
.replaceAll(" +", " "); // normalise
}
+ private boolean responsible(){
+
+ boolean responsible = false;
+ try{
+ LIST_NAMES_LOCK.readLock().lock();
+ Site loopSite = this.site;
+
+ while(null != loopSite){
+
+ // find listnames used for this token predicate
+ responsible = !LIST_NAMES.get(loopSite).isEmpty();
+ if(responsible){ break; }
+
+ // prepare to go to parent
+ loopSite = loopSite.getParent();
+ }
+ }finally{
+ LIST_NAMES_LOCK.readLock().unlock();
+ }
+ return responsible;
+ }
+
// Inner classes -------------------------------------------------
}
_______________________________________________
Kernel-commits mailing list
[email protected]
http://sesat.no/mailman/listinfo/kernel-commits