且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Solr - 返回随机结果(按随机排序)

更新时间:2023-02-26 18:44:20

使用 RandomSortField.示例目录(solr 下)中捆绑的 schema.xml 中有一个示例:

Use a RandomSortField. There's an example in the bundled schema.xml in example directory (under solr):

<dynamicField name="random_*" type="random" />

按字段 random_ 对结果列表进行排序,您可以在该字段中将 替换为随机生成的值(但如果您需要使用相同的值)重新分页结果,因为它会根据字段名称为您提供稳定的排序).

Sort your result list by the field random_<seed>, where you replace <seed> with a randomly generated value (but use the same value if you're paginating through the result, as it will give you a stable sort based on the field name).