Solr Schemaless模式将字段创建为MultiValued [英] Solr Schemaless Mode creating fields as MultiValued

查看:488
本文介绍了Solr Schemaless模式将字段创建为MultiValued的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Schemaless模式下使用Solr 6.1。创建集合并索引样本数据后,创建的字段都设置为MultiValued = true,但唯一ID除外。

I'm using Solr 6.1 in Schemaless Mode. After creating a collection and indexing a sample data the fields created were all set to have MultiValued = true, except for unique id.

问题是使用SolrNet查询此数据时,它不会正确地将结果映射到模型。查询结果作为数组返回,并要求模型中的所有属性都更新为ICollection类型。

The problem is when querying this data using SolrNet it wouldn't map the result to the model correctly. The queried results is returned as an array and require all my properties in the model to be updated to ICollection type.

无论如何,我们可以将这些字段设置为MultiValued = false索引样本数据时?

Is there anyway we can set these field to MultiValued = false when indexing the sample data?

说明问题的一个例子:

1)索引一个样本在Schemaless模式下的以下模型:

1) Index a sample of the following model in Schemaless Mode:

public class TestModel
{
    [SolrUniqueKey("id")]
    public int Id { get; set; }

    [SolrField("guid")]
    public Guid Guid { get; set; }
}

2)Solr的托管模式文件将添加以下字段

2) Solr's managed-schema file will be added with the following fields

  <field name="guid" type="strings"/>
  <field name="id" type="string" multiValued="false" indexed="true" required="true" stored="true"/>

3)查询/映射模型时出错

3) Error during querying / mapping of the model

Object of type 'System.Collections.ArrayList' cannot be converted to type


推荐答案

无模式模式使所有内容 multiValued ,因为它不知道您是否有单个值后跟多值值对于同一领域。因此,它会使所有字段都变为多值,并且还会将数字类型升级到最大值。

The schemaless mode makes everything multiValued as it does not know if you have single values followed by multivalued values for the same field. So it makes all fields multivalued and also upgrades numeric types to the largest.

如果您熟悉您的域名,这很容易调整。整个映射链在solrconfig.xml的更新请求处理器链中定义( add-unknown-fields-to-the schema )您可以将类型映射从多值类型更改为等价单值类型。对于字符串,您可以更改 defaultFieldType 中的值。

This is easily adjustable if you know your domain well. The whole mapping chain is defined in the solrconfig.xml's update request processor chain (add-unknown-fields-to-the-schema) and you can change the type mapping from multivalued type to an equivalent single valued type. For strings, you change the value in the defaultFieldType.

这篇关于Solr Schemaless模式将字段创建为MultiValued的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆