Skip to content

Instantly share code, notes, and snippets.

@darrenferguson
Created September 26, 2014 06:48
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save darrenferguson/2087ad6851522e0bb609 to your computer and use it in GitHub Desktop.
Save darrenferguson/2087ad6851522e0bb609 to your computer and use it in GitHub Desktop.
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