我正在尝试在 solrnet 中实现自定义 IReadOnlyMappingManager 以允许我们使用我们自己的属性类型来装饰代表我们的 solr 索引记录的文档的属性。由于我只需要替换GetFields和GetUniqueKey方法的实现,目前的实现如下:
public class CustomMappingManager : AttributesMappingManager
{
public new ICollection<KeyValuePair<PropertyInfo, string>> GetFields(Type type)
{
IEnumerable<KeyValuePair<PropertyInfo, IndexFieldAttribute[]>> mappedProperties = this.GetPropertiesWithAttribute<IndexFieldAttribute>(type);
IEnumerable<KeyValuePair<PropertyInfo, string>> fields = from mapping in mappedProperties
select new KeyValuePair<PropertyInfo, string>(mapping.Key, mapping.Value[0].FieldName ?? mapping.Key.Name);
return new List<KeyValuePair<PropertyInfo, string>>(fields);
}
public new KeyValuePair<PropertyInfo, string> GetUniqueKey(Type type)
{
KeyValuePair<PropertyInfo, string> uniqueKey;
IEnumerable<KeyValuePair<PropertyInfo, IndexUniqueKeyAttribute[]>> mappedProperties = this.GetPropertiesWithAttribute<IndexUniqueKeyAttribute>(type);
IEnumerable<KeyValuePair<PropertyInfo, string>> fields = from mapping in mappedProperties
select new KeyValuePair<PropertyInfo, string>(mapping.Key, mapping.Value[0].FieldName ?? mapping.Key.Name);
uniqueKey = fields.FirstOrDefault();
return uniqueKey;
}
}
此类型已使用结构映射成功连接,并且我的 IsolrOperations 具体实例中的 mappingManager 是此 CustomMappingManager 类型的实例。
我一直在跟踪堆栈跟踪,一直到执行实际工作的 solrnet 实现中的 Viistor;这些具有预期的 CustomMappingManager 实例。不幸的是,这种类型的 GetFields 和 GetUniqueKey 方法永远不会被调用,而且我的文档总是空的。
任何想法都非常受欢迎。