Skip to content

Instantly share code, notes, and snippets.

@nathanwoulfe
Created June 24, 2015 04:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nathanwoulfe/f83d30fcde854d4cfbc3 to your computer and use it in GitHub Desktop.
Save nathanwoulfe/f83d30fcde854d4cfbc3 to your computer and use it in GitHub Desktop.
Index Archetype content in Umbraco - a custom search indexer
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