2014-11-23 61 views
0

如何將計算後的形狀添加到我的索引中?RavenDB - 如何將WKT圓形添加到索引?

我有一個類

public class Partner 
{ 
    public double Latitude { get; set; } 
    public double Longitude { get; set; } 
    public double WorkingRadius { get; set; } 
    public double WorkingRadiusShape 
    { 
     get 
     { 
     return string.Format("Circle({0},{1}, d={2})", Latitude, Longitude, WorkingRadius); 
     } 
    } 
} 

用下面的指數

public class PartnersByLocation : AbstractIndexCreationTask<Partner> 
{ 
    public PartnersByLocation() 
    { 
     Map = partners => from doc in partners 
           select new 
           { 
           WorkingRadiusShape = doc.WorkingRadiusShape 
           }; 

     Spatial(x => x.WorkingRadiusShape, options => options.Geography.Default()); 
    } 
} 

我重建和運行我的應用程序,但該指數PartnersByLocation是空的。我不確定我做錯了什麼。該索引不會報告錯誤,並且我已檢查合作伙伴集合是否爲寫入WorkingRadiusShape屬性的屬性設置了值。我的語法或方法是否有根本錯誤?

回答

0

我想通了。

Map = partners => from doc in partners 
           where doc.AbilityKeyIds != null 
           select new 
           { 
           WorkingRadiusShape = string.Format("Circle({0},{1}, d={2})", doc.Latitude, doc.Longitude, doc.WorkingRadius) 
           }; 



Spatial(x => x.WorkingRadiusShape, options => options.Geography.Default()); 

的關鍵是移動分配WorkingRadiusShape在索引,否則該屬性只得到更新/寫文件讀取。因此,如果存在任何已棄用/無效的條目,則在寫入索引時將不會更新它們,並且索引將會中斷。在我的情況下,我在我的一個合作伙伴條目中存儲了10000個WorkingRadius。此值導致索引中斷,因爲最大值爲180,可以作爲'd'傳遞。分配形狀時請注意最大值。