我对用固定住房进行记分计算存在问题。 为了将每份文件的分数换成指数,我利用了缩略语来改变文件的推动。 然后,我设立了搜查处,但结果没有根据提升变化。 看来,它完全没有做固定工作。 请检查我的以下法典:
@Test
public void testNormsDocBoost() throws Exception {
Directory dir = new RAMDirectory();
IndexWriter writer = new IndexWriter(dir, new StandardAnalyzer(Version.LUCENE_CURRENT), true,
IndexWriter.MaxFieldLength.LIMITED);
Document doc1 = new Document();
Field f1 = new Field("contents", "common1", Field.Store.YES, Field.Index.ANALYZED);
doc1.add(f1);
doc1.setBoost(100);
writer.addDocument(doc1);
Document doc2 = new Document();
Field f2 = new Field("contents", "common2", Field.Store.YES, Field.Index.ANALYZED);
doc2.add(f2);
doc2.setBoost(200);
writer.addDocument(doc2);
Document doc3 = new Document();
Field f3 = new Field("contents", "common3", Field.Store.YES, Field.Index.ANALYZED);
doc3.add(f3);
doc3.setBoost(300);
writer.addDocument(doc3);
writer.close();
IndexReader reader = IndexReader.open(dir);
IndexSearcher searcher = new IndexSearcher(reader);
TopDocs docs = searcher.search(new PrefixQuery(new Term("contents", "common")), 10);
for (ScoreDoc doc : docs.scoreDocs) {
System.out.println("docid : " + doc.doc + " score : " + doc.score + " "
+ searcher.doc(doc.doc).get("contents"));
}
}
产出如下:
docid : 0 score : 1.0 common1
docid : 1 score : 1.0 common2
docid : 2 score : 1.0 common3