Created
September 26, 2014 06:48
-
-
Save darrenferguson/2087ad6851522e0bb609 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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