apache lucene によって作成されたインデックスを使用してキーワードを検索しています。指定されたキーワードを含むファイルの名前が返されます。今、lucene search によって返されたファイルでのみ検索を絞り込みたいと思います。apache lucene を使用して検索を絞り込むにはどうすればよいですか。次のコードを使用しています。
try
{
File indexDir=new File("path upto the index directory");
Directory directory = FSDirectory.open(indexDir);
IndexSearcher searcher = new IndexSearcher(directory, true);
QueryParser parser = new QueryParser(Version.LUCENE_36, "contents", new SimpleAnalyzer(Version.LUCENE_36));
Query query = parser.parse(qu);
query.setBoost((float) 1.5);
TopDocs topDocs = searcher.search(query, maxhits);
ScoreDoc[] hits = topDocs.scoreDocs;
len = hits.length;
int docId = 0;
Document d;
for ( i = 0; i<len; i++) {
docId = hits[i].doc;
d = searcher.doc(docId);
filename= d.get(("filename"));
}
}
catch(Exception ex){ex.printStackTrace();}
内容とファイル名として使用して、lucene インデックスにドキュメントを追加しました。