Hi all,
Basically, I simply want to do many searches on a given lucene index.
Therefore, I made a class Data with final 'analyzer', 'reader', 'searcher' and 'parser' fields, (all properly initialized in the constructor). The class also provides a 'search' method to search the index. This is all shown in the code below.
The problem is however that memory gradually becomes filled after many calls to 'search' (with different queries). I did not check what happens when always the same query is used. I looked around already for possible answers, and it seems to be best practice to keep the searcher etc open across different searches, so I guess that is not the problem. Any other ideas?
Thanks, Joachim.
(example) code:
public class Data {
private final Analyzer analyzer;
private final IndexReader reader;
private final IndexSearcher searcher;
private final QueryParser parser;
public Data(String indexPath, Analyzer analyzer) throws IOException {
this.analyzer = analyzer;
Directory directory = FSDirectory.open(indexPath);
reader = new FilterIndexReader(IndexReader.open(directory, true));
directory.close();
searcher = new IndexSearcher(reader);
parser = new QueryParser(Version.LUCENE_CURRENT,
FieldName.CONTENT, analyzer);
}
public TopDocs search(String line, Integer maxHits) throws ... {
Query query = parser.parse(QueryParser.escape(line));
return searcher.search(query, maxHits);
}
}