Lucene: how to get the score of a document

前端 未结 3 1945
太阳男子
太阳男子 2020-12-31 22:41

I want to output the score of documents. The code I write for this is that:

IndexReader reader = IndexReader.open(FSDirectory.open(indexDir));
IndexSearcher          


        
相关标签:
3条回答
  • 2020-12-31 22:57

    additional to daulets answere you have to enable the scoring in the indexSearcher:

    ...
    searcher.setDefaultFieldSortScoring(true, true);
    ...
    

    I think thats what you meant remy, but that way it should be clearer :)

    0 讨论(0)
  • 2020-12-31 23:03

    To print score I should set defaultFieldSortScoring(true,true)

    0 讨论(0)
  • 2020-12-31 23:12
            IndexReader reader = IndexReader.open(FSDirectory.open(indexDir));
            IndexSearcher searcher = new IndexSearcher(reader);
            Analyzer analyzer = new IKAnalyzer();
            QueryParser parser = new QueryParser(Version.LUCENE_31, "title", analyzer);
            Query q = null;
            q = parser.parse("MacOS");
            TopDocs docs = searcher.search(q, 10);
            ScoreDoc[] filterScoreDosArray = docs.topDocs().scoreDocs;
            for (int i = 0; i < filterScoreDosArray.length; ++i) {
                int docId = filterScoreDosArray[i].doc;
                Document d = is.doc(docId);
                System.out.println((i + 1) + ". " + d.get("docno")+" Score: "+ filterScoreDosArray[i].score);
            }
    

    try this.

    0 讨论(0)
提交回复
热议问题