简体   繁体   English

Solr索引中缺少Id字段

[英]Missing Id field in Solr index

I just find out that my Solr index doesn't contain a _id field. 我发现我的Solr索引不包含_id字段。 and it is not possible to get item id. 并且无法获得项目ID。 UniqueId is present but this is not really useful. UniqueId存在,但这不是很有用。

public class MyClass
{
    [IndexField(BuiltinFields.UniqueId)]
    public string UniqueId { get; set; }

    [IndexField(BuiltinFields.ID)]
    public int Id { get; set; }
}

How to add item id to Solr index ? 如何将项目ID添加到Solr索引? What should I add to schema.xml ? 我应该向schema.xml添加什么? Is next string would be enough ? 下一个字符串就够了吗?

<field name="_id" type="string" indexed="true" stored="true" required="true" />

If yes why Sitecore doesn't include it during build schema.xml file for Solr ? 如果是,为什么Sitecore在构建针对Solr的schema.xml文件时不包含它?

It seems that it could be an issue with duplication records in search result that I have as well :) 看来它可能是搜索结果中的重复记录问题,我也有:)

As Richard answered, there is a _group field in Solr. 理查德回答说, _group有一个_group字段。 If you want it to be translated automatically into ID object, you can use: 如果您希望将其自动转换为ID对象,您可以使用:

[TypeConverter(typeof (IndexFieldIDValueConverter))]
[IndexField("_group")]
public virtual ID ItemId { get; set; }

Remember that if you have multiple versions or language versions, _group field will not be enough, cause there will be multiple documents with the same _group (id). 请记住,如果您有多个版本或语言版本, _group字段将不够,因为将有多个文档具有相同的_group (id)。 In that case you may want to use UniqueId - it contains information about id, version, language and database: 在这种情况下,您可能想要使用UniqueId - 它包含有关id,版本,语言和数据库的信息:

[IndexField("_uniqueid")]
public virtual string UniqueId { get; set; }

And then to get the Item use: 然后获取Item使用:

private Item _innerItem;
public virtual Item GetItem()
{
    if (_innerItem == null)
    {
        ItemUri uri = new ItemUri(UniqueId);
        _innerItem = Factory.GetDatabase(uri.DatabaseName).GetItem(uri.ItemID, uri.Language, uri.Version);
    }
    return _innerItem;
}

Or you can just inherit your MyClass from Sitecore.ContentSearch.SearchTypes.SearchResultItem and you will have all the built in fields there. 或者您可以从Sitecore.ContentSearch.SearchTypes.SearchResultItem继承您的MyClass ,并且您将拥有所有内置字段。

In SOLR the Item Id field is called _group - this should be added to your schema.xml file when you generate it. 在SOLR中,Item Id字段称为_group - 生成它时应将其添加到schema.xml文件中。

If its not there, this is the definition I have: 如果不存在,这就是我的定义:

<field name="_group" stored="true" indexed="true" type="string"/>

The UniqueId field contains the ItemId along with the version and language of the item. UniqueId字段包含ItemId以及项目的版本和语言。

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

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