简体   繁体   English

Solr 7.3-在多值字段上有条件排序

[英]Solr 7.3 - Sort conditionally on multi-valued field

I am new to Solr, using Solr 7.3 and I am trying to achieve the following - given a date, I need to retrieve all products which have contracts expiring beyond this date, sorted on the earliest expiring contract, but not considering the already expired contracts. 我是Solr的新手,使用Solr 7.3,并尝试实现以下目标-给定一个日期,我需要检索所有合同已过期的产品,该产品按最早到期的合同排序,但不考虑已到期的合同。 I am not able to get the sort correct. 我无法正确排序。 In the below case, product_id "10002023" should have been the last in the list as it has a contract which is expiring last (2021-08-31), ignoring the already expired contract. 在以下情况下,product_id“ 10002023”应该是列表中的最后一个,因为它的合同最近到期(2021-08-31),而忽略了已到期的合同。 Any help is greatly appreciated. 任何帮助是极大的赞赏。

http://localhost/solr/catalogue/select?fl=product_id,%20contract_id,%20contract_valid_to&fq=contract_id:[*%20TO%20*]&fq=contract_valid_to:%20[2018-12-12%20TO%20*]&q=*:*&sort=field(contract_valid_to,%20min)%20asc

..."docs":[
{
  "product_id":"10002023",
  "contract_id":["1427",
    "1428"],
  "contract_valid_to":["2018-12-07 15:36:13.0",
    "2021-08-31 15:40:33.0"]},
{
  "product_id":"1012974",
  "contract_id":["867"],
  "contract_valid_to":["2019-05-16 15:58:01.0"]},
{
  "product_id":"1012985",
  "contract_id":["777"],
  "contract_valid_to":["2019-05-19 11:07:50.0"]},
{
  "product_id":"1012975",
  "contract_id":["787"],
  "contract_valid_to":["2019-05-24 12:02:18.0"]},
{
  "product_id":"1012997",
  "contract_id":["831"],
  "contract_valid_to":["2019-05-29 15:37:37.0"]}]

Unfortunately, the definition that you're using for date field is incorrect 不幸的是,您用于日期字段的定义不正确

<dynamicField name="contract_*" type="string" multiValued="true" indexed="true" stored="true"/>

It is assuming that this is just a plain string, not different from anything else. 假定这只是一个纯字符串,与其他字符串没有区别。

Also, regarding your second comment Solr supports dates of only 1 format - YYYY-MM-DDThh:mm:ssZ , so if you want to use date features you would need to do conversion to a proper format and use date type. 另外,关于第二条评论,Solr仅支持1种格式的日期YYYY-MM-DDThh:mm:ssZ ,因此,如果要使用日期功能,则需要转换为正确的格式并使用date类型。

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

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