Created
March 1, 2016 22:02
-
-
Save RyanABailey/a246b8fd1d8fd5880ad5 to your computer and use it in GitHub Desktop.
Lucene facet computed field
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 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 | |
| } | |
| } | |
| } |
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
| <!-- 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