protected void preloadTerm(final IndexSearcher searcher, final TermSubQueryBuilder termSubQueryBuilder,
final String field, final Term term, final boolean testForHits,
final TermQueryCache cache) {
try {
final TermSubQueryFactory termSubQueryFactory
= termSubQueryBuilder.termToFactory(field, term, ConstantFieldBoost.NORM_BOOST);
if (testForHits && (termSubQueryFactory != null) && (!termSubQueryFactory.isNeverMatchQuery())) {
final Query query = termSubQueryFactory
.createQuery(ConstantFieldBoost.NORM_BOOST, 0.01f, new LuceneTermQueryBuilder());
final TopDocs topDocs = searcher.search(query, 1);
if (topDocs.totalHits < 1) {
cache.put(new CacheKey(field, term),
new TermQueryCacheValue(NeverMatchQueryFactory.FACTORY, PRMSQuery.NEVER_MATCH_PRMS_QUERY));
}
}
} catch (final IOException e) {
LOG.error("Error preloading term " + term.toString(), e);
}
}