latest examine, tweaks to UmbracoFieldDefinitionCollection, adds some test code for testing
This commit is contained in:
@@ -5,7 +5,7 @@ namespace Umbraco.Examine
|
||||
/// <summary>
|
||||
/// A Marker interface for defining an Umbraco indexer
|
||||
/// </summary>
|
||||
public interface IUmbracoIndexer : IIndex
|
||||
public interface IUmbracoIndex : IIndex
|
||||
{
|
||||
/// <summary>
|
||||
/// When set to true Umbraco will keep the index in sync with Umbraco data automatically
|
||||
@@ -48,7 +48,7 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<!-- note: NuGet deals with transitive references now -->
|
||||
<PackageReference Include="Examine" Version="1.0.0-beta046" />
|
||||
<PackageReference Include="Examine" Version="1.0.0-beta050" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
|
||||
<PackageReference Include="NPoco" Version="3.9.4" />
|
||||
</ItemGroup>
|
||||
@@ -72,7 +72,7 @@
|
||||
<Compile Include="IndexPopulator.cs" />
|
||||
<Compile Include="IndexRebuilder.cs" />
|
||||
<Compile Include="IPublishedContentValueSetBuilder.cs" />
|
||||
<Compile Include="IUmbracoIndexer.cs" />
|
||||
<Compile Include="IUmbracoIndex.cs" />
|
||||
<Compile Include="IValueSetBuilder.cs" />
|
||||
<Compile Include="MediaIndexPopulator.cs" />
|
||||
<Compile Include="MediaValueSetBuilder.cs" />
|
||||
|
||||
@@ -18,6 +18,45 @@ using Examine.LuceneEngine;
|
||||
|
||||
namespace Umbraco.Examine
|
||||
{
|
||||
/// <summary>
|
||||
/// Custom <see cref="FieldDefinitionCollection"/> allowing dynamic creation of <see cref="FieldDefinition"/>
|
||||
/// </summary>
|
||||
public class UmbracoFieldDefinitionCollection : FieldDefinitionCollection
|
||||
{
|
||||
|
||||
public UmbracoFieldDefinitionCollection()
|
||||
: base(UmbracoExamineIndex.UmbracoIndexFieldDefinitions)
|
||||
{
|
||||
}
|
||||
|
||||
///// <summary>
|
||||
///// Overridden to dynamically add field definitions for culture variations
|
||||
///// </summary>
|
||||
///// <param name="fieldName"></param>
|
||||
///// <param name="fieldDefinition"></param>
|
||||
///// <returns></returns>
|
||||
//public override bool TryGetValue(string fieldName, out FieldDefinition fieldDefinition)
|
||||
//{
|
||||
// var result = base.TryGetValue(fieldName, out fieldDefinition);
|
||||
// if (result) return true;
|
||||
|
||||
// //if the fieldName is not suffixed with _iso-Code
|
||||
// var underscoreIndex = fieldName.LastIndexOf('_');
|
||||
// if (underscoreIndex == -1) return false;
|
||||
|
||||
|
||||
|
||||
// var isoCode = fieldName.Substring(underscoreIndex);
|
||||
// if (isoCode.Length < 6) return false; //invalid isoCode
|
||||
|
||||
// var hyphenIndex = isoCode.IndexOf('-');
|
||||
// if (hyphenIndex != 3) return false; //invalid isoCode
|
||||
|
||||
// //we'll assume this is a valid isoCode
|
||||
|
||||
//}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// An indexer for Umbraco content and media
|
||||
/// </summary>
|
||||
@@ -52,7 +91,7 @@ namespace Umbraco.Examine
|
||||
/// <param name="indexValueTypes"></param>
|
||||
public UmbracoContentIndex(
|
||||
string name,
|
||||
IEnumerable<FieldDefinition> fieldDefinitions,
|
||||
FieldDefinitionCollection fieldDefinitions,
|
||||
Directory luceneDirectory,
|
||||
Analyzer defaultAnalyzer,
|
||||
ProfilingLogger profilingLogger,
|
||||
@@ -214,27 +253,6 @@ namespace Umbraco.Examine
|
||||
|
||||
base.PerformDeleteFromIndex(nodeId, onComplete);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Overridden to ensure that the variant system fields have the right value types
|
||||
/// </summary>
|
||||
/// <param name="x"></param>
|
||||
/// <param name="indexValueTypesFactory"></param>
|
||||
/// <returns></returns>
|
||||
protected override FieldValueTypeCollection CreateFieldValueTypes(IReadOnlyDictionary<string, Func<string, IIndexValueType>> indexValueTypesFactory = null)
|
||||
{
|
||||
//fixme: languages are dynamic so although this will work on startup it wont work when languages are edited
|
||||
foreach(var lang in LanguageService.GetAllLanguages())
|
||||
{
|
||||
foreach (var field in UmbracoIndexFieldDefinitions)
|
||||
{
|
||||
var def = new FieldDefinition($"{field.Name}_{lang.IsoCode.ToLowerInvariant()}", field.Type);
|
||||
FieldDefinitionCollection.TryAdd(def.Name, def);
|
||||
}
|
||||
}
|
||||
|
||||
return base.CreateFieldValueTypes(indexValueTypesFactory);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ namespace Umbraco.Examine
|
||||
/// An abstract provider containing the basic functionality to be able to query against
|
||||
/// Umbraco data.
|
||||
/// </summary>
|
||||
public abstract class UmbracoExamineIndex : LuceneIndex, IUmbracoIndexer, IIndexDiagnostics
|
||||
public abstract class UmbracoExamineIndex : LuceneIndex, IUmbracoIndex, IIndexDiagnostics
|
||||
{
|
||||
// note
|
||||
// wrapping all operations that end up calling base.SafelyProcessQueueItems in a safe call
|
||||
@@ -67,7 +67,7 @@ namespace Umbraco.Examine
|
||||
/// <param name="indexValueTypes"></param>
|
||||
protected UmbracoExamineIndex(
|
||||
string name,
|
||||
IEnumerable<FieldDefinition> fieldDefinitions,
|
||||
FieldDefinitionCollection fieldDefinitions,
|
||||
Directory luceneDirectory,
|
||||
Analyzer defaultAnalyzer,
|
||||
ProfilingLogger profilingLogger,
|
||||
|
||||
@@ -42,8 +42,8 @@ namespace Umbraco.Examine
|
||||
/// <param name="validator"></param>
|
||||
/// <param name="analyzer"></param>
|
||||
public UmbracoMemberIndex(
|
||||
string name,
|
||||
IEnumerable<FieldDefinition> fieldDefinitions,
|
||||
string name,
|
||||
FieldDefinitionCollection fieldDefinitions,
|
||||
Directory luceneDirectory,
|
||||
Analyzer analyzer,
|
||||
ProfilingLogger profilingLogger,
|
||||
|
||||
@@ -77,7 +77,7 @@
|
||||
<ItemGroup>
|
||||
<PackageReference Include="AutoMapper" Version="7.0.1" />
|
||||
<PackageReference Include="Castle.Core" Version="4.2.1" />
|
||||
<PackageReference Include="Examine" Version="1.0.0-beta046" />
|
||||
<PackageReference Include="Examine" Version="1.0.0-beta050" />
|
||||
<PackageReference Include="HtmlAgilityPack">
|
||||
<Version>1.8.9</Version>
|
||||
</PackageReference>
|
||||
|
||||
@@ -164,7 +164,7 @@ namespace Umbraco.Tests.UmbracoExamine
|
||||
|
||||
var i = new UmbracoContentIndex(
|
||||
"testIndexer",
|
||||
UmbracoExamineIndex.UmbracoIndexFieldDefinitions,
|
||||
new UmbracoFieldDefinitionCollection(),
|
||||
luceneDir,
|
||||
analyzer,
|
||||
profilingLogger,
|
||||
|
||||
@@ -88,7 +88,7 @@
|
||||
<PackageReference Include="CSharpTest.Net.Collections" Version="14.906.1403.1082" />
|
||||
<PackageReference Include="ClientDependency" Version="1.9.7" />
|
||||
<PackageReference Include="ClientDependency-Mvc5" Version="1.8.0.0" />
|
||||
<PackageReference Include="Examine" Version="1.0.0-beta046" />
|
||||
<PackageReference Include="Examine" Version="1.0.0-beta050" />
|
||||
<PackageReference Include="ImageProcessor.Web" Version="4.9.3.25" />
|
||||
<PackageReference Include="ImageProcessor.Web.Config" Version="2.4.1.19" />
|
||||
<PackageReference Include="Microsoft.AspNet.Identity.Owin" Version="2.2.2" />
|
||||
|
||||
@@ -75,7 +75,7 @@ namespace Umbraco.Web.Editors
|
||||
|
||||
var results = Examine.ExamineExtensions.TryParseLuceneQuery(query)
|
||||
? searcher.Search(searcher.CreateCriteria().RawQuery(query), maxResults: pageSize * (pageIndex + 1))
|
||||
: searcher.Search(query, true, maxResults: pageSize * (pageIndex + 1));
|
||||
: searcher.Search(query, maxResults: pageSize * (pageIndex + 1));
|
||||
|
||||
var pagedResults = results.Skip(pageIndex * pageSize);
|
||||
|
||||
|
||||
@@ -243,8 +243,8 @@ namespace Umbraco.Web
|
||||
var searcher = index.GetSearcher();
|
||||
|
||||
var results = skip == 0 && take == 0
|
||||
? searcher.Search(term, true)
|
||||
: searcher.Search(term, true, maxResults: skip + take);
|
||||
? searcher.Search(term)
|
||||
: searcher.Search(term, maxResults: skip + take);
|
||||
|
||||
totalRecords = results.TotalItemCount;
|
||||
return results.ToPublishedSearchResults(_contentCache);
|
||||
|
||||
@@ -149,7 +149,7 @@ namespace Umbraco.Web.Search
|
||||
|
||||
profilingLogger.Logger.Debug<ExamineComponent>("Examine shutdown registered with MainDom");
|
||||
|
||||
var registeredIndexers = examineManager.Indexes.OfType<IUmbracoIndexer>().Count(x => x.EnableDefaultEventHandler);
|
||||
var registeredIndexers = examineManager.Indexes.OfType<IUmbracoIndex>().Count(x => x.EnableDefaultEventHandler);
|
||||
|
||||
profilingLogger.Logger.Info<ExamineComponent>("Adding examine event handlers for {RegisteredIndexers} index providers.", registeredIndexers);
|
||||
|
||||
@@ -166,9 +166,19 @@ namespace Umbraco.Web.Search
|
||||
|
||||
EnsureUnlocked(profilingLogger.Logger, examineManager);
|
||||
|
||||
//TODO: Instead of waiting 5000 ms, we could add an event handler on to fulfilling the first request, then start?
|
||||
RebuildIndexes(indexRebuilder, profilingLogger.Logger, true, 5000);
|
||||
}
|
||||
|
||||
private void TestExtending(IExamineManager examineManager)
|
||||
{
|
||||
if (examineManager.TryGetIndex("Test", out var index) && index is LuceneIndex umbIndex)
|
||||
{
|
||||
umbIndex.FieldValueTypeCollection.ValueTypeFactories.TryAdd()
|
||||
umbIndex.FieldDefinitionCollection.TryAdd("productName_es-es", new FieldDefinition("productName_es-es", ""));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Called to rebuild empty indexes on startup
|
||||
@@ -496,7 +506,7 @@ namespace Umbraco.Web.Search
|
||||
//Delete all content of this content/media/member type that is in any content indexer by looking up matched examine docs
|
||||
foreach (var id in ci.Value.removedIds)
|
||||
{
|
||||
foreach (var index in _examineManager.Indexes.OfType<IUmbracoIndexer>())
|
||||
foreach (var index in _examineManager.Indexes.OfType<IUmbracoIndex>())
|
||||
{
|
||||
var searcher = index.GetSearcher();
|
||||
|
||||
@@ -702,7 +712,7 @@ namespace Umbraco.Web.Search
|
||||
|
||||
public static void Execute(ExamineComponent examineComponent, IContent content, bool isPublished)
|
||||
{
|
||||
foreach (var index in examineComponent._examineManager.Indexes.OfType<IUmbracoIndexer>()
|
||||
foreach (var index in examineComponent._examineManager.Indexes.OfType<IUmbracoIndex>()
|
||||
//filter the indexers
|
||||
.Where(x => isPublished || !x.PublishedValuesOnly)
|
||||
.Where(x => x.EnableDefaultEventHandler))
|
||||
@@ -739,7 +749,7 @@ namespace Umbraco.Web.Search
|
||||
{
|
||||
var valueSet = examineComponent._mediaValueSetBuilder.GetValueSets(media).ToList();
|
||||
|
||||
foreach (var index in examineComponent._examineManager.Indexes.OfType<IUmbracoIndexer>()
|
||||
foreach (var index in examineComponent._examineManager.Indexes.OfType<IUmbracoIndex>()
|
||||
//filter the indexers
|
||||
.Where(x => isPublished || !x.PublishedValuesOnly)
|
||||
.Where(x => x.EnableDefaultEventHandler))
|
||||
@@ -768,7 +778,7 @@ namespace Umbraco.Web.Search
|
||||
public static void Execute(ExamineComponent examineComponent, IMember member)
|
||||
{
|
||||
var valueSet = examineComponent._memberValueSetBuilder.GetValueSets(member).ToList();
|
||||
foreach (var index in examineComponent._examineManager.Indexes.OfType<IUmbracoIndexer>()
|
||||
foreach (var index in examineComponent._examineManager.Indexes.OfType<IUmbracoIndex>()
|
||||
//filter the indexers
|
||||
.Where(x => x.EnableDefaultEventHandler))
|
||||
{
|
||||
@@ -798,7 +808,7 @@ namespace Umbraco.Web.Search
|
||||
public static void Execute(ExamineComponent examineComponent, int id, bool keepIfUnpublished)
|
||||
{
|
||||
var strId = id.ToString(CultureInfo.InvariantCulture);
|
||||
foreach (var index in examineComponent._examineManager.Indexes.OfType<IUmbracoIndexer>()
|
||||
foreach (var index in examineComponent._examineManager.Indexes.OfType<IUmbracoIndex>()
|
||||
|
||||
.Where(x => (keepIfUnpublished && !x.PublishedValuesOnly) || !keepIfUnpublished)
|
||||
.Where(x => x.EnableDefaultEventHandler))
|
||||
|
||||
@@ -33,7 +33,7 @@ namespace Umbraco.Web.Search
|
||||
try
|
||||
{
|
||||
var searcher = _index.GetSearcher();
|
||||
var result = searcher.Search("test", false);
|
||||
var result = searcher.Search("test");
|
||||
return Attempt<string>.Succeed(); //if we can search we'll assume it's healthy
|
||||
}
|
||||
catch (Exception e)
|
||||
|
||||
@@ -59,8 +59,7 @@ namespace Umbraco.Web.Search
|
||||
{
|
||||
var index = new UmbracoContentIndex(
|
||||
Constants.UmbracoIndexes.InternalIndexName,
|
||||
//fixme - how to deal with languages like in UmbracoContentIndexer.CreateFieldValueTypes
|
||||
UmbracoExamineIndex.UmbracoIndexFieldDefinitions,
|
||||
new UmbracoFieldDefinitionCollection(),
|
||||
CreateFileSystemLuceneDirectory(Constants.UmbracoIndexes.InternalIndexPath),
|
||||
new CultureInvariantWhitespaceAnalyzer(),
|
||||
ProfilingLogger,
|
||||
@@ -73,8 +72,7 @@ namespace Umbraco.Web.Search
|
||||
{
|
||||
var index = new UmbracoContentIndex(
|
||||
Constants.UmbracoIndexes.ExternalIndexName,
|
||||
//fixme - how to deal with languages like in UmbracoContentIndexer.CreateFieldValueTypes
|
||||
UmbracoExamineIndex.UmbracoIndexFieldDefinitions,
|
||||
new UmbracoFieldDefinitionCollection(),
|
||||
CreateFileSystemLuceneDirectory(Constants.UmbracoIndexes.ExternalIndexPath),
|
||||
new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_30),
|
||||
ProfilingLogger,
|
||||
@@ -87,8 +85,7 @@ namespace Umbraco.Web.Search
|
||||
{
|
||||
var index = new UmbracoMemberIndex(
|
||||
Constants.UmbracoIndexes.MembersIndexName,
|
||||
//fixme - how to deal with languages like in UmbracoContentIndexer.CreateFieldValueTypes
|
||||
UmbracoExamineIndex.UmbracoIndexFieldDefinitions,
|
||||
new UmbracoFieldDefinitionCollection(),
|
||||
CreateFileSystemLuceneDirectory(Constants.UmbracoIndexes.MembersIndexPath),
|
||||
new CultureInvariantWhitespaceAnalyzer(),
|
||||
ProfilingLogger,
|
||||
|
||||
@@ -62,7 +62,7 @@
|
||||
<PackageReference Include="AutoMapper" Version="7.0.1" />
|
||||
<PackageReference Include="ClientDependency" Version="1.9.7" />
|
||||
<PackageReference Include="CSharpTest.Net.Collections" Version="14.906.1403.1082" />
|
||||
<PackageReference Include="Examine" Version="1.0.0-beta046" />
|
||||
<PackageReference Include="Examine" Version="1.0.0-beta050" />
|
||||
<PackageReference Include="HtmlAgilityPack" Version="1.8.9" />
|
||||
<PackageReference Include="ImageProcessor">
|
||||
<Version>2.6.2.25</Version>
|
||||
|
||||
Reference in New Issue
Block a user