How to rebuild custom examine index programmatically (Umbraco 8)
Hi to all,
I created a custom examine members index and it works fine...but I realized that when I create a new member (programmatically) it doesn't update automatically.
There is a way to force the rebuild each time a new member is created (or
updated) programmatically?
A little update...after some tests, I saw that new member Exist in the examin index, because if I try to search him in Examine Management (backoffice), I found him.
So the problem is only in frontend.
I have a page to search colleagues and I don't find any of the new members.
I can find them only after a rebuild of my custom index.
I had to modify my Custom Index Creator as follows.
Now I have my custom index always updated.
Adriano
using Examine;
using Lucene.Net.Analysis.Standard;
using Lucene.Net.Util;
using System.Collections.Generic;
using Umbraco.Core.Logging;
using Umbraco.Core.Services;
using Umbraco.Examine;
using Umbraco.Web.Search;
namespace AF.Examine.Index.Tools.For.UmbracoV8.Creators
{
public class AFMembersIndexCreator : UmbracoIndexesCreator
{
private readonly IProfilingLogger _profilingLogger;
private readonly ILocalizationService _languageService;
private readonly IPublicAccessService _publicAccessService;
private readonly IMemberService _memberService;
private readonly IUmbracoIndexConfig _iUmbracoIndexConfig;
// Since Umbraco 8 has dependency injection out of the box, we can use it to inject
// the different services that we need.
public AFMembersIndexCreator(IProfilingLogger profilingLogger,
ILocalizationService languageService,
IPublicAccessService publicAccessService,
IMemberService memberService,
IUmbracoIndexConfig umbracoIndexConfig) : base(profilingLogger, languageService, publicAccessService, memberService, umbracoIndexConfig)
{
_profilingLogger = profilingLogger;
_languageService = languageService;
_publicAccessService = publicAccessService;
_memberService = memberService;
_iUmbracoIndexConfig = umbracoIndexConfig;
}
// Noticed that we return a collection of indexes? Technically you
// can create multiple indexes in an indexCreator :) You can have a look at
// UmbracoIndexesCreator.cs in the CMS core and see how the CMS does that.
public override IEnumerable<IIndex> Create()
{
// create my AFMembersIndex definitions
return new[] { CreateAFMembersIndex() };
}
private IIndex CreateAFMembersIndex()
{
var AFMembersIndex = new UmbracoMemberIndex(
"AFMembersIndex",
new FieldDefinitionCollection(
new FieldDefinition("memberId", FieldDefinitionTypes.FullText),
new FieldDefinition("memberNodeName", FieldDefinitionTypes.FullText),
new FieldDefinition("memberLoginName", FieldDefinitionTypes.FullText),
new FieldDefinition("memberEmail", FieldDefinitionTypes.FullText),
new FieldDefinition("memberName", FieldDefinitionTypes.FullText),
new FieldDefinition("memberSurname", FieldDefinitionTypes.FullText),
new FieldDefinition("memberIntTel", FieldDefinitionTypes.FullText),
new FieldDefinition("memberFax", FieldDefinitionTypes.FullText),
new FieldDefinition("memberCel", FieldDefinitionTypes.FullText)
),
CreateFileSystemLuceneDirectory("AFMembersIndex"),
new StandardAnalyzer(Version.LUCENE_30),
ProfilingLogger,
UmbracoIndexConfig.GetMemberValueSetValidator());
return AFMembersIndex;
}
}
}
How to rebuild custom examine index programmatically (Umbraco 8)
Hi to all, I created a custom examine members index and it works fine...but I realized that when I create a new member (programmatically) it doesn't update automatically.
There is a way to force the rebuild each time a new member is created (or updated) programmatically?
Thanks
Adriano
A little update...after some tests, I saw that new member Exist in the examin index, because if I try to search him in Examine Management (backoffice), I found him. So the problem is only in frontend. I have a page to search colleagues and I don't find any of the new members. I can find them only after a rebuild of my custom index.
Any idea?
SOLVED
I had to modify my Custom Index Creator as follows.
Now I have my custom index always updated.
Adriano
is working on a reply...