Skip to content

Instantly share code, notes, and snippets.

@greystate
Forked from darrenferguson/VortoPropertyIndexer
Last active August 29, 2015 14:06
Show Gist options
  • Save greystate/8f8e79a0c829ae37863a to your computer and use it in GitHub Desktop.
Save greystate/8f8e79a0c829ae37863a to your computer and use it in GitHub Desktop.
(Forked only to rename file for getting syntax highlighting — I have no C# skills to otherwise improve the code 🙈 :-)
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