With fields of types Name Value List and Name Lookup Value List, it is possible to reference items by ID. If the selected IDs are stored without curly brackets, then the field value cannot be indexed. The following message can be found in the Crawling logs:
FATAL Could not add field {6AC5BD92-75AE-4EF8-9D9E-BA61A96762B0} : fieldname for indexable sitecore://master/{110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9}?lang=en&ver=1
Exception: System.ArgumentOutOfRangeException
Message: Index and length must refer to a location within the string.
Parameter name: length
Source: mscorlib
at System.String.Substring(Int32 startIndex, Int32 length)
at Sitecore.Data.ShortID.Encode(String guid)
at Sitecore.ContentSearch.FieldReaders.NameValueListFieldReader.GetFieldValue(IIndexableDataField indexableField)
at Sitecore.ContentSearch.FieldReaders.FieldReaderMap.GetFieldValue(IIndexableDataField field)
at Sitecore.ContentSearch.SolrProvider.SolrDocumentBuilder.AddField(IIndexableDataField field)
at Sitecore.ContentSearch.AbstractDocumentBuilder`1.CheckAndAddField(IIndexable indexable, IIndexableDataField field)
To resolve the issue, upgrade your solution to Sitecore XP 10.3.0 or later.
Alternatively, to prevent the issue, consider one of the following options:
Note: To check the raw value of the field, click the Raw values check box on the View tab.
using System.Collections.Generic;
using System.Collections.Specialized;
using Sitecore.Abstractions;
using Sitecore.ContentSearch;
using Sitecore.ContentSearch.FieldReaders;
using Sitecore.Data;
using Sitecore.Data.Fields;
using Sitecore.Diagnostics;
using Sitecore.Web;
public class CustomNameValueListFieldReader : FieldReader
{
public override object GetFieldValue(IIndexableDataField indexableField)
{
Field field = indexableField as SitecoreItemDataField;
List<string> list = new List<string>();
BaseFieldTypeManager instance = ContentSearchManager.Locator.GetInstance<BaseFieldTypeManager>();
Assert.IsNotNull(instance, "fieldTypeManager != null");
NameValueListField nameValueListField = instance.GetField(field) as NameValueListField;
if (nameValueListField != null)
{
NameValueCollection nameValueCollection = WebUtil.ParseUrlParameters(field.Value);
{
foreach (string item in nameValueCollection)
{
string text = nameValueCollection[item];
if (ID.IsID(text))
{
// Treat GUIDs without curly braces as text
text = (text.Length != 38) ? text.Replace("-", "").ToLowerInvariant() : ShortID.Encode(text).ToLowerInvariant();
}
list.Add(text);
}
return list;
}
}
return list;
}
}
<?xml version="1.0" encoding="utf-8" ?>
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/" xmlns:role="http://www.sitecore.net/xmlconfig/role/" xmlns:search="http://www.sitecore.net/xmlconfig/search/" xmlns:set="http://www.sitecore.net/xmlconfig/set/" >
<sitecore role:require="Standalone or ContentManagement or ContentDelivery" search:require="solr">
<contentSearch>
<indexConfigurations>
<defaultSolrIndexConfiguration>
<fieldReaders>
<mapFieldByTypeName>
<fieldReader fieldTypeName="name lookup value list|name value list" set:fieldReaderType="CustomNamespace.CustomNameValueListFieldReader, CustomAssembly" />
</mapFieldByTypeName>
</fieldReaders>
</defaultSolrIndexConfiguration>
</indexConfigurations>
</contentSearch>
</sitecore>
</configuration>