Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
using System.Collections.Generic;
using Moriyama.Library.Architecture;
using Newtonsoft.Json;
namespace Application.Search
{
public class VortoPropertyIndexer
{
// Somewhere in startup
//ExamineManager.Instance.IndexProviderCollection["ExternalIndexer"].GatheringNodeData += MoriyamaApplicationEventHandlerGatheringNodeData;
//void MoriyamaApplicationEventHandlerGatheringNodeData(object sender, IndexingNodeDataEventArgs e)
//{
// VortoPropertyIndexer.Instance.AddVortoFields(e.Fields);
//}
public void AddVortoFields(IDictionary<string, string> fields)
{
var vortoFields = new Dictionary<string, string>();
foreach (var field in fields)
{
if (!field.Value.StartsWith("{"))
continue;
var jsonString = field.Value;
var vortoField = DeserialisePropertyToVortoField(jsonString);
if (vortoField == null || vortoField.Values == null)
continue;
foreach (var vortoValue in vortoField.Values)
{
var newFieldName = field.Key + "_" + vortoValue.Key;
vortoFields.Add(newFieldName, vortoValue.Value);
}
}
foreach (var field in vortoFields)
{
fields.Add(field.Key, field.Value);
}
}
private VortoField DeserialisePropertyToVortoField(string json)
{
VortoField v = null;
try
{
v = JsonConvert.DeserializeObject<VortoField>(json);
}
catch { }
return v;
}
private class VortoField
{
public IDictionary<string, string> Values { get; set; }
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment