Lucene 4.3.0 の使用
ルセンの新機能。現在選択されているドキュメントのようなドキュメントをさらに取得したい。私の調査によると、古いバージョンの Lucene には MoreLikeThis がありました (これは、私が望むものと同様の動作です)。
オプションをテストするために、いくつかのおもちゃのコードをまとめました。インデックス作成が完了し、インデックス作成に TermVector が含まれています。
コードの抜粋
QueryParser parser = new QueryParser(Version.LUCENE_CURRENT, "body", this.analyzer);
Query query = null ;
try {
query = parser.parse(searchterm);
ScoreDoc[] hits = isearcher.search(query, null, 1000).scoreDocs;
simpleresult = simpleresult + "HITS = " + hits.length + "\n";
IndexReader ir = isearcher.getIndexReader() ; //2013-06-09 testing
simpleresult = simpleresult + "Total Indexed Num Docs = " + ir.numDocs() + "\n" ;
//Loop through results and construct simple string representation
for (int i = 0; i < hits.length; i++) {
Document hitdoc = isearcher.doc(hits[i].doc);
float docscore = hits[i].score ;
simpleresult = simpleresult + "=======" + (i+1) + "=======\n" ;
simpleresult = simpleresult + "DOCDBID: " + hitdoc.get("dbid") + "\n" ;
simpleresult = simpleresult + "Score: " + docscore + "\n" ;
simpleresult = simpleresult + "File: " + hitdoc.get("filename") + "\n" ;
simpleresult = simpleresult + hitdoc.get("body") ;
simpleresult = simpleresult + "\n--------META--------\n" ;
simpleresult = simpleresult + hitdoc.get("meta") ;
simpleresult = simpleresult + "==============\n" ;
//TESTING 2013-06-09
//Trying to mimic similar documents
//Feed the text contents of the current document back into nother query?????
query = parser.parse(hitdoc.get("body"));
ScoreDoc[] simhits = isearcher.search(query, null, 1000).scoreDocs;
TopDocs top = isearcher.search(query, 10);
simpleresult = simpleresult + "Similar Hits = " + simhits.length + "\n";
simpleresult = simpleresult + "Top Hits MaxScore= " + top.getMaxScore() + "\n"; //why does this score differ from the above scores???????
simpleresult = simpleresult + "Top Hits = " + top.totalHits + "\n";
}
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
this.close() ;
繰り返しますが、これはおもちゃの例からの抜粋なので、Lucene をよりよく学ぶことができます。基本的には単純なクエリを実行し、各結果を (GUI で) 表示し、次に各ドキュメントを使用して再クエリを試行し、類似したドキュメントを参照して MoreLikeThis を模倣します。私がやろうとしているのは、ドキュメントに似たドキュメントを取得することです。私
ty の例は Lucene 4+ でこれを行う適切な方法ですか?