为什么 solr-node 查询给出错误的文档版本号?

Why does solr-node query gives a wrong document version number?

我正在使用 Solr 7.6。在执行搜索查询时,Solr 给出了文档的错误 version 字段,但所有其他字段都是正确的。

在 Solr 仪表板中,查询给出以下结果:

{
        "id":"518fce46-3617-4380-aaf6-8f6d36e08e6a",
        "type":"tag",
        "count":1,
        "_version_":1626999925241806848
}

然而,solr-node 搜索功能给出:

{
         "id": "518fce46-3617-4380-aaf6-8f6d36e08e6a",
         "type": "tag",
         "count": 1,
         "_version_": 1626999925241806800
}

初步猜测是 solr-node 模块 return 将值作为双精度值(而不是字符串),并且双精度精度不足以表示值 1626999925241806848 正好。

我们可以直接在浏览器的控制台中确认这一点:

-> 1626999925241806848
<- 1626999925241806800

即如果我们输入数值1626999925241806848,它会被最接近的浮点数表示,也就是1626999925241806800.

solr-node 可能 return 这些值超过 int 的可表示值时作为字符串。

更新: solr-node details this at their overview page:

Use json-bigint to handle correctly numbers too large for Javascript Number such as the values of the fields *l and _version. By default json-bigint library is not used because the performance difference compared to the native JSON library is too important with "large" chunk of JSON (https://github.com/lbdremy/solr-node-client/issues/114#issuecomment-54165595), but you want to enable it if you use the Optimistic Concurreny feature available in Solr 4.x, along with RealTime Get and Atomic Updates features because they use the version field. In order to enable it do var client = solr.createClient({ bigint : true}) or directly on the client instance client.options.bigint = true.