Author: ssmiweve
Date: 2008-11-24 23:35:43 +0100 (Mon, 24 Nov 2008)
New Revision: 6978
Modified:
branches/2.18/generic.sesam/query-evaluation/src/main/java/no/sesat/search/query/token/VeryFastTokenEvaluator.java
Log:
clean up, + performance
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-11-24 22:25:35 UTC (rev 6977)
+++
branches/2.18/generic.sesam/query-evaluation/src/main/java/no/sesat/search/query/token/VeryFastTokenEvaluator.java
2008-11-24 22:35:43 UTC (rev 6978)
@@ -103,8 +103,8 @@
// Attributes ----------------------------------------------------
- private final HTTPClient httpClient;
private final Context context;
+ private final Site site;
private final Map<String, List<TokenMatch>> analysisResult;
// Static --------------------------------------------------------
@@ -124,23 +124,13 @@
// pre-condition check
context = cxt;
+ site = cxt.getSite();
- final Properties props = SiteConfiguration.instanceOf(
-
ContextWrapper.wrap(SiteConfiguration.Context.class,context)).getProperties();
- final String host = props.getProperty(TOKEN_HOST_PROPERTY);
- final int port =
Integer.parseInt(props.getProperty(TOKEN_PORT_PROPERTY));
+ init();
- if(0 < port){
- httpClient = HTTPClient.instance(host, port);
+ // Remove whitespace (except space itself) and operator characters.
+ analysisResult = queryFast(cleanString(context.getQueryString()));
- init();
-
- // Remove whitespace (except space itself) and operator characters.
- analysisResult = queryFast(cleanString(context.getQueryString()));
- }else{
- httpClient = null;
- analysisResult = Collections.emptyMap();
- }
}
// Public --------------------------------------------------------
@@ -191,7 +181,7 @@
}
}
}else{
- LOG.info(context.getSite() + " does not define lists behind the
token predicate " + token);
+ LOG.info(site + " does not define lists behind the token predicate
" + token);
}
return evaluation;
}
@@ -373,45 +363,56 @@
String url = null;
try {
- final String token =
URLEncoder.encode(query.replaceAll("\"", ""), "utf-8");
- url = CGI_PATH + token;
+ final Properties props = SiteConfiguration.instanceOf(
+
ContextWrapper.wrap(SiteConfiguration.Context.class,context)).getProperties();
- final Document doc = httpClient.getXmlDocument(url);
+ final String host = props.getProperty(TOKEN_HOST_PROPERTY);
+ final int port =
Integer.parseInt(props.getProperty(TOKEN_PORT_PROPERTY));
+ if(0 < port){
- NodeList l = doc.getElementsByTagName("QUERYTRANSFORMS");
- final Element e = (Element) l.item(0);
+ final HTTPClient httpClient =
HTTPClient.instance(host, port);
- l = e.getElementsByTagName("QUERYTRANSFORM");
+ final String token =
URLEncoder.encode(query.replaceAll("\"", ""), "utf-8");
- for (int i = 0; i < l.getLength(); ++i) {
+ url = CGI_PATH + token;
- final Element trans = (Element) l.item(i);
- final String name = trans.getAttribute("NAME");
- final String custom = trans.getAttribute("CUSTOM");
- final String exactname = 0 <=
name.indexOf(LIST_PREFIX) && 0 < name.indexOf(LIST_SUFFIX)
- ? LIST_PREFIX + EXACT_PREFIX
- + name.substring(name.indexOf('_') + 1,
name.indexOf("QM"))
- + LIST_SUFFIX
- : null;
+ final Document doc = httpClient.getXmlDocument(url);
- if(custom.matches(".+->.*") && usesListName(name,
exactname)){
+ NodeList l =
doc.getElementsByTagName("QUERYTRANSFORMS");
+ final Element e = (Element) l.item(0);
- final String match = (custom.indexOf("->") >0
- ? custom.substring(0, custom.indexOf("->"))
- : custom)
- // remove words made solely of characters
that the parser considers whitespace
- .replaceAll("\\b" + SKIP_REGEX + "+\\b", "
");
+ l = e.getElementsByTagName("QUERYTRANSFORM");
- final String value = custom.indexOf("->") > 0
- ? custom.substring(custom.indexOf("->") +
2)
+ for (int i = 0; i < l.getLength(); ++i) {
+
+ final Element trans = (Element) l.item(i);
+ final String name = trans.getAttribute("NAME");
+ final String custom = trans.getAttribute("CUSTOM");
+ final String exactname = 0 <=
name.indexOf(LIST_PREFIX) && 0 < name.indexOf(LIST_SUFFIX)
+ ? LIST_PREFIX + EXACT_PREFIX
+ + name.substring(name.indexOf('_') +
1, name.indexOf("QM"))
+ + LIST_SUFFIX
: null;
- addMatch(name, match, value,query, result);
+ if(custom.matches(".+->.*") && usesListName(name,
exactname)){
- if (match.equalsIgnoreCase(query.trim())) {
+ final String match = (custom.indexOf("->") >0
+ ? custom.substring(0,
custom.indexOf("->"))
+ : custom)
+ // remove words made solely of
characters that the parser considers whitespace
+ .replaceAll("\\b" + SKIP_REGEX +
"+\\b", " ");
- addMatch(exactname, match, value, query,
result);
+ final String value = custom.indexOf("->") > 0
+ ?
custom.substring(custom.indexOf("->") + 2)
+ : null;
+
+ addMatch(name, match, value,query, result);
+
+ if (match.equalsIgnoreCase(query.trim())) {
+
+ addMatch(exactname, match, value, query,
result);
+ }
}
}
}
@@ -507,7 +508,7 @@
String[] listNames = null;
try{
LIST_NAMES_LOCK.readLock().lock();
- Site site = context.getSite();
+ Site site = this.site;
while(null == listNames && null != site){
_______________________________________________
Kernel-commits mailing list
[email protected]
http://sesat.no/mailman/listinfo/kernel-commits