
This may be touched on in the official Umbraco V9 documentation when that is released, but for now at least, this is how we have managed to create a custom Umbraco Index in V9 filtered to a specific document type.
In V8 we could use an IndexCreator
to achieve this as seen in the documentation here, however it seems this is no longer a thing in V9 and now we inherit the UmbracoExamineIndex
and override IIndex.IndexItems
.
This is probably not the correct way to do this, but until there is some documentation it seems to work, if you find an alternative (or better way) please let us know in the comments below.
So firstly you will want to create your index, so in our case it's for the Knowledgebase, where we only wanted to index items of type knowledgebaseArticle
, in the code below you can see we are restricting the indexed items to the knowledgebaseArticle
document type.
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using Examine; | |
using Examine.Lucene; | |
using Microsoft.Extensions.Logging; | |
using Microsoft.Extensions.Options; | |
using Umbraco.Cms.Core.Hosting; | |
using Umbraco.Cms.Core.Services; | |
using Umbraco.Cms.Infrastructure.Examine; | |
namespace UmbHost.Core.Components | |
{ | |
public class KnowledgebaseIndex : UmbracoExamineIndex, IUmbracoContentIndex, IDisposable | |
{ | |
public KnowledgebaseIndex( | |
ILoggerFactory loggerFactory, | |
string name, | |
IOptionsSnapshot<LuceneDirectoryIndexOptions> indexOptions, | |
IHostingEnvironment hostingEnvironment, | |
IRuntimeState runtimeState) | |
: base(loggerFactory, name, indexOptions, hostingEnvironment, runtimeState) | |
{ | |
loggerFactory.CreateLogger<KnowledgebaseIndex>(); | |
LuceneDirectoryIndexOptions namedOptions = indexOptions.Get(name); | |
if (namedOptions == null) | |
{ | |
throw new InvalidOperationException($"No named {typeof(LuceneDirectoryIndexOptions)} options with name {name}"); | |
} | |
if (namedOptions.Validator is IContentValueSetValidator contentValueSetValidator) | |
{ | |
PublishedValuesOnly = contentValueSetValidator.PublishedValuesOnly; | |
} | |
} | |
void IIndex.IndexItems(IEnumerable<ValueSet> values) => PerformIndexItems(values.Where(v => v.ItemType == "knowledgebaseArticle"), OnIndexOperationComplete); | |
} | |
} |
Next you will want to register this with a composer, here you can see we are giving the index a name of KnowledgebaseArticles
:
using Examine; | |
using Microsoft.Extensions.DependencyInjection; | |
using UmbHost.Core.Components; | |
using Umbraco.Cms.Core.Composing; | |
using Umbraco.Cms.Core.DependencyInjection; | |
using Umbraco.Cms.Infrastructure.Examine; | |
namespace UmbHost.Core.Composers | |
{ | |
public class IndexHelperComposer : IUserComposer | |
{ | |
public void Compose(IUmbracoBuilder builder) | |
{ | |
IServiceCollection services = builder.Services; | |
services | |
.AddExamineLuceneIndex<KnowledgebaseIndex, ConfigurationEnabledDirectoryFactory>("KnowledgebaseArticles"); | |
} | |
} | |
} |
And here you can see it is now showing up in the Umbraco Back Office:
And that's all there is to it as far as we can see, so pretty simple.
Comments
Recent Posts





Categories
See Umbraco Forms Documentation