Last active
November 29, 2017 08:40
-
-
Save hallojoe/f3f29d11c0428373c8a1ef3433aba749 to your computer and use it in GitHub Desktop.
A set of extentsion methods to get field names of indexes
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 System.Linq; | |
using Examine.LuceneEngine.Providers; | |
using Lucene.Net.Index; | |
using Examine; | |
namespace UmbracoExamineApi | |
{ | |
public static class LuceneIndexerExtensions | |
{ | |
/// <summary> | |
/// Shortcut for getting field names of an index | |
/// </summary> | |
/// <param name="indexer"></param> | |
/// <returns></returns> | |
public static IEnumerable<string> GetFieldNames(this LuceneIndexer indexer) => | |
indexer.GetIndexWriter().GetReader().GetFieldNames(IndexReader.FieldOption.ALL); | |
/// <summary> | |
/// Shortcut for getting field names of an index by name | |
/// </summary> | |
/// <param name="indexerName"></param> | |
/// <returns></returns> | |
public static IEnumerable<string> GetFieldNames(this string indexerName) => | |
((LuceneIndexer)ExamineManager.Instance.IndexProviderCollection[indexerName]).GetFieldNames(); | |
/// <summary> | |
/// Shortcut for getting field names of multiple indexes | |
/// </summary> | |
/// <param name="indexers"></param> | |
/// <returns></returns> | |
public static IEnumerable<string> GetFieldNames(this IEnumerable<LuceneIndexer> indexers) | |
{ | |
var names = new List<string>(); | |
foreach (var indexer in indexers) | |
names.AddRange(indexer.GetFieldNames()); | |
return names.Distinct(); | |
} | |
/// <summary> | |
/// Shortcut for getting field names of multiple indexes by names | |
/// </summary> | |
/// <param name="indexerNames"></param> | |
/// <returns></returns> | |
public static IEnumerable<string> GetFieldNames(this IEnumerable<string> indexerNames) | |
{ | |
var indexers = new List<LuceneIndexer>(); | |
foreach (var indexerName in indexerNames) | |
indexers.Add((LuceneIndexer)ExamineManager.Instance.IndexProviderCollection[indexerName]); | |
return indexers.GetFieldNames(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment