throw new IllegalArgumentException("textAnalyzer must not be null");
if (queryAnalyzer == null)
throw new IllegalArgumentException("queryAnalyzer must not be null");
if (DEFAULT_CAPACITY <= 0) { // cache disabled?
MemoryIndex index = new MemoryIndex();
index.addField(FIELD_NAME, text, textAnalyzer);
return index.search(parse(query, queryAnalyzer));
}
Object key = Pool.createHashKeys(new Object[] {text, query, textAnalyzer, queryAnalyzer});
Float score = (Float) entries.get(key); // hit/miss ratio is app specific
// Float score = null;
if (score == null) { // cache miss
Object qkey = Pool.createHashKeys(new Object[] {query, queryAnalyzer});
Query luceneQuery = (Query) entries.get(qkey); // typically good hit/miss ratio
// Query luceneQuery = null;
if (luceneQuery == null) { // cache miss
luceneQuery = parse(query, queryAnalyzer);
entries.put(qkey, luceneQuery);
}
Object tkey = Pool.createHashKeys(new Object[] {text, textAnalyzer, null});
MemoryIndex index = (MemoryIndex) entries.get(tkey);
// MemoryIndex index = null;
if (index == null) { // cache miss
index = new MemoryIndex();
index.addField(FIELD_NAME, text, textAnalyzer);
entries.put(tkey, index);
}
/*
* TODO: Reduce the following lock scope, minimizing lock
* contention? Though not publicly documented anywhere, with the
* current impl, a MemoryIndex instance can actually safely have
* multiple concurrent readers, but I'm not sure that's also true
* for the luceneQuery instance. For the moment better safe than
* sorry...
*/
synchronized (luceneQuery) {
score = new Float(index.search(luceneQuery));
}
entries.put(key, score);
}
return score.floatValue();