-
Notifications
You must be signed in to change notification settings - Fork 1
Description
I'm trying to implement 'Geo Search' - https://docs.developers.optimizely.com/platform-optimizely/docs/geo-search
As per the docs: To enable geo search, you need to use a custom type called GeoPoint that consists of two properties: lat and lon, which are of type float.
I have set this up using the SDK but the stored values for lat and lon under the GeoPoint field always end up as null.
It looks like the GeoPoint field might follow some kind of convention that breaks here. To test, I have created an exact copy of the same GeoPoint object with the same fields and and called it a different name, 'SomeOtherObejct' -> this object saves correctly.
Here's my code:
Defining the types:
public class GeoGraphObject
{
public string Name { get; set; }
public string ProductId { get; set; }
public GeoPoint GeoPointField { get; set; }
public SomeOtherObject SomeOtherObject { get; set; }
}
public class GeoPoint
{
public double lat { get; set; }
public double lon { get; set; }
}
public class SomeOtherObject
{
public double lat { get; set; }
public double lon { get; set; }
}
Saving the types:
public override string Execute()
{
// Initialize the GraphSourceClient by calling the Create method
var client = GraphSourceClient.Create(new Uri("https://cg.optimizely.com"),
source: "geo",
appKey: "----",
secret: "----");
// Add a language preference
client.AddLanguage("en");
// Use the client to configure content types
client.ConfigureContentType<GeoGraphObject>()
.Field(x => x.Name, IndexingType.Searchable)
.Field(x => x.GeoPointField, IndexingType.PropertyType)
.Field(x => x.SomeOtherObject, IndexingType.PropertyType);
client.ConfigurePropertyType<GeoPoint>()
.Field(x => x.lat, IndexingType.Queryable)
.Field(x => x.lon, IndexingType.Queryable);
client.ConfigurePropertyType<SomeOtherObject>()
.Field(x => x.lat, IndexingType.Queryable)
.Field(x => x.lon, IndexingType.Queryable);
// Save content types to Optimizely Graph
var result = client.SaveTypesAsync();
return result.Result;
}
Syncing the types:
public override string Execute()
{
var client = GraphSourceClient.Create(new Uri("https://cg.optimizely.com"),
source: "geo",
appKey: "----",
secret: "----");
var itemsToSync = new GeoGraphObject[]
{
new GeoGraphObject()
{
ProductId = "abcd-1234",
Name = "Item One",
GeoPointField = new GeoPoint()
{
lon = 1,
lat = 2
},
SomeOtherObject = new SomeOtherObject()
{
lat = 5,
lon = 6
}
},
new GeoGraphObject()
{
ProductId = "wxyz-6789",
Name = "Item Two",
GeoPointField = new GeoPoint()
{
lon = 1,
lat = 2
},
SomeOtherObject = new SomeOtherObject()
{
lat = 5,
lon = 6
}
}
};
foreach (var item in itemsToSync)
{
client.SaveContentAsync<GeoGraphObject>(
generateId: (obj) => obj.ProductId,
item);
}
return "Sync completed successfully.";
}
When it's all set up, here's what we end up with in the index:
Note, the lat and lon values for the 'SomeOtherObject' are populated but the same values for the 'GeoPointField' are are null.
Please let me know is there a way around this
Thanks in advance