Implements Examine/Lucene index syncing for use on Azure (#10386)
* Updates to latest examine, ensures indexes are unlocked on startup, adds more info to the diagnostics and allows for the new sync directory factory to work. * Gets index syncing working correct and fixes reindexing to not overprocess indexes * fix duplicate package ref * rebuilds empty indexes and fixes config with enum * missing file
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
// Copyright (c) Umbraco.
|
||||
// See LICENSE for more details.
|
||||
|
||||
using System;
|
||||
|
||||
namespace Umbraco.Cms.Core.Configuration.Models
|
||||
{
|
||||
/// <summary>
|
||||
@@ -11,6 +13,7 @@ namespace Umbraco.Cms.Core.Configuration.Models
|
||||
/// <summary>
|
||||
/// Gets or sets a value for lucene directory factory type.
|
||||
/// </summary>
|
||||
public string LuceneDirectoryFactory { get; set; }
|
||||
public LuceneDirectoryFactory LuceneDirectoryFactory { get; set; }
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
// Copyright (c) Umbraco.
|
||||
// See LICENSE for more details.
|
||||
|
||||
namespace Umbraco.Cms.Core.Configuration.Models
|
||||
{
|
||||
public enum LuceneDirectoryFactory
|
||||
{
|
||||
/// <summary>
|
||||
/// The index will operate from the default location: Umbraco/Data/Temp/ExamineIndexes
|
||||
/// </summary>
|
||||
Default,
|
||||
|
||||
/// <summary>
|
||||
/// The index will operate on a local index created in the processes %temp% location and
|
||||
/// will replicate back to main storage in Umbraco/Data/Temp/ExamineIndexes
|
||||
/// </summary>
|
||||
SyncedTempFileSystemDirectoryFactory,
|
||||
|
||||
/// <summary>
|
||||
/// The index will operate only in the processes %temp% directory location
|
||||
/// </summary>
|
||||
TempFileSystemDirectoryFactory
|
||||
}
|
||||
}
|
||||
@@ -5,79 +5,61 @@ using System;
|
||||
using System.IO;
|
||||
using Examine;
|
||||
using Examine.Lucene.Directories;
|
||||
using Examine.Lucene.Providers;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Umbraco.Cms.Core.Composing;
|
||||
using Umbraco.Cms.Core.Configuration.Models;
|
||||
using Umbraco.Cms.Core.Hosting;
|
||||
using Umbraco.Extensions;
|
||||
using Constants = Umbraco.Cms.Core.Constants;
|
||||
|
||||
namespace Umbraco.Cms.Infrastructure.Examine
|
||||
{
|
||||
public class ConfigurationEnabledDirectoryFactory : IDirectoryFactory
|
||||
/// <summary>
|
||||
/// An Examine directory factory implementation based on configured values
|
||||
/// </summary>
|
||||
public class ConfigurationEnabledDirectoryFactory : DirectoryFactoryBase
|
||||
{
|
||||
private readonly IServiceProvider _services;
|
||||
private readonly ITypeFinder _typeFinder;
|
||||
private readonly IHostingEnvironment _hostingEnvironment;
|
||||
private readonly ILockFactory _lockFactory;
|
||||
private readonly IApplicationRoot _applicationRoot;
|
||||
private readonly IndexCreatorSettings _settings;
|
||||
private IDirectoryFactory _directoryFactory;
|
||||
|
||||
public ConfigurationEnabledDirectoryFactory(
|
||||
IServiceProvider services,
|
||||
ITypeFinder typeFinder,
|
||||
IHostingEnvironment hostingEnvironment,
|
||||
ILockFactory lockFactory,
|
||||
IOptions<IndexCreatorSettings> settings,
|
||||
IApplicationRoot applicationRoot)
|
||||
{
|
||||
_services = services;
|
||||
_typeFinder = typeFinder;
|
||||
_hostingEnvironment = hostingEnvironment;
|
||||
_lockFactory = lockFactory;
|
||||
_applicationRoot = applicationRoot;
|
||||
_settings = settings.Value;
|
||||
}
|
||||
|
||||
public Lucene.Net.Store.Directory CreateDirectory(string indexName) => CreateFileSystemLuceneDirectory(indexName);
|
||||
protected override Lucene.Net.Store.Directory CreateDirectory(LuceneIndex luceneIndex, bool forceUnlock)
|
||||
{
|
||||
_directoryFactory = CreateFactory();
|
||||
return _directoryFactory.CreateDirectory(luceneIndex, forceUnlock);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a file system based Lucene <see cref="Lucene.Net.Store.Directory"/> with the correct locking guidelines for Umbraco
|
||||
/// </summary>
|
||||
/// <param name="indexName">
|
||||
/// The folder name to store the index (single word, not a fully qualified folder) (i.e. Internal)
|
||||
/// </param>
|
||||
/// <returns></returns>
|
||||
public virtual Lucene.Net.Store.Directory CreateFileSystemLuceneDirectory(string indexName)
|
||||
/// Creates a directory factory based on the configured value and ensures that
|
||||
/// </summary>
|
||||
private IDirectoryFactory CreateFactory()
|
||||
{
|
||||
var dirInfo = _applicationRoot.ApplicationRoot;
|
||||
DirectoryInfo dirInfo = _applicationRoot.ApplicationRoot;
|
||||
|
||||
if (!dirInfo.Exists)
|
||||
{
|
||||
Directory.CreateDirectory(dirInfo.FullName);
|
||||
}
|
||||
|
||||
//check if there's a configured directory factory, if so create it and use that to create the lucene dir
|
||||
var configuredDirectoryFactory = _settings.LuceneDirectoryFactory;
|
||||
|
||||
if (!configuredDirectoryFactory.IsNullOrWhiteSpace())
|
||||
{
|
||||
//this should be a fully qualified type
|
||||
Type factoryType = _typeFinder.GetTypeByName(configuredDirectoryFactory);
|
||||
if (factoryType == null)
|
||||
{
|
||||
throw new InvalidOperationException("No directory type found for value: " + configuredDirectoryFactory);
|
||||
}
|
||||
|
||||
var directoryFactory = (IDirectoryFactory)ActivatorUtilities.CreateInstance(_services, factoryType);
|
||||
|
||||
return directoryFactory.CreateDirectory(indexName);
|
||||
switch (_settings.LuceneDirectoryFactory)
|
||||
{
|
||||
case LuceneDirectoryFactory.SyncedTempFileSystemDirectoryFactory:
|
||||
return _services.GetRequiredService<SyncedFileSystemDirectoryFactory>();
|
||||
case LuceneDirectoryFactory.TempFileSystemDirectoryFactory:
|
||||
return _services.GetRequiredService<TempEnvFileSystemDirectoryFactory>();
|
||||
case LuceneDirectoryFactory.Default:
|
||||
default:
|
||||
return _services.GetRequiredService<FileSystemDirectoryFactory>();
|
||||
}
|
||||
|
||||
var fileSystemDirectoryFactory = new FileSystemDirectoryFactory(dirInfo, _lockFactory);
|
||||
return fileSystemDirectoryFactory.CreateDirectory(indexName);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,8 +3,10 @@ using Examine;
|
||||
using Examine.Lucene;
|
||||
using Examine.Lucene.Analyzers;
|
||||
using Lucene.Net.Analysis.Standard;
|
||||
using Lucene.Net.Index;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Umbraco.Cms.Core;
|
||||
using Umbraco.Cms.Core.Configuration.Models;
|
||||
|
||||
namespace Umbraco.Cms.Infrastructure.Examine.DependencyInjection
|
||||
{
|
||||
@@ -14,9 +16,15 @@ namespace Umbraco.Cms.Infrastructure.Examine.DependencyInjection
|
||||
public sealed class ConfigureIndexOptions : IConfigureNamedOptions<LuceneDirectoryIndexOptions>
|
||||
{
|
||||
private readonly IUmbracoIndexConfig _umbracoIndexConfig;
|
||||
private readonly IOptions<IndexCreatorSettings> _settings;
|
||||
|
||||
public ConfigureIndexOptions(IUmbracoIndexConfig umbracoIndexConfig)
|
||||
=> _umbracoIndexConfig = umbracoIndexConfig;
|
||||
public ConfigureIndexOptions(
|
||||
IUmbracoIndexConfig umbracoIndexConfig,
|
||||
IOptions<IndexCreatorSettings> settings)
|
||||
{
|
||||
_umbracoIndexConfig = umbracoIndexConfig;
|
||||
_settings = settings;
|
||||
}
|
||||
|
||||
public void Configure(string name, LuceneDirectoryIndexOptions options)
|
||||
{
|
||||
@@ -38,6 +46,17 @@ namespace Umbraco.Cms.Infrastructure.Examine.DependencyInjection
|
||||
options.FieldDefinitions = new UmbracoFieldDefinitionCollection();
|
||||
break;
|
||||
}
|
||||
|
||||
// ensure indexes are unlocked on startup
|
||||
options.UnlockIndex = true;
|
||||
|
||||
if (_settings.Value.LuceneDirectoryFactory == LuceneDirectoryFactory.SyncedTempFileSystemDirectoryFactory)
|
||||
{
|
||||
// if this directory factory is enabled then a snapshot deletion policy is required
|
||||
options.IndexDeletionPolicy = new SnapshotDeletionPolicy(new KeepOnlyLastCommitDeletionPolicy());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void Configure(LuceneDirectoryIndexOptions options)
|
||||
|
||||
@@ -10,6 +10,8 @@ using Lucene.Net.Analysis.Core;
|
||||
using Lucene.Net.Index;
|
||||
using Lucene.Net.QueryParsers.Classic;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Umbraco.Cms.Core.Composing;
|
||||
using Umbraco.Cms.Core.Configuration.Models;
|
||||
using Umbraco.Cms.Core.Runtime;
|
||||
using Umbraco.Cms.Infrastructure.Examine;
|
||||
|
||||
|
||||
@@ -4,9 +4,11 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Examine.Lucene;
|
||||
using Examine.Lucene.Providers;
|
||||
using Lucene.Net.Store;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Umbraco.Cms.Core;
|
||||
using Umbraco.Cms.Core.Hosting;
|
||||
using Umbraco.Extensions;
|
||||
@@ -16,10 +18,16 @@ namespace Umbraco.Cms.Infrastructure.Examine
|
||||
public class LuceneIndexDiagnostics : IIndexDiagnostics
|
||||
{
|
||||
private readonly IHostingEnvironment _hostingEnvironment;
|
||||
private readonly LuceneDirectoryIndexOptions _indexOptions;
|
||||
|
||||
public LuceneIndexDiagnostics(LuceneIndex index, ILogger<LuceneIndexDiagnostics> logger, IHostingEnvironment hostingEnvironment)
|
||||
public LuceneIndexDiagnostics(
|
||||
LuceneIndex index,
|
||||
ILogger<LuceneIndexDiagnostics> logger,
|
||||
IHostingEnvironment hostingEnvironment,
|
||||
IOptionsSnapshot<LuceneDirectoryIndexOptions> indexOptions)
|
||||
{
|
||||
_hostingEnvironment = hostingEnvironment;
|
||||
_indexOptions = indexOptions.Get(index.Name);
|
||||
Index = index;
|
||||
Logger = logger;
|
||||
}
|
||||
@@ -43,7 +51,7 @@ namespace Umbraco.Cms.Infrastructure.Examine
|
||||
{
|
||||
get
|
||||
{
|
||||
var luceneDir = Index.GetLuceneDirectory();
|
||||
Directory luceneDir = Index.GetLuceneDirectory();
|
||||
var d = new Dictionary<string, object>
|
||||
{
|
||||
[nameof(UmbracoExamineIndex.CommitCount)] = Index.CommitCount,
|
||||
@@ -58,6 +66,20 @@ namespace Umbraco.Cms.Infrastructure.Examine
|
||||
d[nameof(UmbracoExamineIndex.LuceneIndexFolder)] = fsDir.Directory.ToString().ToLowerInvariant().TrimStart(rootDir.ToLowerInvariant()).Replace("\\", "/").EnsureStartsWith('/');
|
||||
}
|
||||
|
||||
if (_indexOptions != null)
|
||||
{
|
||||
if (_indexOptions.DirectoryFactory != null)
|
||||
{
|
||||
d[nameof(LuceneDirectoryIndexOptions.DirectoryFactory)] = _indexOptions.DirectoryFactory.GetType();
|
||||
}
|
||||
|
||||
if (_indexOptions.IndexDeletionPolicy != null)
|
||||
{
|
||||
d[nameof(LuceneDirectoryIndexOptions.IndexDeletionPolicy)] = _indexOptions.IndexDeletionPolicy.GetType();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return d;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,13 @@
|
||||
// Copyright (c) Umbraco.
|
||||
// See LICENSE for more details.
|
||||
|
||||
using System;
|
||||
using Examine;
|
||||
using Examine.Lucene;
|
||||
using Examine.Lucene.Providers;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Umbraco.Cms.Core.Hosting;
|
||||
|
||||
namespace Umbraco.Cms.Infrastructure.Examine
|
||||
@@ -17,7 +21,9 @@ namespace Umbraco.Cms.Infrastructure.Examine
|
||||
private readonly ILoggerFactory _loggerFactory;
|
||||
private readonly IHostingEnvironment _hostingEnvironment;
|
||||
|
||||
public LuceneIndexDiagnosticsFactory(ILoggerFactory loggerFactory, IHostingEnvironment hostingEnvironment)
|
||||
public LuceneIndexDiagnosticsFactory(
|
||||
ILoggerFactory loggerFactory,
|
||||
IHostingEnvironment hostingEnvironment)
|
||||
{
|
||||
_loggerFactory = loggerFactory;
|
||||
_hostingEnvironment = hostingEnvironment;
|
||||
@@ -29,7 +35,11 @@ namespace Umbraco.Cms.Infrastructure.Examine
|
||||
{
|
||||
if (index is LuceneIndex luceneIndex)
|
||||
{
|
||||
indexDiag = new LuceneIndexDiagnostics(luceneIndex, _loggerFactory.CreateLogger<LuceneIndexDiagnostics>(), _hostingEnvironment);
|
||||
indexDiag = new LuceneIndexDiagnostics(
|
||||
luceneIndex,
|
||||
_loggerFactory.CreateLogger<LuceneIndexDiagnostics>(),
|
||||
_hostingEnvironment,
|
||||
null);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -3,19 +3,23 @@
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using Examine.Lucene.Directories;
|
||||
using Examine.Lucene.Providers;
|
||||
using Lucene.Net.Store;
|
||||
using Directory = Lucene.Net.Store.Directory;
|
||||
|
||||
namespace Umbraco.Cms.Infrastructure.Examine
|
||||
{
|
||||
public class LuceneRAMDirectoryFactory : IDirectoryFactory
|
||||
public class LuceneRAMDirectoryFactory : DirectoryFactoryBase
|
||||
{
|
||||
|
||||
public LuceneRAMDirectoryFactory()
|
||||
{
|
||||
}
|
||||
|
||||
public Directory CreateDirectory(string indexName) => new RandomIdRAMDirectory();
|
||||
protected override Directory CreateDirectory(LuceneIndex luceneIndex, bool forceUnlock)
|
||||
=> new RandomIdRAMDirectory();
|
||||
|
||||
private class RandomIdRAMDirectory : RAMDirectory
|
||||
{
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
<RootNamespace>Umbraco.Cms.Infrastructure.Examine</RootNamespace>
|
||||
@@ -21,7 +21,11 @@
|
||||
<None Remove="obj\**" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Examine" Version="2.0.0-beta.136" />
|
||||
<ProjectReference Include="..\Umbraco.Core\Umbraco.Core.csproj" />
|
||||
<ProjectReference Include="..\Umbraco.Infrastructure\Umbraco.Infrastructure.csproj" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Examine" Version="2.0.0-beta.150" />
|
||||
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
|
||||
@@ -38,7 +38,7 @@ namespace Umbraco.Cms.Infrastructure.Examine
|
||||
: base(loggerFactory, name, indexOptions)
|
||||
{
|
||||
_runtimeState = runtimeState;
|
||||
_diagnostics = new UmbracoExamineIndexDiagnostics(this, loggerFactory.CreateLogger<UmbracoExamineIndexDiagnostics>(), hostingEnvironment);
|
||||
_diagnostics = new UmbracoExamineIndexDiagnostics(this, loggerFactory.CreateLogger<UmbracoExamineIndexDiagnostics>(), hostingEnvironment, indexOptions);
|
||||
_logger = loggerFactory.CreateLogger<UmbracoExamineIndex>();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
// Copyright (c) Umbraco.
|
||||
// Copyright (c) Umbraco.
|
||||
// See LICENSE for more details.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Examine.Lucene;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Umbraco.Cms.Core.Hosting;
|
||||
|
||||
namespace Umbraco.Cms.Infrastructure.Examine
|
||||
@@ -12,8 +14,12 @@ namespace Umbraco.Cms.Infrastructure.Examine
|
||||
{
|
||||
private readonly UmbracoExamineIndex _index;
|
||||
|
||||
public UmbracoExamineIndexDiagnostics(UmbracoExamineIndex index, ILogger<UmbracoExamineIndexDiagnostics> logger, IHostingEnvironment hostingEnvironment)
|
||||
: base(index, logger, hostingEnvironment)
|
||||
public UmbracoExamineIndexDiagnostics(
|
||||
UmbracoExamineIndex index,
|
||||
ILogger<UmbracoExamineIndexDiagnostics> logger,
|
||||
IHostingEnvironment hostingEnvironment,
|
||||
IOptionsSnapshot<LuceneDirectoryIndexOptions> indexOptions)
|
||||
: base(index, logger, hostingEnvironment, indexOptions)
|
||||
{
|
||||
_index = index;
|
||||
}
|
||||
|
||||
@@ -93,10 +93,18 @@ namespace Umbraco.Cms.Infrastructure.Examine
|
||||
|
||||
if (useBackgroundThread)
|
||||
{
|
||||
_logger.LogInformation($"Starting async background thread for {nameof(RebuildIndexes)}.");
|
||||
_logger.LogDebug($"Queuing background job for {nameof(RebuildIndexes)}.");
|
||||
|
||||
_backgroundTaskQueue.QueueBackgroundWorkItem(
|
||||
cancellationToken => Task.Run(() => RebuildIndexes(onlyEmptyIndexes, delay.Value, cancellationToken)));
|
||||
cancellationToken =>
|
||||
{
|
||||
// This is a fire/forget task spawned by the background thread queue (which means we
|
||||
// don't need to worry about ExecutionContext flowing).
|
||||
Task.Run(() => RebuildIndexes(onlyEmptyIndexes, delay.Value, cancellationToken));
|
||||
|
||||
// immediately return so the queue isn't waiting.
|
||||
return Task.CompletedTask;
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -162,8 +170,9 @@ namespace Umbraco.Cms.Infrastructure.Examine
|
||||
}
|
||||
else
|
||||
{
|
||||
// If an index exists but it has zero docs we'll consider it empty and rebuild
|
||||
IIndex[] indexes = (onlyEmptyIndexes
|
||||
? _examineManager.Indexes.Where(x => !x.IndexExists())
|
||||
? _examineManager.Indexes.Where(x => !x.IndexExists() || (x is IIndexStats stats && stats.GetDocumentCount() == 0))
|
||||
: _examineManager.Indexes).ToArray();
|
||||
|
||||
if (indexes.Length == 0)
|
||||
|
||||
@@ -242,34 +242,35 @@ namespace Umbraco.Cms.Infrastructure.Examine
|
||||
private class DeferedReIndexForContent : DeferedAction
|
||||
{
|
||||
private readonly IBackgroundTaskQueue _backgroundTaskQueue;
|
||||
private readonly ExamineUmbracoIndexingHandler _ExamineUmbracoIndexingHandler;
|
||||
private readonly ExamineUmbracoIndexingHandler _examineUmbracoIndexingHandler;
|
||||
private readonly IContent _content;
|
||||
private readonly bool _isPublished;
|
||||
|
||||
public DeferedReIndexForContent(IBackgroundTaskQueue backgroundTaskQueue, ExamineUmbracoIndexingHandler ExamineUmbracoIndexingHandler, IContent content, bool isPublished)
|
||||
public DeferedReIndexForContent(IBackgroundTaskQueue backgroundTaskQueue, ExamineUmbracoIndexingHandler examineUmbracoIndexingHandler, IContent content, bool isPublished)
|
||||
{
|
||||
_backgroundTaskQueue = backgroundTaskQueue;
|
||||
_ExamineUmbracoIndexingHandler = ExamineUmbracoIndexingHandler;
|
||||
_examineUmbracoIndexingHandler = examineUmbracoIndexingHandler;
|
||||
_content = content;
|
||||
_isPublished = isPublished;
|
||||
}
|
||||
|
||||
public override void Execute() => Execute(_backgroundTaskQueue, _ExamineUmbracoIndexingHandler, _content, _isPublished);
|
||||
public override void Execute() => Execute(_backgroundTaskQueue, _examineUmbracoIndexingHandler, _content, _isPublished);
|
||||
|
||||
public static void Execute(IBackgroundTaskQueue backgroundTaskQueue, ExamineUmbracoIndexingHandler ExamineUmbracoIndexingHandler, IContent content, bool isPublished)
|
||||
public static void Execute(IBackgroundTaskQueue backgroundTaskQueue, ExamineUmbracoIndexingHandler examineUmbracoIndexingHandler, IContent content, bool isPublished)
|
||||
=> backgroundTaskQueue.QueueBackgroundWorkItem(cancellationToken =>
|
||||
{
|
||||
using IScope scope = ExamineUmbracoIndexingHandler._scopeProvider.CreateScope(autoComplete: true);
|
||||
using IScope scope = examineUmbracoIndexingHandler._scopeProvider.CreateScope(autoComplete: true);
|
||||
|
||||
// for content we have a different builder for published vs unpublished
|
||||
// we don't want to build more value sets than is needed so we'll lazily build 2 one for published one for non-published
|
||||
var builders = new Dictionary<bool, Lazy<List<ValueSet>>>
|
||||
{
|
||||
[true] = new Lazy<List<ValueSet>>(() => ExamineUmbracoIndexingHandler._publishedContentValueSetBuilder.GetValueSets(content).ToList()),
|
||||
[false] = new Lazy<List<ValueSet>>(() => ExamineUmbracoIndexingHandler._contentValueSetBuilder.GetValueSets(content).ToList())
|
||||
[true] = new Lazy<List<ValueSet>>(() => examineUmbracoIndexingHandler._publishedContentValueSetBuilder.GetValueSets(content).ToList()),
|
||||
[false] = new Lazy<List<ValueSet>>(() => examineUmbracoIndexingHandler._contentValueSetBuilder.GetValueSets(content).ToList())
|
||||
};
|
||||
|
||||
foreach (IUmbracoIndex index in ExamineUmbracoIndexingHandler._examineManager.Indexes.OfType<IUmbracoIndex>()
|
||||
// This is only for content - so only index items for IUmbracoContentIndex (to exlude members)
|
||||
foreach (IUmbracoIndex index in examineUmbracoIndexingHandler._examineManager.Indexes.OfType<IUmbracoContentIndex>()
|
||||
//filter the indexers
|
||||
.Where(x => isPublished || !x.PublishedValuesOnly)
|
||||
.Where(x => x.EnableDefaultEventHandler))
|
||||
@@ -293,29 +294,30 @@ namespace Umbraco.Cms.Infrastructure.Examine
|
||||
private class DeferedReIndexForMedia : DeferedAction
|
||||
{
|
||||
private readonly IBackgroundTaskQueue _backgroundTaskQueue;
|
||||
private readonly ExamineUmbracoIndexingHandler _ExamineUmbracoIndexingHandler;
|
||||
private readonly ExamineUmbracoIndexingHandler _examineUmbracoIndexingHandler;
|
||||
private readonly IMedia _media;
|
||||
private readonly bool _isPublished;
|
||||
|
||||
public DeferedReIndexForMedia(IBackgroundTaskQueue backgroundTaskQueue, ExamineUmbracoIndexingHandler ExamineUmbracoIndexingHandler, IMedia media, bool isPublished)
|
||||
public DeferedReIndexForMedia(IBackgroundTaskQueue backgroundTaskQueue, ExamineUmbracoIndexingHandler examineUmbracoIndexingHandler, IMedia media, bool isPublished)
|
||||
{
|
||||
_backgroundTaskQueue = backgroundTaskQueue;
|
||||
_ExamineUmbracoIndexingHandler = ExamineUmbracoIndexingHandler;
|
||||
_examineUmbracoIndexingHandler = examineUmbracoIndexingHandler;
|
||||
_media = media;
|
||||
_isPublished = isPublished;
|
||||
}
|
||||
|
||||
public override void Execute() => Execute(_backgroundTaskQueue, _ExamineUmbracoIndexingHandler, _media, _isPublished);
|
||||
public override void Execute() => Execute(_backgroundTaskQueue, _examineUmbracoIndexingHandler, _media, _isPublished);
|
||||
|
||||
public static void Execute(IBackgroundTaskQueue backgroundTaskQueue, ExamineUmbracoIndexingHandler ExamineUmbracoIndexingHandler, IMedia media, bool isPublished) =>
|
||||
public static void Execute(IBackgroundTaskQueue backgroundTaskQueue, ExamineUmbracoIndexingHandler examineUmbracoIndexingHandler, IMedia media, bool isPublished) =>
|
||||
// perform the ValueSet lookup on a background thread
|
||||
backgroundTaskQueue.QueueBackgroundWorkItem(cancellationToken =>
|
||||
{
|
||||
using IScope scope = ExamineUmbracoIndexingHandler._scopeProvider.CreateScope(autoComplete: true);
|
||||
using IScope scope = examineUmbracoIndexingHandler._scopeProvider.CreateScope(autoComplete: true);
|
||||
|
||||
var valueSet = ExamineUmbracoIndexingHandler._mediaValueSetBuilder.GetValueSets(media).ToList();
|
||||
var valueSet = examineUmbracoIndexingHandler._mediaValueSetBuilder.GetValueSets(media).ToList();
|
||||
|
||||
foreach (IUmbracoIndex index in ExamineUmbracoIndexingHandler._examineManager.Indexes.OfType<IUmbracoIndex>()
|
||||
// This is only for content - so only index items for IUmbracoContentIndex (to exlude members)
|
||||
foreach (IUmbracoIndex index in examineUmbracoIndexingHandler._examineManager.Indexes.OfType<IUmbracoContentIndex>()
|
||||
//filter the indexers
|
||||
.Where(x => isPublished || !x.PublishedValuesOnly)
|
||||
.Where(x => x.EnableDefaultEventHandler))
|
||||
@@ -332,27 +334,29 @@ namespace Umbraco.Cms.Infrastructure.Examine
|
||||
/// </summary>
|
||||
private class DeferedReIndexForMember : DeferedAction
|
||||
{
|
||||
private readonly ExamineUmbracoIndexingHandler _ExamineUmbracoIndexingHandler;
|
||||
private readonly ExamineUmbracoIndexingHandler _examineUmbracoIndexingHandler;
|
||||
private readonly IMember _member;
|
||||
private readonly IBackgroundTaskQueue _backgroundTaskQueue;
|
||||
|
||||
public DeferedReIndexForMember(IBackgroundTaskQueue backgroundTaskQueue, ExamineUmbracoIndexingHandler ExamineUmbracoIndexingHandler, IMember member)
|
||||
public DeferedReIndexForMember(IBackgroundTaskQueue backgroundTaskQueue, ExamineUmbracoIndexingHandler examineUmbracoIndexingHandler, IMember member)
|
||||
{
|
||||
_ExamineUmbracoIndexingHandler = ExamineUmbracoIndexingHandler;
|
||||
_examineUmbracoIndexingHandler = examineUmbracoIndexingHandler;
|
||||
_member = member;
|
||||
_backgroundTaskQueue = backgroundTaskQueue;
|
||||
}
|
||||
|
||||
public override void Execute() => Execute(_backgroundTaskQueue, _ExamineUmbracoIndexingHandler, _member);
|
||||
public override void Execute() => Execute(_backgroundTaskQueue, _examineUmbracoIndexingHandler, _member);
|
||||
|
||||
public static void Execute(IBackgroundTaskQueue backgroundTaskQueue, ExamineUmbracoIndexingHandler ExamineUmbracoIndexingHandler, IMember member) =>
|
||||
public static void Execute(IBackgroundTaskQueue backgroundTaskQueue, ExamineUmbracoIndexingHandler examineUmbracoIndexingHandler, IMember member) =>
|
||||
// perform the ValueSet lookup on a background thread
|
||||
backgroundTaskQueue.QueueBackgroundWorkItem(cancellationToken =>
|
||||
{
|
||||
using IScope scope = ExamineUmbracoIndexingHandler._scopeProvider.CreateScope(autoComplete: true);
|
||||
using IScope scope = examineUmbracoIndexingHandler._scopeProvider.CreateScope(autoComplete: true);
|
||||
|
||||
var valueSet = ExamineUmbracoIndexingHandler._memberValueSetBuilder.GetValueSets(member).ToList();
|
||||
foreach (IUmbracoIndex index in ExamineUmbracoIndexingHandler._examineManager.Indexes.OfType<IUmbracoIndex>()
|
||||
var valueSet = examineUmbracoIndexingHandler._memberValueSetBuilder.GetValueSets(member).ToList();
|
||||
|
||||
// only process for IUmbracoMemberIndex (not content indexes)
|
||||
foreach (IUmbracoIndex index in examineUmbracoIndexingHandler._examineManager.Indexes.OfType<IUmbracoMemberIndex>()
|
||||
//filter the indexers
|
||||
.Where(x => x.EnableDefaultEventHandler))
|
||||
{
|
||||
@@ -365,23 +369,23 @@ namespace Umbraco.Cms.Infrastructure.Examine
|
||||
|
||||
private class DeferedDeleteIndex : DeferedAction
|
||||
{
|
||||
private readonly ExamineUmbracoIndexingHandler _ExamineUmbracoIndexingHandler;
|
||||
private readonly ExamineUmbracoIndexingHandler _examineUmbracoIndexingHandler;
|
||||
private readonly int _id;
|
||||
private readonly bool _keepIfUnpublished;
|
||||
|
||||
public DeferedDeleteIndex(ExamineUmbracoIndexingHandler ExamineUmbracoIndexingHandler, int id, bool keepIfUnpublished)
|
||||
public DeferedDeleteIndex(ExamineUmbracoIndexingHandler examineUmbracoIndexingHandler, int id, bool keepIfUnpublished)
|
||||
{
|
||||
_ExamineUmbracoIndexingHandler = ExamineUmbracoIndexingHandler;
|
||||
_examineUmbracoIndexingHandler = examineUmbracoIndexingHandler;
|
||||
_id = id;
|
||||
_keepIfUnpublished = keepIfUnpublished;
|
||||
}
|
||||
|
||||
public override void Execute() => Execute(_ExamineUmbracoIndexingHandler, _id, _keepIfUnpublished);
|
||||
public override void Execute() => Execute(_examineUmbracoIndexingHandler, _id, _keepIfUnpublished);
|
||||
|
||||
public static void Execute(ExamineUmbracoIndexingHandler ExamineUmbracoIndexingHandler, int id, bool keepIfUnpublished)
|
||||
public static void Execute(ExamineUmbracoIndexingHandler examineUmbracoIndexingHandler, int id, bool keepIfUnpublished)
|
||||
{
|
||||
var strId = id.ToString(CultureInfo.InvariantCulture);
|
||||
foreach (var index in ExamineUmbracoIndexingHandler._examineManager.Indexes.OfType<IUmbracoIndex>()
|
||||
foreach (var index in examineUmbracoIndexingHandler._examineManager.Indexes.OfType<IUmbracoIndex>()
|
||||
.Where(x => x.PublishedValuesOnly || !keepIfUnpublished)
|
||||
.Where(x => x.EnableDefaultEventHandler))
|
||||
{
|
||||
|
||||
@@ -5,8 +5,7 @@ namespace Umbraco.Cms.Infrastructure.Examine
|
||||
/// <summary>
|
||||
/// Marker interface for indexes of Umbraco content
|
||||
/// </summary>
|
||||
public interface IUmbracoContentIndex : IIndex
|
||||
public interface IUmbracoContentIndex : IUmbracoIndex
|
||||
{
|
||||
bool PublishedValuesOnly { get; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ using Examine;
|
||||
|
||||
namespace Umbraco.Cms.Infrastructure.Examine
|
||||
{
|
||||
public interface IUmbracoMemberIndex : IIndex
|
||||
public interface IUmbracoMemberIndex : IUmbracoIndex
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
@@ -66,7 +66,7 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Examine.Lucene" Version="2.0.0-beta.136" />
|
||||
<PackageReference Include="Examine.Lucene" Version="2.0.0-beta.150" />
|
||||
<PackageReference Include="Microsoft.AspNet.WebApi.Client" Version="5.2.7" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="5.0.6" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.4" />
|
||||
|
||||
Reference in New Issue
Block a user