こんにちは、lucene を初めて使用します。lucene を使用してインデックスを作成しました。ファイル名とファイルの内容の 2 つのフィールドを lucene インデックスに追加しています。しかし、インデックスから検索しているとき、クエリワードの出現と、クエリワードを含むファイル名を取得できます。インデックスを作成したファイルの内容を表示できません
Directory directory = FSDirectory.open(indexDir);
IndexSearcher searcher = new IndexSearcher(directory,true);
QueryParser parser =
new QueryParser(Version.LUCENE_30,"contents", new SimpleAnalyzer());
Query query = parser.parse(queryStr);
query.setBoost((float)1.5);
TopDocs topDocs = searcher.search(query, maxHits);
ScoreDoc[] hits = topDocs.scoreDocs;
arr= new String[hits.length];
for ( i = 0; i <hits.length; i++) {
int docId = hits[i].doc;
Document d = searcher.doc(docId);
arr[i]=d.get("filename");
}
インデックスを読み取るためにこのコードを使用しています。