2011-02-25 4 views
0

solrnet에서 사용자 지정 IReadOnlyMappingManager를 구현하여 solr 인덱스 레코드를 나타내는 문서의 속성을 꾸미기 위해 고유 한 특성 형식을 사용할 수있게하려고합니다.solrnet에서 사용자 지정 IReadOnlyMappingManager 구현

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; 
    } 
} 

이 유형이 성공적으로 structuremap를 사용하여 유선 및 ISolrOperations의 내 구체적인 인스턴스의 mappingManager 된 인스턴스이다 : 나는 단지 GetFields 및 GetUniqueKey 방법의 구현을 교체해야로서 다음과 같이 현재의 구현은 이 CustomMappingManager 유형의

실제 작업을 수행하는 solrnet 구현에서 Viistors 바로 아래까지 스택 추적을 수행했습니다. 이것들은 의도 한대로 CustomMappingManager 인스턴스를가집니다. 불행히도이 형식의 GetFields 및 GetUniqueKey 메서드는 호출되지 않으며 내 문서는 항상 비어 있습니다.

아이디어를 환영합니다.

+0

왜 자신의 속성을 사용하고 싶습니까? 추가 정보가 있습니까? –

+0

솔라 넷 유형에 대한 의존성을 없애려는 의도라고 생각합니다. 추가 기능을 부여하지는 않습니다. 저는 몇 달 전에 동료가 한 몇 가지 연구 코드에서 이것을 집어 냈습니다. 이제 며칠을 보내고 나면 고립에 대한 필요성을 확신하지 못했습니다. – Jason

답변

0

나는 이것을 해결했다. 문제의 접근 방식은 잘못 될 수밖에 없었습니다. 다음은 CustomMappingManager 구현을위한 작업 코드의 상당 부분입니다.

public class CustomMappingManager : IReadOnlyMappingManager 
{ 

public ICollection<SolrFieldModel> GetFields(Type type) 
    { 
     IEnumerable<KeyValuePair<PropertyInfo, IndexFieldAttribute[]>> mappedProperties = this.GetPropertiesWithAttribute<IndexFieldAttribute>(type); 

     IEnumerable<SolrFieldModel> fields = from mapping in mappedProperties 
              select new SolrFieldModel() 
              { 
               Property = mapping.Key, 
               FieldName = mapping.Value[0].FieldName ?? mapping.Key.Name 
              }; 

     return new List<SolrFieldModel>(fields); 
    } 

public SolrFieldModel GetUniqueKey(Type type) 
    { 
     SolrFieldModel uniqueKey; 

     IEnumerable<KeyValuePair<PropertyInfo, IndexUniqueKeyAttribute[]>> mappedProperties = this.GetPropertiesWithAttribute<IndexUniqueKeyAttribute>(type); 

     IEnumerable<SolrFieldModel> fields = from mapping in mappedProperties 
              select new SolrFieldModel() 
              { 
               Property = mapping.Key, 
               FieldName = mapping.Value[0].FieldName ?? mapping.Key.Name 
              }; 

     uniqueKey = fields.FirstOrDefault(); 

     if (uniqueKey == null) 
     { 
      throw new Exception("Index document has no unique key attribute"); 
     } 

     return uniqueKey; 
    } 
} 
관련 문제