Created
June 24, 2015 04:33
-
-
Save nathanwoulfe/f83d30fcde854d4cfbc3 to your computer and use it in GitHub Desktop.
Index Archetype content in Umbraco - a custom search indexer
This file contains hidden or 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
namespace Your.Namespace { | |
class CustomIndexer : UmbracoContentIndexer { | |
protected override Dictionary<string, string> GetDataToIndex(XElement node, string type) | |
{ | |
Dictionary<string,string> data = base.GetDataToIndex(node, type); | |
string content = ""; | |
if (data.ContainsKey("archetypeAlias")) | |
{ | |
var archetypes = JsonConvert.DeserializeObject<ArchetypeModel>(data["archetypeAlias"]); | |
foreach (var archetype in archetypes) | |
{ | |
//Iterate the archetype objects, add the desired values to the content variable | |
if (archetype.Alias == "indexAPropertyOfThisFieldset") | |
{ | |
content += archetype.GetValue("indexThisProperty") | |
} | |
} | |
//Adding the archetype content to the bodytext field to make it searchable using current queries | |
if (!String.IsNullOrEmpty(content)) | |
{ | |
if (data.ContainsKey("bodyText")) | |
data["bodyText"] += content; | |
else | |
data.Add("bodyText", content); | |
} | |
} | |
return data; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment