IndexSearcher searcher = null;
try {
searcher = new IndexSearcher(indexFilePath);
Term productIdTerm = new Term("product_id", product.getProductId());
org.apache.lucene.search.Query query = new TermQuery(productIdTerm);
Hits hits = searcher.search(query);
// should be exactly 1 hit
if (hits.length() != 1) {
throw new CatalogException("Product: ["
+ product.getProductId()
+ "] is not unique in the catalog! Num Hits: ["
+ hits.length() + "]");
}
Document productDoc = hits.doc(0);
CompleteProduct prod = toCompleteProduct(productDoc, false, true);
return prod.getMetadata();
} catch (IOException e) {
LOG.log(Level.WARNING,
"IOException when opening index directory: ["