Skip to content

Instantly share code, notes, and snippets.

@RyanABailey
Created March 1, 2016 22:02
Show Gist options
  • Select an option

  • Save RyanABailey/a246b8fd1d8fd5880ad5 to your computer and use it in GitHub Desktop.

Select an option

Save RyanABailey/a246b8fd1d8fd5880ad5 to your computer and use it in GitHub Desktop.
Lucene facet computed field
namespace MyProject
{
public class IndexType : IComputedIndexField
{
/// <inheritdoc />
public string FieldName { get; set; }
/// <inheritdoc />
public string ReturnType { get; set; }
/// <inheritdoc />
public object ComputeFieldValue(IIndexable indexable)
{
Item item = indexable as SitecoreIndexableItem;
if (item != null)
{
try
{
if (item.Paths.IsMediaItem)
{
return "Doc";
}
else
{
return "Page";
}
}
catch (Exception)
{
return null;
}
}
return null; // Return null if nothing to index
}
}
}
<!-- Type for faceting-->
<field fieldName="typefacet" storageType="yes" indexType="untokenized"
patch:after="field[last()]">MyProject.IndexType, MyProject</field>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment