嗨,我正在尝试通过Kentico CustomAzureSearchModule在 Azure 搜索索引中创建 Edm.GeographyPoint 项。这是在 Kentico 中的索引重建时激活的。我不断收到错误消息为空间属性指定的值无效。您必须指定一个有效的空间值。. 我的代码如下:
public class CustomAzureSearchModule : Module
{
private string nodeguid = "";
public CustomAzureSearchModule() : base(nameof(CustomAzureSearchModule))
{
}
protected override void OnInit()
{
base.OnInit();
DataMapper.Instance.RegisterMapping(typeof(GeographyPoint), Microsoft.Azure.Search.Models.DataType.GeographyPoint);
DocumentFieldCreator.Instance.CreatingField.After += CreatingField_After;
DocumentCreator.Instance.AddingDocumentValue.Execute += AddingValue;
}
private void CreatingField_After(object sender, CreateFieldEventArgs e)
{
if (e.SearchField.FieldName == "GeoLocation")
{
//Change the field type to Edm.GeographyPoint for Azure Search
e.Field = new Microsoft.Azure.Search.Models.Field("geolocation", Microsoft.Azure.Search.Models.DataType.GeographyPoint);
}
}
private void AddingValue(object sender, AddDocumentValueEventArgs e)
{
if (e.Document.ContainsKey("nodeguid"))
{
nodeguid = e.Document["nodeguid"].ToString(); //Store NodeGuid
}
//}
if (e.AzureName == "geolocation")
{
//Collect nodeGuid and use to get page
TreeNode page = DocumentHelper.GetDocuments()
.WhereEquals("NodeGUID", nodeguid)
.OnCurrentSite()
.Culture("en-gb")
.TopN(1)
.FirstOrDefault();
if (page != null)
{
// Check page type is a service only
if (page.ClassName == ServicePage.CLASS_NAME)
{
//Check for Children
if (page.Children.Count > 0)
{
e.Value = GeographyPoint.Create(31.8, -5); //Add location data to index
}
}
}
}
}
}
}
将不胜感激任何帮助。最终希望使用多个地理编码在 Azure 索引中创建 Collection(EDM.GeographyPoint) 类型。按照这篇文章生成我的代码https://devnet.kentico.com/articles/customizing-azure-search-fields