简体   繁体   English

SolrJ从solr查询中获取所有生成的文档的文档分数

[英]SolrJ Getting document score of all the resulting documents from solr query

I am able to fetch all the documents for a solr query in Solr 6.3.0 using the JAVA API SolrJ.I want an additional field of correct "score" calculated by solr(using tf,idf and field norm) to rank the documents.I am getting the score field as 1.0 for all the documents.Can you help me get the correct "score" field. 我能够使用JAVA API SolrJ在Solr 6.3.0中获取所有文件,以进行Solr查询。我将所有文档的得分字段都设置为1.0。您能帮助我获得正确的“得分”字段吗?

Below is my code snippet and the output. 以下是我的代码段和输出。

        String urlString = "http://localhost:8983/solr/mycore2";
        SolrClient solr = new HttpSolrClient.Builder(urlString).build();
        SolrQuery query = new SolrQuery();
        query.setQuery( "*" );
        query.set("fl", "id,house,postcode,score");
        String s="house=".concat(address.getHouseNumber().getCoveredText());
        query.addFilterQuery(s);
        QueryResponse resp = solr.query(query);
        SolrDocumentList list = resp.getResults();

        if(list!=null)
        {
            System.out.println(list.toString());
        }

Output 输出量

{numFound=4,start=0,maxScore=1.0,docs=[SolrDocument{id=1, house=[150-151], postcode=[641044], score=1.0}, SolrDocument{id=2, house=[150/151], postcode=[641044], score=1.0}, SolrDocument{id=3, house=[151/150], postcode=[641044], score=1.0}, SolrDocument{id=4, house=[151/150], postcode=[641044], score=1.0}]}

Edit After MatsLindh's suggestion,here is the tweaked code and the output. 根据MatsLindh的建议进行编辑 ,这是经过调整的代码和输出。

String urlString = "http://localhost:8983/solr/mycore2";
        SolrClient solr = new HttpSolrClient.Builder(urlString).build();
        SolrQuery query = new SolrQuery();
        query.setQuery(address.getHouseNumber().getCoveredText().concat(" ").concat(address.getPostcode().getCoveredText()));
        query.set("fl", "id,house,postcode,score");
        QueryResponse resp = solr.query(query);
        SolrDocumentList list = resp.getResults();
        if(list!=null)
        {
            System.out.println(list.toString());
        }

Output 输出量

{numFound=3,start=0,maxScore=2.4800222,docs=[SolrDocument{id=6, house=[34], postcode=[641006], score=2.4800222}, SolrDocument{id=5, house=[34], postcode=[641005], score=1.2400111}, SolrDocument{id=7, house=[2-11A], postcode=[641006], score=1.1138368}]}

Since you're not querying for anything, you're not getting a score (each score is the same, 1.0f ). 由于您没有查询任何内容,因此您没有得到分数(每个分数都是1.0f )。 You're only applying a filter, which does not affect the score. 您仅应用了一个过滤器,不会影响得分。

There is no tf/idf (but remember that Solr now uses BM25 as the default similarity model and not tf/idf) score to calculate if there are no tokens to match in the actual query. 没有tf / idf(但请记住,Solr现在使用BM25作为默认相似模型而不是tf / idf)得分来计算实际查询中是否没有匹配的标记。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM