Solr - C# 查询附加“s”到排序字段

问题描述 投票:0回答:1

我们的排序顺序无法正常工作,我发现这是因为生成的 solr 查询以 sort=date_tdts%20desc 结尾 - 而它应该以 sort=date_tdt%20desc 结尾(注意额外的 's')。但我不确定代码中这个额外的 s 来自哪里。这是索引字段配置:

[IndexField("date_tdt")]
public DateTime Date { get; set; }

这是生成查询的代码:

    var orderExpression = searchAdapter.MapFilterToOrder(query, out bool orderByDescending);

    var resultsQueryable = providerSearchContext.GetQueryable<TSearchItem>()
        .Where(basePredicate);

    if(query.Filters != null)
    {
        var queryPredicate = CombinePredicates(query.Filters.Select(searchAdapter.MapFilterToPredicate));
        resultsQueryable = resultsQueryable.Where(queryPredicate);
    }

    if (orderExpression != null)
    {
        resultsQueryable = orderByDescending
            ? resultsQueryable.OrderByDescending(orderExpression)
            : resultsQueryable.OrderBy(orderExpression);
    }

    public virtual Expression<Func<ArticleSearchResultItem, object>> MapFilterToOrder(SearchQuery query,
        out bool @descending)
    {
        @descending = true;

        return x => x.Date;
    }

为什么要在 date_tdt 后面附加 s?

solr
1个回答
0
投票

解决方案中的(不是 Solr 中的)需要更新,以便它知道将该字段视为什么类型:

  <contentSearch>
      <indexConfigurations>
          <defaultSolrIndexConfiguration>
              <fieldMap>
                  <fieldNames>
                      <field fieldName="date_tdt" returnType="datetime"></field>
                  </fieldNames>
              </fieldMap>
          </defaultSolrIndexConfiguration>
      </indexConfigurations>
  </contentSearch>
© www.soinside.com 2019 - 2024. All rights reserved.