From c8b3f11498506f5072c71df96e7b820bf93eddf4 Mon Sep 17 00:00:00 2001 From: Shannon Date: Thu, 13 Dec 2018 15:04:18 +1100 Subject: [PATCH 01/11] latest examine, tweaks to UmbracoFieldDefinitionCollection, adds some test code for testing --- .../{IUmbracoIndexer.cs => IUmbracoIndex.cs} | 2 +- src/Umbraco.Examine/Umbraco.Examine.csproj | 4 +- src/Umbraco.Examine/UmbracoContentIndex.cs | 62 ++++++++++++------- src/Umbraco.Examine/UmbracoExamineIndex.cs | 4 +- src/Umbraco.Examine/UmbracoMemberIndex.cs | 4 +- src/Umbraco.Tests/Umbraco.Tests.csproj | 2 +- .../UmbracoExamine/IndexInitializer.cs | 2 +- src/Umbraco.Web.UI/Umbraco.Web.UI.csproj | 2 +- .../Editors/ExamineManagementController.cs | 2 +- src/Umbraco.Web/PublishedContentQuery.cs | 4 +- src/Umbraco.Web/Search/ExamineComponent.cs | 22 +++++-- .../Search/GenericIndexDiagnostics.cs | 2 +- .../Search/UmbracoIndexesCreator.cs | 9 +-- src/Umbraco.Web/Umbraco.Web.csproj | 2 +- 14 files changed, 74 insertions(+), 49 deletions(-) rename src/Umbraco.Examine/{IUmbracoIndexer.cs => IUmbracoIndex.cs} (94%) diff --git a/src/Umbraco.Examine/IUmbracoIndexer.cs b/src/Umbraco.Examine/IUmbracoIndex.cs similarity index 94% rename from src/Umbraco.Examine/IUmbracoIndexer.cs rename to src/Umbraco.Examine/IUmbracoIndex.cs index 00f772b1e2..e70652a342 100644 --- a/src/Umbraco.Examine/IUmbracoIndexer.cs +++ b/src/Umbraco.Examine/IUmbracoIndex.cs @@ -5,7 +5,7 @@ namespace Umbraco.Examine /// /// A Marker interface for defining an Umbraco indexer /// - public interface IUmbracoIndexer : IIndex + public interface IUmbracoIndex : IIndex { /// /// When set to true Umbraco will keep the index in sync with Umbraco data automatically diff --git a/src/Umbraco.Examine/Umbraco.Examine.csproj b/src/Umbraco.Examine/Umbraco.Examine.csproj index 66b1f09068..3c2f5a8ea6 100644 --- a/src/Umbraco.Examine/Umbraco.Examine.csproj +++ b/src/Umbraco.Examine/Umbraco.Examine.csproj @@ -48,7 +48,7 @@ - + @@ -72,7 +72,7 @@ - + diff --git a/src/Umbraco.Examine/UmbracoContentIndex.cs b/src/Umbraco.Examine/UmbracoContentIndex.cs index 910941ea7b..ac9683f3f2 100644 --- a/src/Umbraco.Examine/UmbracoContentIndex.cs +++ b/src/Umbraco.Examine/UmbracoContentIndex.cs @@ -18,6 +18,45 @@ using Examine.LuceneEngine; namespace Umbraco.Examine { + /// + /// Custom allowing dynamic creation of + /// + public class UmbracoFieldDefinitionCollection : FieldDefinitionCollection + { + + public UmbracoFieldDefinitionCollection() + : base(UmbracoExamineIndex.UmbracoIndexFieldDefinitions) + { + } + + ///// + ///// Overridden to dynamically add field definitions for culture variations + ///// + ///// + ///// + ///// + //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 + + //} + } + /// /// An indexer for Umbraco content and media /// @@ -52,7 +91,7 @@ namespace Umbraco.Examine /// public UmbracoContentIndex( string name, - IEnumerable fieldDefinitions, + FieldDefinitionCollection fieldDefinitions, Directory luceneDirectory, Analyzer defaultAnalyzer, ProfilingLogger profilingLogger, @@ -214,27 +253,6 @@ namespace Umbraco.Examine base.PerformDeleteFromIndex(nodeId, onComplete); } - - /// - /// Overridden to ensure that the variant system fields have the right value types - /// - /// - /// - /// - protected override FieldValueTypeCollection CreateFieldValueTypes(IReadOnlyDictionary> 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); - } } } diff --git a/src/Umbraco.Examine/UmbracoExamineIndex.cs b/src/Umbraco.Examine/UmbracoExamineIndex.cs index 15f1a75955..8d84e417d4 100644 --- a/src/Umbraco.Examine/UmbracoExamineIndex.cs +++ b/src/Umbraco.Examine/UmbracoExamineIndex.cs @@ -23,7 +23,7 @@ namespace Umbraco.Examine /// An abstract provider containing the basic functionality to be able to query against /// Umbraco data. /// - 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 /// protected UmbracoExamineIndex( string name, - IEnumerable fieldDefinitions, + FieldDefinitionCollection fieldDefinitions, Directory luceneDirectory, Analyzer defaultAnalyzer, ProfilingLogger profilingLogger, diff --git a/src/Umbraco.Examine/UmbracoMemberIndex.cs b/src/Umbraco.Examine/UmbracoMemberIndex.cs index 28b46f72dd..43962855c9 100644 --- a/src/Umbraco.Examine/UmbracoMemberIndex.cs +++ b/src/Umbraco.Examine/UmbracoMemberIndex.cs @@ -42,8 +42,8 @@ namespace Umbraco.Examine /// /// public UmbracoMemberIndex( - string name, - IEnumerable fieldDefinitions, + string name, + FieldDefinitionCollection fieldDefinitions, Directory luceneDirectory, Analyzer analyzer, ProfilingLogger profilingLogger, diff --git a/src/Umbraco.Tests/Umbraco.Tests.csproj b/src/Umbraco.Tests/Umbraco.Tests.csproj index 513701bf6a..b31a78a08f 100644 --- a/src/Umbraco.Tests/Umbraco.Tests.csproj +++ b/src/Umbraco.Tests/Umbraco.Tests.csproj @@ -77,7 +77,7 @@ - + 1.8.9 diff --git a/src/Umbraco.Tests/UmbracoExamine/IndexInitializer.cs b/src/Umbraco.Tests/UmbracoExamine/IndexInitializer.cs index cbd335a6c4..4435a5e829 100644 --- a/src/Umbraco.Tests/UmbracoExamine/IndexInitializer.cs +++ b/src/Umbraco.Tests/UmbracoExamine/IndexInitializer.cs @@ -164,7 +164,7 @@ namespace Umbraco.Tests.UmbracoExamine var i = new UmbracoContentIndex( "testIndexer", - UmbracoExamineIndex.UmbracoIndexFieldDefinitions, + new UmbracoFieldDefinitionCollection(), luceneDir, analyzer, profilingLogger, diff --git a/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj b/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj index 5751e9155c..60e1324969 100644 --- a/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj +++ b/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj @@ -88,7 +88,7 @@ - + diff --git a/src/Umbraco.Web/Editors/ExamineManagementController.cs b/src/Umbraco.Web/Editors/ExamineManagementController.cs index 2f96ee3d45..6667510b49 100644 --- a/src/Umbraco.Web/Editors/ExamineManagementController.cs +++ b/src/Umbraco.Web/Editors/ExamineManagementController.cs @@ -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); diff --git a/src/Umbraco.Web/PublishedContentQuery.cs b/src/Umbraco.Web/PublishedContentQuery.cs index 67b54330c5..f27745055c 100644 --- a/src/Umbraco.Web/PublishedContentQuery.cs +++ b/src/Umbraco.Web/PublishedContentQuery.cs @@ -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); diff --git a/src/Umbraco.Web/Search/ExamineComponent.cs b/src/Umbraco.Web/Search/ExamineComponent.cs index 65264d0308..3061a668ca 100644 --- a/src/Umbraco.Web/Search/ExamineComponent.cs +++ b/src/Umbraco.Web/Search/ExamineComponent.cs @@ -149,7 +149,7 @@ namespace Umbraco.Web.Search profilingLogger.Logger.Debug("Examine shutdown registered with MainDom"); - var registeredIndexers = examineManager.Indexes.OfType().Count(x => x.EnableDefaultEventHandler); + var registeredIndexers = examineManager.Indexes.OfType().Count(x => x.EnableDefaultEventHandler); profilingLogger.Logger.Info("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", "")); + } + } + /// /// 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()) + foreach (var index in _examineManager.Indexes.OfType()) { 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() + foreach (var index in examineComponent._examineManager.Indexes.OfType() //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() + foreach (var index in examineComponent._examineManager.Indexes.OfType() //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() + foreach (var index in examineComponent._examineManager.Indexes.OfType() //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() + foreach (var index in examineComponent._examineManager.Indexes.OfType() .Where(x => (keepIfUnpublished && !x.PublishedValuesOnly) || !keepIfUnpublished) .Where(x => x.EnableDefaultEventHandler)) diff --git a/src/Umbraco.Web/Search/GenericIndexDiagnostics.cs b/src/Umbraco.Web/Search/GenericIndexDiagnostics.cs index 32c8d43575..560fb19f09 100644 --- a/src/Umbraco.Web/Search/GenericIndexDiagnostics.cs +++ b/src/Umbraco.Web/Search/GenericIndexDiagnostics.cs @@ -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.Succeed(); //if we can search we'll assume it's healthy } catch (Exception e) diff --git a/src/Umbraco.Web/Search/UmbracoIndexesCreator.cs b/src/Umbraco.Web/Search/UmbracoIndexesCreator.cs index 3723dedc48..4296176abf 100644 --- a/src/Umbraco.Web/Search/UmbracoIndexesCreator.cs +++ b/src/Umbraco.Web/Search/UmbracoIndexesCreator.cs @@ -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, diff --git a/src/Umbraco.Web/Umbraco.Web.csproj b/src/Umbraco.Web/Umbraco.Web.csproj index 4034dd2be6..e2df681122 100755 --- a/src/Umbraco.Web/Umbraco.Web.csproj +++ b/src/Umbraco.Web/Umbraco.Web.csproj @@ -62,7 +62,7 @@ - + 2.6.2.25 From 5e6320730d67415b7b69ac102eff61c7c41bc664 Mon Sep 17 00:00:00 2001 From: Shannon Date: Thu, 13 Dec 2018 18:18:04 +1100 Subject: [PATCH 02/11] Updates nuspec to latest examine --- build/NuSpecs/UmbracoCms.Web.nuspec | 3 +-- src/Umbraco.Web/Search/ExamineComponent.cs | 11 +---------- 2 files changed, 2 insertions(+), 12 deletions(-) diff --git a/build/NuSpecs/UmbracoCms.Web.nuspec b/build/NuSpecs/UmbracoCms.Web.nuspec index adf090c69b..d3fad9a71d 100644 --- a/build/NuSpecs/UmbracoCms.Web.nuspec +++ b/build/NuSpecs/UmbracoCms.Web.nuspec @@ -25,8 +25,7 @@ - - + diff --git a/src/Umbraco.Web/Search/ExamineComponent.cs b/src/Umbraco.Web/Search/ExamineComponent.cs index 3061a668ca..0a18192cfd 100644 --- a/src/Umbraco.Web/Search/ExamineComponent.cs +++ b/src/Umbraco.Web/Search/ExamineComponent.cs @@ -23,6 +23,7 @@ using Umbraco.Core.Persistence.DatabaseModelDefinitions; using Umbraco.Web.Scheduling; using System.Threading.Tasks; using Examine.LuceneEngine.Directories; +using Examine.LuceneEngine.Indexing; using LightInject; using Umbraco.Core.Composing; using Umbraco.Core.Strings; @@ -170,16 +171,6 @@ namespace Umbraco.Web.Search 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", "")); - } - } - - /// /// Called to rebuild empty indexes on startup /// From 7159bca71fbccacc31ed3eb9e681c11676d13823 Mon Sep 17 00:00:00 2001 From: Shannon Date: Thu, 13 Dec 2018 18:24:06 +1100 Subject: [PATCH 03/11] Update to latest examine api changes --- src/Umbraco.Examine/Umbraco.Examine.csproj | 2 +- src/Umbraco.Examine/UmbracoContentIndex.cs | 2 +- src/Umbraco.Examine/UmbracoExamineIndex.cs | 10 +++++----- src/Umbraco.Examine/UmbracoMemberIndex.cs | 4 ++-- src/Umbraco.Tests/Umbraco.Tests.csproj | 2 +- src/Umbraco.Web.UI/Umbraco.Web.UI.csproj | 2 +- src/Umbraco.Web/Umbraco.Web.csproj | 2 +- 7 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/Umbraco.Examine/Umbraco.Examine.csproj b/src/Umbraco.Examine/Umbraco.Examine.csproj index 3c2f5a8ea6..bf404cf890 100644 --- a/src/Umbraco.Examine/Umbraco.Examine.csproj +++ b/src/Umbraco.Examine/Umbraco.Examine.csproj @@ -48,7 +48,7 @@ - + diff --git a/src/Umbraco.Examine/UmbracoContentIndex.cs b/src/Umbraco.Examine/UmbracoContentIndex.cs index ac9683f3f2..499de741d8 100644 --- a/src/Umbraco.Examine/UmbracoContentIndex.cs +++ b/src/Umbraco.Examine/UmbracoContentIndex.cs @@ -97,7 +97,7 @@ namespace Umbraco.Examine ProfilingLogger profilingLogger, ILocalizationService languageService, IContentValueSetValidator validator, - IReadOnlyDictionary> indexValueTypes = null) + IReadOnlyDictionary indexValueTypes = null) : base(name, fieldDefinitions, luceneDirectory, defaultAnalyzer, profilingLogger, validator, indexValueTypes) { if (validator == null) throw new ArgumentNullException(nameof(validator)); diff --git a/src/Umbraco.Examine/UmbracoExamineIndex.cs b/src/Umbraco.Examine/UmbracoExamineIndex.cs index 8d84e417d4..9cf4d05c75 100644 --- a/src/Umbraco.Examine/UmbracoExamineIndex.cs +++ b/src/Umbraco.Examine/UmbracoExamineIndex.cs @@ -72,7 +72,7 @@ namespace Umbraco.Examine Analyzer defaultAnalyzer, ProfilingLogger profilingLogger, IValueSetValidator validator = null, - IReadOnlyDictionary> indexValueTypes = null) + IReadOnlyDictionary indexValueTypes = null) : base(name, fieldDefinitions, luceneDirectory, defaultAnalyzer, validator, indexValueTypes) { ProfilingLogger = profilingLogger ?? throw new ArgumentNullException(nameof(profilingLogger)); @@ -125,14 +125,14 @@ namespace Umbraco.Examine /// /// /// - protected override FieldValueTypeCollection CreateFieldValueTypes(IReadOnlyDictionary> indexValueTypesFactory = null) + protected override FieldValueTypeCollection CreateFieldValueTypes(IReadOnlyDictionary indexValueTypesFactory = null) { //if config based then ensure the value types else it's assumed these were passed in via ctor if (_configBased) { foreach (var field in UmbracoIndexFieldDefinitions) { - FieldDefinitionCollection.TryAdd(field.Name, field); + FieldDefinitionCollection.TryAdd(field); } } @@ -200,7 +200,7 @@ namespace Umbraco.Examine ConfigIndexCriteria = CreateFieldDefinitionsFromConfig(indexSet); foreach (var fieldDefinition in ConfigIndexCriteria.StandardFields.Union(ConfigIndexCriteria.UserFields)) { - FieldDefinitionCollection.TryAdd(fieldDefinition.Name, fieldDefinition); + FieldDefinitionCollection.TryAdd(fieldDefinition); } found = true; break; @@ -228,7 +228,7 @@ namespace Umbraco.Examine ConfigIndexCriteria = CreateFieldDefinitionsFromConfig(indexSet); foreach (var fieldDefinition in ConfigIndexCriteria.StandardFields.Union(ConfigIndexCriteria.UserFields)) { - FieldDefinitionCollection.TryAdd(fieldDefinition.Name, fieldDefinition); + FieldDefinitionCollection.TryAdd(fieldDefinition); } } } diff --git a/src/Umbraco.Examine/UmbracoMemberIndex.cs b/src/Umbraco.Examine/UmbracoMemberIndex.cs index 43962855c9..27490e0e18 100644 --- a/src/Umbraco.Examine/UmbracoMemberIndex.cs +++ b/src/Umbraco.Examine/UmbracoMemberIndex.cs @@ -64,10 +64,10 @@ namespace Umbraco.Examine /// /// /// - protected override FieldValueTypeCollection CreateFieldValueTypes(IReadOnlyDictionary> indexValueTypesFactory = null) + protected override FieldValueTypeCollection CreateFieldValueTypes(IReadOnlyDictionary indexValueTypesFactory = null) { var keyDef = new FieldDefinition("__key", FieldDefinitionTypes.Raw); - FieldDefinitionCollection.TryAdd(keyDef.Name, keyDef); + FieldDefinitionCollection.TryAdd(keyDef); return base.CreateFieldValueTypes(indexValueTypesFactory); } diff --git a/src/Umbraco.Tests/Umbraco.Tests.csproj b/src/Umbraco.Tests/Umbraco.Tests.csproj index b31a78a08f..e7cc0c54aa 100644 --- a/src/Umbraco.Tests/Umbraco.Tests.csproj +++ b/src/Umbraco.Tests/Umbraco.Tests.csproj @@ -77,7 +77,7 @@ - + 1.8.9 diff --git a/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj b/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj index 60e1324969..4bd30fa383 100644 --- a/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj +++ b/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj @@ -88,7 +88,7 @@ - + diff --git a/src/Umbraco.Web/Umbraco.Web.csproj b/src/Umbraco.Web/Umbraco.Web.csproj index ee27a05641..3a3f9ceedd 100755 --- a/src/Umbraco.Web/Umbraco.Web.csproj +++ b/src/Umbraco.Web/Umbraco.Web.csproj @@ -62,7 +62,7 @@ - + 2.6.2.25 From 2060f69ab07d692c6a83a7135a0d22fe6a924e15 Mon Sep 17 00:00:00 2001 From: Shannon Date: Thu, 13 Dec 2018 21:09:56 +1100 Subject: [PATCH 04/11] Allow configuring a DirectoryFactory for all LuceneIndexes created with LuceneIndexCreator --- build/NuSpecs/UmbracoCms.Web.nuspec | 2 +- src/Umbraco.Core/Composing/TypeFinder.cs | 2 ++ src/Umbraco.Examine/LuceneIndexCreator.cs | 33 +++++++++++++++++----- src/Umbraco.Examine/Umbraco.Examine.csproj | 2 +- src/Umbraco.Examine/UmbracoContentIndex.cs | 5 +--- src/Umbraco.Tests/Umbraco.Tests.csproj | 2 +- src/Umbraco.Web.UI/Umbraco.Web.UI.csproj | 2 +- src/Umbraco.Web/Umbraco.Web.csproj | 2 +- 8 files changed, 34 insertions(+), 16 deletions(-) diff --git a/build/NuSpecs/UmbracoCms.Web.nuspec b/build/NuSpecs/UmbracoCms.Web.nuspec index d3fad9a71d..1693e0a7d1 100644 --- a/build/NuSpecs/UmbracoCms.Web.nuspec +++ b/build/NuSpecs/UmbracoCms.Web.nuspec @@ -25,7 +25,7 @@ - + diff --git a/src/Umbraco.Core/Composing/TypeFinder.cs b/src/Umbraco.Core/Composing/TypeFinder.cs index 9604f599cf..86d3863994 100644 --- a/src/Umbraco.Core/Composing/TypeFinder.cs +++ b/src/Umbraco.Core/Composing/TypeFinder.cs @@ -618,6 +618,8 @@ namespace Umbraco.Core.Composing // doesn't actualy load in all assemblies, only the types that have been referenced so far. // However, in a web context, the BuildManager will have executed which will force all assemblies // to be loaded so it's fine for now. + // It could be fairly easy to parse the typeName to get the assembly name and then do Assembly.Load and + // find the type from there. //now try fall back procedures. type = Type.GetType(typeName); diff --git a/src/Umbraco.Examine/LuceneIndexCreator.cs b/src/Umbraco.Examine/LuceneIndexCreator.cs index 572de1e8a8..0e83b37dc5 100644 --- a/src/Umbraco.Examine/LuceneIndexCreator.cs +++ b/src/Umbraco.Examine/LuceneIndexCreator.cs @@ -1,8 +1,12 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; +using System.Configuration; using System.IO; using Examine; using Examine.LuceneEngine.Directories; using Lucene.Net.Store; +using Umbraco.Core; +using Umbraco.Core.Composing; using Umbraco.Core.IO; namespace Umbraco.Examine @@ -18,17 +22,30 @@ namespace Umbraco.Examine /// /// Creates a file system based Lucene with the correct locking guidelines for Umbraco /// - /// + /// + /// The folder name to store the index (single word, not a fully qualified folder) (i.e. Internal) + /// /// - public virtual Lucene.Net.Store.Directory CreateFileSystemLuceneDirectory(string name) + public virtual Lucene.Net.Store.Directory CreateFileSystemLuceneDirectory(string folderName) { - //TODO: We should have a single AppSetting to be able to specify a default DirectoryFactory so we can have a single - //setting to configure all indexes that use this to easily swap the directory to Sync/%temp%/blog, etc... - - var dirInfo = new DirectoryInfo(Path.Combine(IOHelper.MapPath(SystemDirectories.Data), "TEMP", "ExamineIndexes", name)); + + var dirInfo = new DirectoryInfo(Path.Combine(IOHelper.MapPath(SystemDirectories.Data), "TEMP", "ExamineIndexes", folderName)); if (!dirInfo.Exists) System.IO.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 = ConfigurationManager.AppSettings["Umbraco.Examine.LuceneDirectoryFactory"]; + if (!configuredDirectoryFactory.IsNullOrWhiteSpace()) + { + //this should be a fully qualified type + var factoryType = TypeFinder.GetTypeByName(configuredDirectoryFactory); + if (factoryType == null) throw new NullReferenceException("No directory type found for value: " + configuredDirectoryFactory); + var directoryFactory = (IDirectoryFactory)Activator.CreateInstance(factoryType); + return directoryFactory.CreateDirectory(dirInfo); + } + + //no dir factory, just create a normal fs directory + var luceneDir = new SimpleFSDirectory(dirInfo); //we want to tell examine to use a different fs lock instead of the default NativeFSFileLock which could cause problems if the appdomain @@ -38,6 +55,8 @@ namespace Umbraco.Examine // however, we are setting the DefaultLockFactory in startup so we'll use that instead since it can be managed globally. luceneDir.SetLockFactory(DirectoryFactory.DefaultLockFactory(dirInfo)); return luceneDir; + + } } } diff --git a/src/Umbraco.Examine/Umbraco.Examine.csproj b/src/Umbraco.Examine/Umbraco.Examine.csproj index bf404cf890..aa00f29f4a 100644 --- a/src/Umbraco.Examine/Umbraco.Examine.csproj +++ b/src/Umbraco.Examine/Umbraco.Examine.csproj @@ -48,7 +48,7 @@ - + diff --git a/src/Umbraco.Examine/UmbracoContentIndex.cs b/src/Umbraco.Examine/UmbracoContentIndex.cs index 499de741d8..3231511936 100644 --- a/src/Umbraco.Examine/UmbracoContentIndex.cs +++ b/src/Umbraco.Examine/UmbracoContentIndex.cs @@ -246,10 +246,7 @@ namespace Umbraco.Examine ProfilingLogger.Logger.Debug(GetType(), "DeleteFromIndex with query: {Query} (found {TotalItems} results)", rawQuery, results.TotalItemCount); //need to queue a delete item for each one found - foreach (var r in results) - { - QueueIndexOperation(new IndexOperation(new ValueSet(r.Id), IndexOperationType.Delete)); - } + QueueIndexOperation(results.Select(r => new IndexOperation(new ValueSet(r.Id), IndexOperationType.Delete))); base.PerformDeleteFromIndex(nodeId, onComplete); } diff --git a/src/Umbraco.Tests/Umbraco.Tests.csproj b/src/Umbraco.Tests/Umbraco.Tests.csproj index e7cc0c54aa..4112be45ca 100644 --- a/src/Umbraco.Tests/Umbraco.Tests.csproj +++ b/src/Umbraco.Tests/Umbraco.Tests.csproj @@ -77,7 +77,7 @@ - + 1.8.9 diff --git a/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj b/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj index 4bd30fa383..cde23b0df6 100644 --- a/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj +++ b/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj @@ -88,7 +88,7 @@ - + diff --git a/src/Umbraco.Web/Umbraco.Web.csproj b/src/Umbraco.Web/Umbraco.Web.csproj index 3a3f9ceedd..54b5a025bf 100755 --- a/src/Umbraco.Web/Umbraco.Web.csproj +++ b/src/Umbraco.Web/Umbraco.Web.csproj @@ -62,7 +62,7 @@ - + 2.6.2.25 From c129375dd0744df87aff2f299500f24ea4ebf977 Mon Sep 17 00:00:00 2001 From: Shannon Date: Thu, 13 Dec 2018 22:33:41 +1100 Subject: [PATCH 05/11] more bug fixes --- build/NuSpecs/UmbracoCms.Web.nuspec | 2 +- src/Umbraco.Examine/Umbraco.Examine.csproj | 3 +- src/Umbraco.Examine/UmbracoContentIndex.cs | 41 +---------- src/Umbraco.Examine/UmbracoExamineIndex.cs | 68 ++++++------------- .../UmbracoFieldDefinitionCollection.cs | 43 ++++++++++++ src/Umbraco.Tests/Umbraco.Tests.csproj | 2 +- src/Umbraco.Web.UI/Umbraco.Web.UI.csproj | 2 +- src/Umbraco.Web/Umbraco.Web.csproj | 2 +- 8 files changed, 72 insertions(+), 91 deletions(-) create mode 100644 src/Umbraco.Examine/UmbracoFieldDefinitionCollection.cs diff --git a/build/NuSpecs/UmbracoCms.Web.nuspec b/build/NuSpecs/UmbracoCms.Web.nuspec index 1693e0a7d1..d36c4a240a 100644 --- a/build/NuSpecs/UmbracoCms.Web.nuspec +++ b/build/NuSpecs/UmbracoCms.Web.nuspec @@ -25,7 +25,7 @@ - + diff --git a/src/Umbraco.Examine/Umbraco.Examine.csproj b/src/Umbraco.Examine/Umbraco.Examine.csproj index aa00f29f4a..56e9b1a928 100644 --- a/src/Umbraco.Examine/Umbraco.Examine.csproj +++ b/src/Umbraco.Examine/Umbraco.Examine.csproj @@ -48,7 +48,7 @@ - + @@ -90,6 +90,7 @@ + Properties\SolutionInfo.cs diff --git a/src/Umbraco.Examine/UmbracoContentIndex.cs b/src/Umbraco.Examine/UmbracoContentIndex.cs index 3231511936..9134c691f4 100644 --- a/src/Umbraco.Examine/UmbracoContentIndex.cs +++ b/src/Umbraco.Examine/UmbracoContentIndex.cs @@ -18,45 +18,6 @@ using Examine.LuceneEngine; namespace Umbraco.Examine { - /// - /// Custom allowing dynamic creation of - /// - public class UmbracoFieldDefinitionCollection : FieldDefinitionCollection - { - - public UmbracoFieldDefinitionCollection() - : base(UmbracoExamineIndex.UmbracoIndexFieldDefinitions) - { - } - - ///// - ///// Overridden to dynamically add field definitions for culture variations - ///// - ///// - ///// - ///// - //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 - - //} - } - /// /// An indexer for Umbraco content and media /// @@ -161,7 +122,7 @@ namespace Umbraco.Examine //anywhere else in this class Current.Services.PublicAccessService, parentId, - ConfigIndexCriteria.IncludeItemTypes, ConfigIndexCriteria.ExcludeItemTypes); + ConfigIndexCriteria?.IncludeItemTypes, ConfigIndexCriteria?.ExcludeItemTypes); PublishedValuesOnly = supportUnpublished; } diff --git a/src/Umbraco.Examine/UmbracoExamineIndex.cs b/src/Umbraco.Examine/UmbracoExamineIndex.cs index 9cf4d05c75..3a7a21bdb3 100644 --- a/src/Umbraco.Examine/UmbracoExamineIndex.cs +++ b/src/Umbraco.Examine/UmbracoExamineIndex.cs @@ -20,8 +20,7 @@ namespace Umbraco.Examine { /// - /// An abstract provider containing the basic functionality to be able to query against - /// Umbraco data. + /// An abstract provider containing the basic functionality to be able to query against Umbraco data. /// public abstract class UmbracoExamineIndex : LuceneIndex, IUmbracoIndex, IIndexDiagnostics { @@ -53,6 +52,7 @@ namespace Umbraco.Examine { ProfilingLogger = Current.ProfilingLogger; _configBased = true; + _diagnostics = new UmbracoExamineIndexDiagnostics(this, ProfilingLogger.Logger); } /// @@ -120,26 +120,6 @@ namespace Umbraco.Examine protected ProfilingLogger ProfilingLogger { get; } - /// - /// Overridden to ensure that the umbraco system field definitions are in place - /// - /// - /// - protected override FieldValueTypeCollection CreateFieldValueTypes(IReadOnlyDictionary indexValueTypesFactory = null) - { - //if config based then ensure the value types else it's assumed these were passed in via ctor - if (_configBased) - { - foreach (var field in UmbracoIndexFieldDefinitions) - { - FieldDefinitionCollection.TryAdd(field); - } - } - - - return base.CreateFieldValueTypes(indexValueTypesFactory); - } - /// /// When set to true Umbraco will keep the index in sync with Umbraco data automatically /// @@ -174,12 +154,15 @@ namespace Umbraco.Examine EnableDefaultEventHandler = enabled; } - //Need to check if the index set or IndexerData is specified... - if (config["indexSet"] == null && FieldDefinitionCollection.Count == 0) + //this is config based, so add the default definitions + foreach (var field in UmbracoIndexFieldDefinitions) { - //if we don't have either, then we'll try to set the index set by naming conventions - var found = false; + FieldDefinitionCollection.TryAdd(field); + } + //Need to check if the index set is specified... + if (config["indexSet"] == null) + { var possibleSuffixes = new[] {"Index", "Indexer"}; foreach (var suffix in possibleSuffixes) { @@ -200,36 +183,29 @@ namespace Umbraco.Examine ConfigIndexCriteria = CreateFieldDefinitionsFromConfig(indexSet); foreach (var fieldDefinition in ConfigIndexCriteria.StandardFields.Union(ConfigIndexCriteria.UserFields)) { - FieldDefinitionCollection.TryAdd(fieldDefinition); + //replace any existing or add + FieldDefinitionCollection.AddOrUpdate(fieldDefinition); } - found = true; break; } - - if (!found) - throw new ArgumentNullException("indexSet on LuceneExamineIndexer provider has not been set in configuration and/or the IndexerData property has not been explicitly set"); - } - else if (config["indexSet"] != null) + else { //if an index set is specified, ensure it exists and initialize the indexer based on the set if (IndexSets.Instance.Sets[config["indexSet"]] == null) - { throw new ArgumentException("The indexSet specified for the LuceneExamineIndexer provider does not exist"); - } - else + + IndexSetName = config["indexSet"]; + + var indexSet = IndexSets.Instance.Sets[IndexSetName]; + + //get the index criteria and ensure folder + ConfigIndexCriteria = CreateFieldDefinitionsFromConfig(indexSet); + foreach (var fieldDefinition in ConfigIndexCriteria.StandardFields.Union(ConfigIndexCriteria.UserFields)) { - IndexSetName = config["indexSet"]; - - var indexSet = IndexSets.Instance.Sets[IndexSetName]; - - //get the index criteria and ensure folder - ConfigIndexCriteria = CreateFieldDefinitionsFromConfig(indexSet); - foreach (var fieldDefinition in ConfigIndexCriteria.StandardFields.Union(ConfigIndexCriteria.UserFields)) - { - FieldDefinitionCollection.TryAdd(fieldDefinition); - } + //replace any existing or add + FieldDefinitionCollection.AddOrUpdate(fieldDefinition); } } diff --git a/src/Umbraco.Examine/UmbracoFieldDefinitionCollection.cs b/src/Umbraco.Examine/UmbracoFieldDefinitionCollection.cs new file mode 100644 index 0000000000..ce59501046 --- /dev/null +++ b/src/Umbraco.Examine/UmbracoFieldDefinitionCollection.cs @@ -0,0 +1,43 @@ +using Examine; + +namespace Umbraco.Examine +{ + /// + /// Custom allowing dynamic creation of + /// + public class UmbracoFieldDefinitionCollection : FieldDefinitionCollection + { + + public UmbracoFieldDefinitionCollection() + : base(UmbracoExamineIndex.UmbracoIndexFieldDefinitions) + { + } + + ///// + ///// Overridden to dynamically add field definitions for culture variations + ///// + ///// + ///// + ///// + //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 + + //} + } +} \ No newline at end of file diff --git a/src/Umbraco.Tests/Umbraco.Tests.csproj b/src/Umbraco.Tests/Umbraco.Tests.csproj index 4112be45ca..38c049f7aa 100644 --- a/src/Umbraco.Tests/Umbraco.Tests.csproj +++ b/src/Umbraco.Tests/Umbraco.Tests.csproj @@ -77,7 +77,7 @@ - + 1.8.9 diff --git a/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj b/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj index cde23b0df6..88155846d7 100644 --- a/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj +++ b/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj @@ -88,7 +88,7 @@ - + diff --git a/src/Umbraco.Web/Umbraco.Web.csproj b/src/Umbraco.Web/Umbraco.Web.csproj index 54b5a025bf..9a96acbd8c 100755 --- a/src/Umbraco.Web/Umbraco.Web.csproj +++ b/src/Umbraco.Web/Umbraco.Web.csproj @@ -62,7 +62,7 @@ - + 2.6.2.25 From 162f8480d17fa8a3422700f08767fc14fd895522 Mon Sep 17 00:00:00 2001 From: Shannon Date: Thu, 13 Dec 2018 23:17:58 +1100 Subject: [PATCH 06/11] more tweaks to get config based indexes working, updates to IIndexPopulator to have strongly typed association --- build/NuSpecs/UmbracoCms.Web.nuspec | 2 +- src/Umbraco.Examine/ContentIndexPopulator.cs | 5 +---- src/Umbraco.Examine/IIndexPopulator.cs | 10 ++++++---- src/Umbraco.Examine/IndexPopulator.cs | 19 ++++++++++++++++--- src/Umbraco.Examine/IndexRebuilder.cs | 4 ++-- src/Umbraco.Examine/MediaIndexPopulator.cs | 5 +---- src/Umbraco.Examine/MemberIndexPopulator.cs | 4 +--- src/Umbraco.Examine/Umbraco.Examine.csproj | 2 +- src/Umbraco.Tests/Umbraco.Tests.csproj | 2 +- src/Umbraco.Tests/UmbracoExamine/IndexTest.cs | 3 --- .../UmbracoExamine/SearchTests.cs | 1 - src/Umbraco.Web.UI/Umbraco.Web.UI.csproj | 2 +- .../Editors/ExamineManagementController.cs | 12 ++++++------ src/Umbraco.Web/Umbraco.Web.csproj | 2 +- 14 files changed, 38 insertions(+), 35 deletions(-) diff --git a/build/NuSpecs/UmbracoCms.Web.nuspec b/build/NuSpecs/UmbracoCms.Web.nuspec index d36c4a240a..11d9004a34 100644 --- a/build/NuSpecs/UmbracoCms.Web.nuspec +++ b/build/NuSpecs/UmbracoCms.Web.nuspec @@ -14,7 +14,7 @@ Contains the core assemblies needed to run Umbraco Cms en-US umbraco - + - + diff --git a/src/Umbraco.Tests/Umbraco.Tests.csproj b/src/Umbraco.Tests/Umbraco.Tests.csproj index 38c049f7aa..810ebe5ab4 100644 --- a/src/Umbraco.Tests/Umbraco.Tests.csproj +++ b/src/Umbraco.Tests/Umbraco.Tests.csproj @@ -77,7 +77,7 @@ - + 1.8.9 diff --git a/src/Umbraco.Tests/UmbracoExamine/IndexTest.cs b/src/Umbraco.Tests/UmbracoExamine/IndexTest.cs index 35e3524459..2f0adfcb25 100644 --- a/src/Umbraco.Tests/UmbracoExamine/IndexTest.cs +++ b/src/Umbraco.Tests/UmbracoExamine/IndexTest.cs @@ -130,8 +130,6 @@ namespace Umbraco.Tests.UmbracoExamine validator: new ContentValueSetValidator(false))) using (indexer.ProcessNonAsync()) { - contentRebuilder.RegisterIndex(indexer.Name); - mediaRebuilder.RegisterIndex(indexer.Name); var searcher = indexer.GetSearcher(); @@ -283,7 +281,6 @@ namespace Umbraco.Tests.UmbracoExamine validator: new ContentValueSetValidator(false))) using (indexer.ProcessNonAsync()) { - rebuilder.RegisterIndex(indexer.Name); var searcher = indexer.GetSearcher(); diff --git a/src/Umbraco.Tests/UmbracoExamine/SearchTests.cs b/src/Umbraco.Tests/UmbracoExamine/SearchTests.cs index a01d49cc22..8156f640d6 100644 --- a/src/Umbraco.Tests/UmbracoExamine/SearchTests.cs +++ b/src/Umbraco.Tests/UmbracoExamine/SearchTests.cs @@ -62,7 +62,6 @@ namespace Umbraco.Tests.UmbracoExamine using (var indexer = IndexInitializer.GetUmbracoIndexer(ProfilingLogger, luceneDir)) using (indexer.ProcessNonAsync()) { - rebuilder.RegisterIndex(indexer.Name); indexer.CreateIndex(); rebuilder.Populate(indexer); diff --git a/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj b/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj index 88155846d7..4a34e23afb 100644 --- a/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj +++ b/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj @@ -88,7 +88,7 @@ - + diff --git a/src/Umbraco.Web/Editors/ExamineManagementController.cs b/src/Umbraco.Web/Editors/ExamineManagementController.cs index 6667510b49..bce2c4a438 100644 --- a/src/Umbraco.Web/Editors/ExamineManagementController.cs +++ b/src/Umbraco.Web/Editors/ExamineManagementController.cs @@ -109,7 +109,7 @@ namespace Umbraco.Web.Editors if (!validate.IsSuccessStatusCode) throw new HttpResponseException(validate); - validate = ValidatePopulator(indexName); + validate = ValidatePopulator(index); if (!validate.IsSuccessStatusCode) throw new HttpResponseException(validate); @@ -134,7 +134,7 @@ namespace Umbraco.Web.Editors if (!validate.IsSuccessStatusCode) return validate; - validate = ValidatePopulator(indexName); + validate = ValidatePopulator(index); if (!validate.IsSuccessStatusCode) return validate; @@ -201,7 +201,7 @@ namespace Umbraco.Web.Editors Name = indexName, HealthStatus = isHealth.Success ? (isHealth.Result ?? "Healthy") : (isHealth.Result ?? "Unhealthy"), ProviderProperties = properties, - CanRebuild = _indexRebuilder.CanRebuild(indexName) + CanRebuild = _indexRebuilder.CanRebuild(index) }; @@ -228,13 +228,13 @@ namespace Umbraco.Web.Editors return response1; } - private HttpResponseMessage ValidatePopulator(string indexName) + private HttpResponseMessage ValidatePopulator(IIndex index) { - if (_indexRebuilder.CanRebuild(indexName)) + if (_indexRebuilder.CanRebuild(index)) return Request.CreateResponse(HttpStatusCode.OK); var response = Request.CreateResponse(HttpStatusCode.BadRequest); - response.Content = new StringContent($"The index {indexName} cannot be rebuilt because it does not have an associated {typeof(IIndexPopulator)}"); + response.Content = new StringContent($"The index {index.Name} cannot be rebuilt because it does not have an associated {typeof(IIndexPopulator)}"); response.ReasonPhrase = "Index cannot be rebuilt"; return response; } diff --git a/src/Umbraco.Web/Umbraco.Web.csproj b/src/Umbraco.Web/Umbraco.Web.csproj index 9a96acbd8c..8006277c73 100755 --- a/src/Umbraco.Web/Umbraco.Web.csproj +++ b/src/Umbraco.Web/Umbraco.Web.csproj @@ -62,7 +62,7 @@ - + 2.6.2.25 From d38e4e6e3450d32c2b6f309355db89332bff64ee Mon Sep 17 00:00:00 2001 From: Shannon Date: Fri, 14 Dec 2018 11:32:20 +1100 Subject: [PATCH 07/11] latest examine, fixes sortability --- build/NuSpecs/UmbracoCms.Web.nuspec | 2 +- src/Umbraco.Examine/Umbraco.Examine.csproj | 2 +- src/Umbraco.Examine/UmbracoExamineIndex.cs | 34 ++---------------- .../UmbracoFieldDefinitionCollection.cs | 36 +++++++++++++++++-- src/Umbraco.Tests/Umbraco.Tests.csproj | 2 +- .../UmbracoExamine/SearchTests.cs | 3 +- src/Umbraco.Web.UI/Umbraco.Web.UI.csproj | 2 +- .../XmlPublishedCache/PublishedMediaCache.cs | 1 + src/Umbraco.Web/Umbraco.Web.csproj | 2 +- 9 files changed, 44 insertions(+), 40 deletions(-) diff --git a/build/NuSpecs/UmbracoCms.Web.nuspec b/build/NuSpecs/UmbracoCms.Web.nuspec index 11d9004a34..aacd55d4be 100644 --- a/build/NuSpecs/UmbracoCms.Web.nuspec +++ b/build/NuSpecs/UmbracoCms.Web.nuspec @@ -25,7 +25,7 @@ - + diff --git a/src/Umbraco.Examine/Umbraco.Examine.csproj b/src/Umbraco.Examine/Umbraco.Examine.csproj index 4258e14aa0..75c3f5a230 100644 --- a/src/Umbraco.Examine/Umbraco.Examine.csproj +++ b/src/Umbraco.Examine/Umbraco.Examine.csproj @@ -48,7 +48,7 @@ - + diff --git a/src/Umbraco.Examine/UmbracoExamineIndex.cs b/src/Umbraco.Examine/UmbracoExamineIndex.cs index 3a7a21bdb3..1933874fc7 100644 --- a/src/Umbraco.Examine/UmbracoExamineIndex.cs +++ b/src/Umbraco.Examine/UmbracoExamineIndex.cs @@ -86,37 +86,7 @@ namespace Umbraco.Examine private readonly bool _configBased = false; - /// - /// A type that defines the type of index for each Umbraco field (non user defined fields) - /// Alot of standard umbraco fields shouldn't be tokenized or even indexed, just stored into lucene - /// for retreival after searching. - /// - public static readonly FieldDefinition[] UmbracoIndexFieldDefinitions = - { - new FieldDefinition("parentID", FieldDefinitionTypes.Integer), - new FieldDefinition("level", FieldDefinitionTypes.Integer), - new FieldDefinition("writerID", FieldDefinitionTypes.Integer), - new FieldDefinition("creatorID", FieldDefinitionTypes.Integer), - new FieldDefinition("sortOrder", FieldDefinitionTypes.Integer), - new FieldDefinition("template", FieldDefinitionTypes.Integer), - - new FieldDefinition("createDate", FieldDefinitionTypes.DateTime), - new FieldDefinition("updateDate", FieldDefinitionTypes.DateTime), - - new FieldDefinition("key", FieldDefinitionTypes.InvariantCultureIgnoreCase), - new FieldDefinition("version", FieldDefinitionTypes.Raw), - new FieldDefinition("nodeType", FieldDefinitionTypes.InvariantCultureIgnoreCase), - new FieldDefinition("template", FieldDefinitionTypes.Raw), - new FieldDefinition("urlName", FieldDefinitionTypes.InvariantCultureIgnoreCase), - new FieldDefinition("path", FieldDefinitionTypes.Raw), - - new FieldDefinition("email", FieldDefinitionTypes.EmailAddress), - - new FieldDefinition(PublishedFieldName, FieldDefinitionTypes.Raw), - new FieldDefinition(NodeKeyFieldName, FieldDefinitionTypes.Raw), - new FieldDefinition(IndexPathFieldName, FieldDefinitionTypes.Raw), - new FieldDefinition(IconFieldName, FieldDefinitionTypes.Raw) - }; + protected ProfilingLogger ProfilingLogger { get; } @@ -155,7 +125,7 @@ namespace Umbraco.Examine } //this is config based, so add the default definitions - foreach (var field in UmbracoIndexFieldDefinitions) + foreach (var field in UmbracoFieldDefinitionCollection.UmbracoIndexFieldDefinitions) { FieldDefinitionCollection.TryAdd(field); } diff --git a/src/Umbraco.Examine/UmbracoFieldDefinitionCollection.cs b/src/Umbraco.Examine/UmbracoFieldDefinitionCollection.cs index ce59501046..97d1f68727 100644 --- a/src/Umbraco.Examine/UmbracoFieldDefinitionCollection.cs +++ b/src/Umbraco.Examine/UmbracoFieldDefinitionCollection.cs @@ -9,10 +9,42 @@ namespace Umbraco.Examine { public UmbracoFieldDefinitionCollection() - : base(UmbracoExamineIndex.UmbracoIndexFieldDefinitions) + : base(UmbracoIndexFieldDefinitions) { } + /// + /// A type that defines the type of index for each Umbraco field (non user defined fields) + /// Alot of standard umbraco fields shouldn't be tokenized or even indexed, just stored into lucene + /// for retreival after searching. + /// + public static readonly FieldDefinition[] UmbracoIndexFieldDefinitions = + { + new FieldDefinition("parentID", FieldDefinitionTypes.Integer), + new FieldDefinition("level", FieldDefinitionTypes.Integer), + new FieldDefinition("writerID", FieldDefinitionTypes.Integer), + new FieldDefinition("creatorID", FieldDefinitionTypes.Integer), + new FieldDefinition("sortOrder", FieldDefinitionTypes.Integer), + new FieldDefinition("template", FieldDefinitionTypes.Integer), + + new FieldDefinition("createDate", FieldDefinitionTypes.DateTime), + new FieldDefinition("updateDate", FieldDefinitionTypes.DateTime), + + new FieldDefinition("key", FieldDefinitionTypes.InvariantCultureIgnoreCase), + new FieldDefinition("version", FieldDefinitionTypes.Raw), + new FieldDefinition("nodeType", FieldDefinitionTypes.InvariantCultureIgnoreCase), + new FieldDefinition("template", FieldDefinitionTypes.Raw), + new FieldDefinition("urlName", FieldDefinitionTypes.InvariantCultureIgnoreCase), + new FieldDefinition("path", FieldDefinitionTypes.Raw), + + new FieldDefinition("email", FieldDefinitionTypes.EmailAddress), + + new FieldDefinition(UmbracoExamineIndex.PublishedFieldName, FieldDefinitionTypes.Raw), + new FieldDefinition(UmbracoExamineIndex.NodeKeyFieldName, FieldDefinitionTypes.Raw), + new FieldDefinition(UmbracoExamineIndex.IndexPathFieldName, FieldDefinitionTypes.Raw), + new FieldDefinition(UmbracoExamineIndex.IconFieldName, FieldDefinitionTypes.Raw) + }; + ///// ///// Overridden to dynamically add field definitions for culture variations ///// @@ -40,4 +72,4 @@ namespace Umbraco.Examine //} } -} \ No newline at end of file +} diff --git a/src/Umbraco.Tests/Umbraco.Tests.csproj b/src/Umbraco.Tests/Umbraco.Tests.csproj index 810ebe5ab4..2d20c588b5 100644 --- a/src/Umbraco.Tests/Umbraco.Tests.csproj +++ b/src/Umbraco.Tests/Umbraco.Tests.csproj @@ -77,7 +77,7 @@ - + 1.8.9 diff --git a/src/Umbraco.Tests/UmbracoExamine/SearchTests.cs b/src/Umbraco.Tests/UmbracoExamine/SearchTests.cs index 8156f640d6..3e96e30c6a 100644 --- a/src/Umbraco.Tests/UmbracoExamine/SearchTests.cs +++ b/src/Umbraco.Tests/UmbracoExamine/SearchTests.cs @@ -5,6 +5,7 @@ using LightInject; using Examine; using NUnit.Framework; using Examine.LuceneEngine.SearchCriteria; +using Examine.SearchCriteria; using Moq; using Umbraco.Core.Models; using Umbraco.Core.Persistence; @@ -74,7 +75,7 @@ namespace Umbraco.Tests.UmbracoExamine var stringSortedCriteria = searcher.CreateCriteria() .ParentId(1148).And() - .OrderBy("sortOrder"); //will default to string + .OrderBy(new SortableField("sortOrder"));//will default to string var stringSortedResult = searcher.Search(stringSortedCriteria.Compile()); Assert.AreEqual(12, numberSortedResult.TotalItemCount); diff --git a/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj b/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj index 4a34e23afb..465544960c 100644 --- a/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj +++ b/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj @@ -88,7 +88,7 @@ - + diff --git a/src/Umbraco.Web/PublishedCache/XmlPublishedCache/PublishedMediaCache.cs b/src/Umbraco.Web/PublishedCache/XmlPublishedCache/PublishedMediaCache.cs index f203d5d2c9..3f776830a6 100644 --- a/src/Umbraco.Web/PublishedCache/XmlPublishedCache/PublishedMediaCache.cs +++ b/src/Umbraco.Web/PublishedCache/XmlPublishedCache/PublishedMediaCache.cs @@ -8,6 +8,7 @@ using System.Xml.XPath; using Examine; using Examine.LuceneEngine.SearchCriteria; using Examine.Providers; +using Examine.SearchCriteria; using Lucene.Net.Store; using Umbraco.Core; using Umbraco.Core.Logging; diff --git a/src/Umbraco.Web/Umbraco.Web.csproj b/src/Umbraco.Web/Umbraco.Web.csproj index 8006277c73..eb6eab9829 100755 --- a/src/Umbraco.Web/Umbraco.Web.csproj +++ b/src/Umbraco.Web/Umbraco.Web.csproj @@ -62,7 +62,7 @@ - + 2.6.2.25 From 4976782247f613dea5a769dbc4073644996a3088 Mon Sep 17 00:00:00 2001 From: Shannon Date: Mon, 17 Dec 2018 12:17:03 +1100 Subject: [PATCH 08/11] Updates search published content search extensions to correspond with new examine api changes, updates examine api changes --- build/NuSpecs/UmbracoCms.Web.nuspec | 2 +- src/Umbraco.Examine/Umbraco.Examine.csproj | 2 +- src/Umbraco.Examine/UmbracoContentIndex.cs | 6 +- .../UmbracoExamineExtensions.cs | 8 +-- .../PublishedContent/PublishedMediaTests.cs | 4 +- src/Umbraco.Tests/Umbraco.Tests.csproj | 2 +- .../UmbracoExamine/EventsTest.cs | 2 +- src/Umbraco.Tests/UmbracoExamine/IndexTest.cs | 22 ++++---- .../UmbracoExamine/SearchTests.cs | 19 +++---- src/Umbraco.Web.UI/Umbraco.Web.UI.csproj | 2 +- .../Editors/ExamineManagementController.cs | 2 +- src/Umbraco.Web/IPublishedContentQuery.cs | 13 +++-- .../XmlPublishedCache/PublishedMediaCache.cs | 20 +++---- src/Umbraco.Web/PublishedContentExtensions.cs | 47 ++++++---------- src/Umbraco.Web/PublishedContentQuery.cs | 30 +++------- src/Umbraco.Web/Search/ExamineComponent.cs | 4 +- src/Umbraco.Web/Search/UmbracoTreeSearcher.cs | 6 +- src/Umbraco.Web/Umbraco.Web.csproj | 2 +- src/Umbraco.Web/UmbracoHelper.cs | 56 ------------------- 19 files changed, 79 insertions(+), 170 deletions(-) diff --git a/build/NuSpecs/UmbracoCms.Web.nuspec b/build/NuSpecs/UmbracoCms.Web.nuspec index aacd55d4be..51d7e3b8d0 100644 --- a/build/NuSpecs/UmbracoCms.Web.nuspec +++ b/build/NuSpecs/UmbracoCms.Web.nuspec @@ -25,7 +25,7 @@ - + diff --git a/src/Umbraco.Examine/Umbraco.Examine.csproj b/src/Umbraco.Examine/Umbraco.Examine.csproj index 75c3f5a230..a037c3028e 100644 --- a/src/Umbraco.Examine/Umbraco.Examine.csproj +++ b/src/Umbraco.Examine/Umbraco.Examine.csproj @@ -48,7 +48,7 @@ - + diff --git a/src/Umbraco.Examine/UmbracoContentIndex.cs b/src/Umbraco.Examine/UmbracoContentIndex.cs index 9134c691f4..c584f5bf51 100644 --- a/src/Umbraco.Examine/UmbracoContentIndex.cs +++ b/src/Umbraco.Examine/UmbracoContentIndex.cs @@ -200,9 +200,9 @@ namespace Umbraco.Examine var descendantPath = $@"\-1\,*{nodeId}\,*"; var rawQuery = $"{IndexPathFieldName}:{descendantPath}"; var searcher = GetSearcher(); - var c = searcher.CreateCriteria(); - var filtered = c.RawQuery(rawQuery); - var results = searcher.Search(filtered); + var c = searcher.CreateQuery(); + var filtered = c.NativeQuery(rawQuery); + var results = filtered.Execute(); ProfilingLogger.Logger.Debug(GetType(), "DeleteFromIndex with query: {Query} (found {TotalItems} results)", rawQuery, results.TotalItemCount); diff --git a/src/Umbraco.Examine/UmbracoExamineExtensions.cs b/src/Umbraco.Examine/UmbracoExamineExtensions.cs index 8be5a6c1e3..f33b7587e0 100644 --- a/src/Umbraco.Examine/UmbracoExamineExtensions.cs +++ b/src/Umbraco.Examine/UmbracoExamineExtensions.cs @@ -1,10 +1,6 @@ -using System; -using System.ComponentModel; -using System.Web; -using Examine.LuceneEngine.SearchCriteria; -using Examine.SearchCriteria; +using Examine.LuceneEngine.Search; +using Examine.Search; using Umbraco.Core; -using Umbraco.Examine.Config; namespace Umbraco.Examine { diff --git a/src/Umbraco.Tests/PublishedContent/PublishedMediaTests.cs b/src/Umbraco.Tests/PublishedContent/PublishedMediaTests.cs index d5fdd2bf0c..309ce1c0fb 100644 --- a/src/Umbraco.Tests/PublishedContent/PublishedMediaTests.cs +++ b/src/Umbraco.Tests/PublishedContent/PublishedMediaTests.cs @@ -173,9 +173,9 @@ namespace Umbraco.Tests.PublishedContent //ensure it still exists in the index (raw examine search) - var criteria = searcher.CreateCriteria(); + var criteria = searcher.CreateQuery(); var filter = criteria.Id(3113); - var found = searcher.Search(filter.Compile()); + var found = filter.Execute(); Assert.IsNotNull(found); Assert.AreEqual(1, found.TotalItemCount); diff --git a/src/Umbraco.Tests/Umbraco.Tests.csproj b/src/Umbraco.Tests/Umbraco.Tests.csproj index a9f38ba391..35a51e0584 100644 --- a/src/Umbraco.Tests/Umbraco.Tests.csproj +++ b/src/Umbraco.Tests/Umbraco.Tests.csproj @@ -77,7 +77,7 @@ - + 1.8.9 diff --git a/src/Umbraco.Tests/UmbracoExamine/EventsTest.cs b/src/Umbraco.Tests/UmbracoExamine/EventsTest.cs index 47fa32cbaa..ed5ae07fc0 100644 --- a/src/Umbraco.Tests/UmbracoExamine/EventsTest.cs +++ b/src/Umbraco.Tests/UmbracoExamine/EventsTest.cs @@ -36,7 +36,7 @@ namespace Umbraco.Tests.UmbracoExamine var valueSet = node.ConvertToValueSet(IndexTypes.Content); indexer.IndexItems(new[] { valueSet }); - var found = searcher.Search(searcher.CreateCriteria().Id((string)node.Attribute("id")).Compile()); + var found = searcher.CreateQuery().Id((string)node.Attribute("id")).Execute(); Assert.AreEqual(0, found.TotalItemCount); } diff --git a/src/Umbraco.Tests/UmbracoExamine/IndexTest.cs b/src/Umbraco.Tests/UmbracoExamine/IndexTest.cs index 2f0adfcb25..1bc51b6173 100644 --- a/src/Umbraco.Tests/UmbracoExamine/IndexTest.cs +++ b/src/Umbraco.Tests/UmbracoExamine/IndexTest.cs @@ -105,7 +105,7 @@ namespace Umbraco.Tests.UmbracoExamine var searcher = indexer.GetSearcher(); - var results = searcher.Search(searcher.CreateCriteria().Id(555).Compile()); + var results = searcher.CreateQuery().Id(555).Execute(); Assert.AreEqual(1, results.TotalItemCount); var result = results.First(); @@ -137,7 +137,7 @@ namespace Umbraco.Tests.UmbracoExamine contentRebuilder.Populate(indexer); mediaRebuilder.Populate(indexer); - var result = searcher.Search(searcher.CreateCriteria().All().Compile()); + var result = searcher.CreateQuery().All().Execute(); Assert.AreEqual(29, result.TotalItemCount); } @@ -208,7 +208,7 @@ namespace Umbraco.Tests.UmbracoExamine indexer.IndexItem(node.ConvertToValueSet(IndexTypes.Media)); //it will not exist because it exists under 2222 - var results = searcher.Search(searcher.CreateCriteria().Id(2112).Compile()); + var results = searcher.CreateQuery().Id(2112).Execute(); Assert.AreEqual(0, results.Count()); //now mimic moving 2112 to 1116 @@ -220,7 +220,7 @@ namespace Umbraco.Tests.UmbracoExamine indexer.IndexItems(new[] { node.ConvertToValueSet(IndexTypes.Media) }); //now ensure it exists - results = searcher.Search(searcher.CreateCriteria().Id(2112).Compile()); + results = searcher.CreateQuery().Id(2112).Execute(); Assert.AreEqual(1, results.Count()); } } @@ -251,7 +251,7 @@ namespace Umbraco.Tests.UmbracoExamine indexer1.IndexItem(node.ConvertToValueSet(IndexTypes.Media)); //it will exist because it exists under 2222 - var results = searcher.Search(searcher.CreateCriteria().Id(2112).Compile()); + var results = searcher.CreateQuery().Id(2112).Execute(); Assert.AreEqual(1, results.Count()); //now mimic moving the node underneath 1116 instead of 2222 @@ -262,7 +262,7 @@ namespace Umbraco.Tests.UmbracoExamine indexer1.IndexItems(new[] { node.ConvertToValueSet(IndexTypes.Media) }); //now ensure it's deleted - results = searcher.Search(searcher.CreateCriteria().Id(2112).Compile()); + results = searcher.CreateQuery().Id(2112).Execute(); Assert.AreEqual(0, results.Count()); } } @@ -287,7 +287,7 @@ namespace Umbraco.Tests.UmbracoExamine //create the whole thing rebuilder.Populate(indexer); - var result = searcher.Search(searcher.CreateCriteria().Field(LuceneIndex.CategoryFieldName, IndexTypes.Content).Compile()); + var result = searcher.CreateQuery().Field(LuceneIndex.CategoryFieldName, IndexTypes.Content).Execute(); Assert.AreEqual(21, result.TotalItemCount); //delete all content @@ -298,13 +298,13 @@ namespace Umbraco.Tests.UmbracoExamine //ensure it's all gone - result = searcher.Search(searcher.CreateCriteria().Field(LuceneIndex.CategoryFieldName, IndexTypes.Content).Compile()); + result = searcher.CreateQuery().Field(LuceneIndex.CategoryFieldName, IndexTypes.Content).Execute(); Assert.AreEqual(0, result.TotalItemCount); //call our indexing methods rebuilder.Populate(indexer); - result = searcher.Search(searcher.CreateCriteria().Field(LuceneIndex.CategoryFieldName, IndexTypes.Content).Compile()); + result = searcher.CreateQuery().Field(LuceneIndex.CategoryFieldName, IndexTypes.Content).Execute(); Assert.AreEqual(21, result.TotalItemCount); } } @@ -332,10 +332,10 @@ namespace Umbraco.Tests.UmbracoExamine indexer.DeleteFromIndex(1140.ToString()); //this node had children: 1141 & 1142, let's ensure they are also removed - var results = searcher.Search(searcher.CreateCriteria().Id(1141).Compile()); + var results = searcher.CreateQuery().Id(1141).Execute(); Assert.AreEqual(0, results.Count()); - results = searcher.Search(searcher.CreateCriteria().Id(1142).Compile()); + results = searcher.CreateQuery().Id(1142).Execute(); Assert.AreEqual(0, results.Count()); } diff --git a/src/Umbraco.Tests/UmbracoExamine/SearchTests.cs b/src/Umbraco.Tests/UmbracoExamine/SearchTests.cs index 3e96e30c6a..747bab3c6d 100644 --- a/src/Umbraco.Tests/UmbracoExamine/SearchTests.cs +++ b/src/Umbraco.Tests/UmbracoExamine/SearchTests.cs @@ -3,18 +3,15 @@ using System.Collections.Generic; using System.Linq; using LightInject; using Examine; +using Examine.Search; using NUnit.Framework; -using Examine.LuceneEngine.SearchCriteria; -using Examine.SearchCriteria; using Moq; using Umbraco.Core.Models; -using Umbraco.Core.Persistence; using Umbraco.Core.Persistence.Querying; using Umbraco.Core.Services; -using Umbraco.Examine; using Umbraco.Tests.Testing; using Umbraco.Core.PropertyEditors; -using Umbraco.Core.Strings; +using Umbraco.Examine; namespace Umbraco.Tests.UmbracoExamine { @@ -68,15 +65,15 @@ namespace Umbraco.Tests.UmbracoExamine var searcher = indexer.GetSearcher(); - var numberSortedCriteria = searcher.CreateCriteria() - .ParentId(1148).And() + var numberSortedCriteria = searcher.CreateQuery() + .ParentId(1148) .OrderBy(new SortableField("sortOrder", SortType.Int)); - var numberSortedResult = searcher.Search(numberSortedCriteria.Compile()); + var numberSortedResult = numberSortedCriteria.Execute(); - var stringSortedCriteria = searcher.CreateCriteria() - .ParentId(1148).And() + var stringSortedCriteria = searcher.CreateQuery() + .ParentId(1148) .OrderBy(new SortableField("sortOrder"));//will default to string - var stringSortedResult = searcher.Search(stringSortedCriteria.Compile()); + var stringSortedResult = stringSortedCriteria.Execute(); Assert.AreEqual(12, numberSortedResult.TotalItemCount); Assert.AreEqual(12, stringSortedResult.TotalItemCount); diff --git a/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj b/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj index 465544960c..afb3cfa9d7 100644 --- a/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj +++ b/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj @@ -88,7 +88,7 @@ - + diff --git a/src/Umbraco.Web/Editors/ExamineManagementController.cs b/src/Umbraco.Web/Editors/ExamineManagementController.cs index bce2c4a438..b583babee3 100644 --- a/src/Umbraco.Web/Editors/ExamineManagementController.cs +++ b/src/Umbraco.Web/Editors/ExamineManagementController.cs @@ -74,7 +74,7 @@ namespace Umbraco.Web.Editors throw new HttpResponseException(msg); var results = Examine.ExamineExtensions.TryParseLuceneQuery(query) - ? searcher.Search(searcher.CreateCriteria().RawQuery(query), maxResults: pageSize * (pageIndex + 1)) + ? searcher.CreateQuery().NativeQuery(query).Execute(maxResults: pageSize * (pageIndex + 1)) : searcher.Search(query, maxResults: pageSize * (pageIndex + 1)); var pagedResults = results.Skip(pageIndex * pageSize); diff --git a/src/Umbraco.Web/IPublishedContentQuery.cs b/src/Umbraco.Web/IPublishedContentQuery.cs index 3ab1c5e3ae..cc388ad094 100644 --- a/src/Umbraco.Web/IPublishedContentQuery.cs +++ b/src/Umbraco.Web/IPublishedContentQuery.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Xml.XPath; +using Examine.Search; using Umbraco.Core; using Umbraco.Core.Models.PublishedContent; using Umbraco.Core.Xml; @@ -34,21 +35,21 @@ namespace Umbraco.Web /// /// Searches content. /// - IEnumerable Search(string term, bool useWildCards = true, string indexName = null); + IEnumerable Search(string term, string indexName = null); /// /// Searches content. /// - IEnumerable Search(int skip, int take, out long totalRecords, string term, bool useWildCards = true, string indexName = null); + IEnumerable Search(string term, int skip, int take, out long totalRecords, string indexName = null); /// - /// Searches content. + /// Executes the query and converts the results to PublishedSearchResult. /// - IEnumerable Search(Examine.SearchCriteria.ISearchCriteria criteria, Examine.ISearcher searchProvider = null); + IEnumerable Search(IQueryExecutor query); /// - /// Searches content. + /// Executes the query and converts the results to PublishedSearchResult. /// - IEnumerable Search(int skip, int take, out long totalRecords, Examine.SearchCriteria.ISearchCriteria criteria, Examine.ISearcher searcher = null); + IEnumerable Search(IQueryExecutor query, int skip, int take, out long totalRecords); } } diff --git a/src/Umbraco.Web/PublishedCache/XmlPublishedCache/PublishedMediaCache.cs b/src/Umbraco.Web/PublishedCache/XmlPublishedCache/PublishedMediaCache.cs index 3f776830a6..229a981510 100644 --- a/src/Umbraco.Web/PublishedCache/XmlPublishedCache/PublishedMediaCache.cs +++ b/src/Umbraco.Web/PublishedCache/XmlPublishedCache/PublishedMediaCache.cs @@ -6,9 +6,8 @@ using System.Linq; using System.Threading; using System.Xml.XPath; using Examine; -using Examine.LuceneEngine.SearchCriteria; using Examine.Providers; -using Examine.SearchCriteria; +using Examine.Search; using Lucene.Net.Store; using Umbraco.Core; using Umbraco.Core.Logging; @@ -16,7 +15,6 @@ using Umbraco.Core.Models; using Umbraco.Core.Models.PublishedContent; using Umbraco.Core.Xml; using Umbraco.Examine; -using umbraco; using Umbraco.Core.Cache; using Umbraco.Core.Services; using Umbraco.Web.Composing; @@ -108,10 +106,10 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache // first check in Examine for the cache values // +(+parentID:-1) +__IndexType:media - var criteria = searchProvider.CreateCriteria("media"); + var criteria = searchProvider.CreateQuery("media"); var filter = criteria.ParentId(-1).Not().Field(UmbracoExamineIndex.IndexPathFieldName, "-1,-21,".MultipleCharacterWildcard()); - var result = searchProvider.Search(filter.Compile()); + var result = filter.Execute(); if (result != null) return result.Select(x => CreateFromCacheValues(ConvertFromSearchResult(x))); } @@ -294,10 +292,10 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache // // note that since the use of the wildcard, it automatically escapes it in Lucene. - var criteria = searchProvider.CreateCriteria("media"); + var criteria = searchProvider.CreateQuery("media"); var filter = criteria.Id(id.ToInvariantString()).Not().Field(UmbracoExamineIndex.IndexPathFieldName, "-1,-21,".MultipleCharacterWildcard()); - var result = searchProvider.Search(filter.Compile()).FirstOrDefault(); + var result = filter.Execute().FirstOrDefault(); if (result != null) return ConvertFromSearchResult(result); } catch (Exception ex) @@ -508,15 +506,15 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache try { //first check in Examine as this is WAY faster - var criteria = searchProvider.CreateCriteria("media"); + var criteria = searchProvider.CreateQuery("media"); - var filter = criteria.ParentId(parentId).Not().Field(UmbracoExamineIndex.IndexPathFieldName, "-1,-21,".MultipleCharacterWildcard()); + var filter = criteria.ParentId(parentId).Not().Field(UmbracoExamineIndex.IndexPathFieldName, "-1,-21,".MultipleCharacterWildcard()) + .OrderBy(new SortableField("sortOrder", SortType.Int)); //the above filter will create a query like this, NOTE: That since the use of the wildcard, it automatically escapes it in Lucene. //+(+parentId:3113 -__Path:-1,-21,*) +__IndexType:media // sort with the Sort field (updated for 8.0) - var results = searchProvider.Search( - filter.And().OrderBy(new SortableField("sortOrder", SortType.Int)).Compile()); + var results = filter.Execute(); if (results.Any()) { diff --git a/src/Umbraco.Web/PublishedContentExtensions.cs b/src/Umbraco.Web/PublishedContentExtensions.cs index e3291f9ad5..8deec5d92a 100644 --- a/src/Umbraco.Web/PublishedContentExtensions.cs +++ b/src/Umbraco.Web/PublishedContentExtensions.cs @@ -4,12 +4,13 @@ using System.Data; using System.Linq; using System.Web; using Examine; -using Examine.LuceneEngine.SearchCriteria; +using Examine.Search; using Umbraco.Core; using Umbraco.Core.Configuration; using Umbraco.Core.Models.PublishedContent; using Umbraco.Core.Models; using Umbraco.Core.Services; +using Umbraco.Examine; using Umbraco.Web.Composing; namespace Umbraco.Web @@ -282,7 +283,7 @@ namespace Umbraco.Web #region Search - public static IEnumerable SearchDescendants(this IPublishedContent content, string term, bool useWildCards = true, string indexName = null) + public static IEnumerable SearchDescendants(this IPublishedContent content, string term, string indexName = null) { //fixme: pass in the IExamineManager @@ -292,17 +293,18 @@ namespace Umbraco.Web var searcher = index.GetSearcher(); - var t = term.Escape().Value; - if (useWildCards) - t = term.MultipleCharacterWildcard().Value; + //var t = term.Escape().Value; + //var luceneQuery = "+__Path:(" + content.Path.Replace("-", "\\-") + "*) +" + t; - var luceneQuery = "+__Path:(" + content.Path.Replace("-", "\\-") + "*) +" + t; - var crit = searcher.CreateCriteria().RawQuery(luceneQuery); + var query = searcher.CreateQuery() + .Field(UmbracoExamineIndex.IndexPathFieldName, (content.Path + ",").MultipleCharacterWildcard()) + .And() + .ManagedQuery(term); - return content.Search(crit, searcher); + return query.Execute().ToPublishedSearchResults(UmbracoContext.Current.ContentCache); } - public static IEnumerable SearchChildren(this IPublishedContent content, string term, bool useWildCards = true, string indexName = null) + public static IEnumerable SearchChildren(this IPublishedContent content, string term, string indexName = null) { //fixme: pass in the IExamineManager @@ -312,28 +314,15 @@ namespace Umbraco.Web var searcher = index.GetSearcher(); - var t = term.Escape().Value; - if (useWildCards) - t = term.MultipleCharacterWildcard().Value; + //var t = term.Escape().Value; + //var luceneQuery = "+parentID:" + content.Id + " +" + t; - var luceneQuery = "+parentID:" + content.Id + " +" + t; - var crit = searcher.CreateCriteria().RawQuery(luceneQuery); + var query = searcher.CreateQuery() + .Field("parentID", content.Id) + .And() + .ManagedQuery(term); - return content.Search(crit, searcher); - } - - public static IEnumerable Search(this IPublishedContent content, Examine.SearchCriteria.ISearchCriteria criteria, ISearcher searchProvider = null) - { - //fixme: pass in the IExamineManager - - if (searchProvider == null) - { - if (!ExamineManager.Instance.TryGetIndex(Constants.UmbracoIndexes.ExternalIndexName, out var index)) - throw new InvalidOperationException("No index found with name " + Constants.UmbracoIndexes.ExternalIndexName); - searchProvider = index.GetSearcher(); - } - var results = searchProvider.Search(criteria); - return results.ToPublishedSearchResults(UmbracoContext.Current.ContentCache); + return query.Execute().ToPublishedSearchResults(UmbracoContext.Current.ContentCache); } #endregion diff --git a/src/Umbraco.Web/PublishedContentQuery.cs b/src/Umbraco.Web/PublishedContentQuery.cs index 0864203a50..57e57445ef 100644 --- a/src/Umbraco.Web/PublishedContentQuery.cs +++ b/src/Umbraco.Web/PublishedContentQuery.cs @@ -4,9 +4,7 @@ using System.Linq; using System.Reflection; using System.Xml.XPath; using Examine; -using Examine.LuceneEngine.Providers; -using Examine.LuceneEngine.SearchCriteria; -using Examine.SearchCriteria; +using Examine.Search; using Umbraco.Core; using Umbraco.Core.Models.PublishedContent; using Umbraco.Core.Services; @@ -181,16 +179,14 @@ namespace Umbraco.Web #region Search /// - public IEnumerable Search(string term, bool useWildCards = true, string indexName = null) + public IEnumerable Search(string term, string indexName = null) { - return Search(0, 0, out _, term, useWildCards, indexName); + return Search(term, 0, 0, out _, indexName); } /// - public IEnumerable Search(int skip, int take, out long totalRecords, string term, bool useWildCards = true, string indexName = null) + public IEnumerable Search(string term, int skip, int take, out long totalRecords, string indexName = null) { - //fixme: inject IExamineManager - indexName = string.IsNullOrEmpty(indexName) ? Constants.UmbracoIndexes.ExternalIndexName : indexName; @@ -209,25 +205,17 @@ namespace Umbraco.Web } /// - public IEnumerable Search(ISearchCriteria criteria, ISearcher searchProvider = null) + public IEnumerable Search(IQueryExecutor query) { - return Search(0, 0, out _, criteria, searchProvider); + return Search(query, 0, 0, out _); } /// - public IEnumerable Search(int skip, int take, out long totalRecords, ISearchCriteria criteria, ISearcher searcher = null) + public IEnumerable Search(IQueryExecutor query, int skip, int take, out long totalRecords) { - //fixme: inject IExamineManager - if (searcher == null) - { - if (!ExamineManager.Instance.TryGetIndex(Constants.UmbracoIndexes.ExternalIndexName, out var index)) - throw new InvalidOperationException($"No index found by name {Constants.UmbracoIndexes.ExternalIndexName}"); - searcher = index.GetSearcher(); - } - var results = skip == 0 && take == 0 - ? searcher.Search(criteria) - : searcher.Search(criteria, maxResults: skip + take); + ? query.Execute() + : query.Execute(maxResults: skip + take); totalRecords = results.TotalItemCount; return results.ToPublishedSearchResults(_contentCache); diff --git a/src/Umbraco.Web/Search/ExamineComponent.cs b/src/Umbraco.Web/Search/ExamineComponent.cs index 555414da44..71061a5cb3 100644 --- a/src/Umbraco.Web/Search/ExamineComponent.cs +++ b/src/Umbraco.Web/Search/ExamineComponent.cs @@ -490,9 +490,7 @@ namespace Umbraco.Web.Search while (page * pageSize < total) { //paging with examine, see https://shazwazza.com/post/paging-with-examine/ - var results = searcher.Search( - searcher.CreateCriteria().Field("nodeType", id).Compile(), - maxResults: pageSize * (page + 1)); + var results = searcher.CreateQuery().Field("nodeType", id).Execute(maxResults: pageSize * (page + 1)); total = results.TotalItemCount; var paged = results.Skip(page * pageSize); diff --git a/src/Umbraco.Web/Search/UmbracoTreeSearcher.cs b/src/Umbraco.Web/Search/UmbracoTreeSearcher.cs index c3ab7318a0..47e73d383c 100644 --- a/src/Umbraco.Web/Search/UmbracoTreeSearcher.cs +++ b/src/Umbraco.Web/Search/UmbracoTreeSearcher.cs @@ -109,11 +109,9 @@ namespace Umbraco.Web.Search return Enumerable.Empty(); } - var raw = internalSearcher.CreateCriteria().RawQuery(sb.ToString()); - - var result = internalSearcher + var result = internalSearcher.CreateQuery().NativeQuery(sb.ToString()) //only return the number of items specified to read up to the amount of records to fill from 0 -> the number of items on the page requested - .Search(raw, Convert.ToInt32(pageSize * (pageIndex + 1))); + .Execute(Convert.ToInt32(pageSize * (pageIndex + 1))); totalFound = result.TotalItemCount; diff --git a/src/Umbraco.Web/Umbraco.Web.csproj b/src/Umbraco.Web/Umbraco.Web.csproj index eb6eab9829..9c44539f92 100755 --- a/src/Umbraco.Web/Umbraco.Web.csproj +++ b/src/Umbraco.Web/Umbraco.Web.csproj @@ -62,7 +62,7 @@ - + 2.6.2.25 diff --git a/src/Umbraco.Web/UmbracoHelper.cs b/src/Umbraco.Web/UmbracoHelper.cs index 9698e3e024..b98db65b27 100644 --- a/src/Umbraco.Web/UmbracoHelper.cs +++ b/src/Umbraco.Web/UmbracoHelper.cs @@ -775,62 +775,6 @@ namespace Umbraco.Web #endregion - #region Search - - /// - /// Searches content. - /// - /// - /// - /// - /// - public IEnumerable Search(string term, bool useWildCards = true, string indexName = null) - { - return ContentQuery.Search(term, useWildCards, indexName); - } - - /// - /// Searches content. - /// - /// - /// - /// - /// - /// - /// - /// - public IEnumerable Search(int skip, int take, out long totalRecords, string term, bool useWildCards = true, string indexName = null) - { - return ContentQuery.Search(skip, take, out totalRecords, term, useWildCards, indexName); - } - - /// - /// Searhes content. - /// - /// - /// - /// - /// - /// - /// - public IEnumerable Search(int skip, int take, out long totalRecords, Examine.SearchCriteria.ISearchCriteria criteria, Examine.Providers.BaseSearchProvider searchProvider = null) - { - return ContentQuery.Search(skip, take, out totalRecords, criteria, searchProvider); - } - - /// - /// Searhes content. - /// - /// - /// - /// - public IEnumerable Search(Examine.SearchCriteria.ISearchCriteria criteria, Examine.Providers.BaseSearchProvider searchProvider = null) - { - return ContentQuery.Search(criteria, searchProvider); - } - - #endregion - #region Strings /// From 748462689354f3b79cf0d439af3848e17498e296 Mon Sep 17 00:00:00 2001 From: Shannon Date: Mon, 17 Dec 2018 13:11:51 +1100 Subject: [PATCH 09/11] Allows passing in a culture to the IPublishedContentQuery search methods --- src/Umbraco.Examine/IUmbracoIndex.cs | 9 +++- src/Umbraco.Examine/Umbraco.Examine.csproj | 1 - src/Umbraco.Examine/UmbracoExamineIndex.cs | 8 +++ src/Umbraco.Examine/UmbracoExamineSearcher.cs | 52 ------------------- src/Umbraco.Web/IPublishedContentQuery.cs | 4 +- src/Umbraco.Web/PublishedContentQuery.cs | 51 ++++++++++++++---- 6 files changed, 60 insertions(+), 65 deletions(-) delete mode 100644 src/Umbraco.Examine/UmbracoExamineSearcher.cs diff --git a/src/Umbraco.Examine/IUmbracoIndex.cs b/src/Umbraco.Examine/IUmbracoIndex.cs index e70652a342..9461434fff 100644 --- a/src/Umbraco.Examine/IUmbracoIndex.cs +++ b/src/Umbraco.Examine/IUmbracoIndex.cs @@ -1,4 +1,5 @@ -using Examine; +using System.Collections.Generic; +using Examine; namespace Umbraco.Examine { @@ -21,5 +22,11 @@ namespace Umbraco.Examine /// * non-published Variants /// bool PublishedValuesOnly { get; } + + /// + /// Returns a list of all indexed fields + /// + /// + IEnumerable GetFields(); } } diff --git a/src/Umbraco.Examine/Umbraco.Examine.csproj b/src/Umbraco.Examine/Umbraco.Examine.csproj index a037c3028e..2bdf6f833d 100644 --- a/src/Umbraco.Examine/Umbraco.Examine.csproj +++ b/src/Umbraco.Examine/Umbraco.Examine.csproj @@ -88,7 +88,6 @@ - diff --git a/src/Umbraco.Examine/UmbracoExamineIndex.cs b/src/Umbraco.Examine/UmbracoExamineIndex.cs index 1933874fc7..fc7f834a29 100644 --- a/src/Umbraco.Examine/UmbracoExamineIndex.cs +++ b/src/Umbraco.Examine/UmbracoExamineIndex.cs @@ -97,6 +97,14 @@ namespace Umbraco.Examine public bool PublishedValuesOnly { get; protected set; } = false; + /// + public IEnumerable GetFields() + { + //we know this is a LuceneSearcher + var searcher = (LuceneSearcher) GetSearcher(); + return searcher.GetAllIndexedFields(); + } + protected ConfigIndexCriteria ConfigIndexCriteria { get; private set; } /// diff --git a/src/Umbraco.Examine/UmbracoExamineSearcher.cs b/src/Umbraco.Examine/UmbracoExamineSearcher.cs deleted file mode 100644 index 50c6c21e37..0000000000 --- a/src/Umbraco.Examine/UmbracoExamineSearcher.cs +++ /dev/null @@ -1,52 +0,0 @@ -//using System; -//using System.ComponentModel; -//using System.IO; -//using System.Linq; -//using Umbraco.Core; -//using Examine.LuceneEngine.Providers; -//using Lucene.Net.Analysis; -//using Lucene.Net.Index; -//using Umbraco.Core.Composing; -//using Umbraco.Examine.Config; -//using Directory = Lucene.Net.Store.Directory; -//using Examine.LuceneEngine; - -//namespace Umbraco.Examine -//{ -// /// -// /// An Examine searcher which uses Lucene.Net as the -// /// -// public class UmbracoExamineSearcher : LuceneSearcher -// { -// /// -// /// Constructor to allow for creating an indexer at runtime -// /// -// /// -// /// -// /// -// public UmbracoExamineSearcher(string name, Directory luceneDirectory, Analyzer analyzer, FieldValueTypeCollection fieldValueTypeCollection) -// : base(name, luceneDirectory, analyzer, fieldValueTypeCollection) -// { -// } - -// /// -// public UmbracoExamineSearcher(string name, IndexWriter writer, Analyzer analyzer, FieldValueTypeCollection fieldValueTypeCollection) -// : base(name, writer, analyzer, fieldValueTypeCollection) -// { -// } - -// /// -// /// Returns a list of fields to search on, this will also exclude the IndexPathFieldName and node type alias -// /// -// /// -// public override string[] GetAllIndexedFields() -// { -// var fields = base.GetAllIndexedFields(); -// return fields -// .Where(x => x != UmbracoExamineIndexer.IndexPathFieldName) -// .Where(x => x != LuceneIndex.ItemTypeFieldName) -// .ToArray(); -// } - -// } -//} diff --git a/src/Umbraco.Web/IPublishedContentQuery.cs b/src/Umbraco.Web/IPublishedContentQuery.cs index cc388ad094..72ca5d6ddb 100644 --- a/src/Umbraco.Web/IPublishedContentQuery.cs +++ b/src/Umbraco.Web/IPublishedContentQuery.cs @@ -35,12 +35,12 @@ namespace Umbraco.Web /// /// Searches content. /// - IEnumerable Search(string term, string indexName = null); + IEnumerable Search(string term, string culture = null, string indexName = null); /// /// Searches content. /// - IEnumerable Search(string term, int skip, int take, out long totalRecords, string indexName = null); + IEnumerable Search(string term, int skip, int take, out long totalRecords, string culture = null, string indexName = null); /// /// Executes the query and converts the results to PublishedSearchResult. diff --git a/src/Umbraco.Web/PublishedContentQuery.cs b/src/Umbraco.Web/PublishedContentQuery.cs index 57e57445ef..ea351b5ffd 100644 --- a/src/Umbraco.Web/PublishedContentQuery.cs +++ b/src/Umbraco.Web/PublishedContentQuery.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Linq; using System.Reflection; +using System.Text.RegularExpressions; using System.Xml.XPath; using Examine; using Examine.Search; @@ -9,6 +10,7 @@ using Umbraco.Core; using Umbraco.Core.Models.PublishedContent; using Umbraco.Core.Services; using Umbraco.Core.Xml; +using Umbraco.Examine; using Umbraco.Web.PublishedCache; namespace Umbraco.Web @@ -179,26 +181,49 @@ namespace Umbraco.Web #region Search /// - public IEnumerable Search(string term, string indexName = null) + public IEnumerable Search(string term, string culture = null, string indexName = null) { - return Search(term, 0, 0, out _, indexName); + return Search(term, 0, 0, out _, culture, indexName); } /// - public IEnumerable Search(string term, int skip, int take, out long totalRecords, string indexName = null) + public IEnumerable Search(string term, int skip, int take, out long totalRecords, string culture = null, string indexName = null) { indexName = string.IsNullOrEmpty(indexName) ? Constants.UmbracoIndexes.ExternalIndexName : indexName; - if (!ExamineManager.Instance.TryGetIndex(indexName, out var index)) - throw new InvalidOperationException($"No index found by name {indexName}"); + if (!ExamineManager.Instance.TryGetIndex(indexName, out var index) || !(index is IUmbracoIndex umbIndex)) + throw new InvalidOperationException($"No index found by name {indexName} or is not of type {typeof(IUmbracoIndex)}"); - var searcher = index.GetSearcher(); + var searcher = umbIndex.GetSearcher(); - var results = skip == 0 && take == 0 - ? searcher.Search(term) - : searcher.Search(term, maxResults: skip + take); + ISearchResults results; + if (!culture.IsNullOrWhiteSpace()) + { + results = searcher.Search(term, (skip == 0 && take == 0 + ? 500 //default max results + : skip + take)); + } + else + { + //get all index fields suffixed with the culture name supplied + var cultureFields = new List(); + var fields = umbIndex.GetFields(); + var qry = searcher.CreateQuery().Field(UmbracoContentIndex.VariesByCultureFieldName, 1); //must vary by culture + // ReSharper disable once LoopCanBeConvertedToQuery + foreach (var field in fields) + { + var match = CultureIsoCodeFieldName.Match(field); + if (match.Success && match.Groups.Count == 2 && culture.InvariantEquals(match.Groups[1].Value)) + cultureFields.Add(field); + } + + results = qry.And().ManagedQuery(term, cultureFields.ToArray()).Execute((skip == 0 && take == 0 + ? 500 //default max results + : skip + take)); + + } totalRecords = results.TotalItemCount; return results.ToPublishedSearchResults(_contentCache); @@ -221,6 +246,14 @@ namespace Umbraco.Web return results.ToPublishedSearchResults(_contentCache); } + /// + /// Matches a culture iso name suffix + /// + /// + /// myFieldName_en-us will match the "en-us" + /// + private static readonly Regex CultureIsoCodeFieldName = new Regex("^[_\\w]+_([a-z]{2}-[a-z0-9]{2,4})$", RegexOptions.Compiled); + #endregion } From 07d23208982a7906bfb6becfc1d040767e4bf376 Mon Sep 17 00:00:00 2001 From: Shannon Date: Mon, 17 Dec 2018 13:44:11 +1100 Subject: [PATCH 10/11] fixes bool --- src/Umbraco.Web/PublishedContentQuery.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Umbraco.Web/PublishedContentQuery.cs b/src/Umbraco.Web/PublishedContentQuery.cs index ea351b5ffd..79f6e07282 100644 --- a/src/Umbraco.Web/PublishedContentQuery.cs +++ b/src/Umbraco.Web/PublishedContentQuery.cs @@ -199,7 +199,7 @@ namespace Umbraco.Web var searcher = umbIndex.GetSearcher(); ISearchResults results; - if (!culture.IsNullOrWhiteSpace()) + if (culture.IsNullOrWhiteSpace()) { results = searcher.Search(term, (skip == 0 && take == 0 ? 500 //default max results From 23eabee1a263c30301a65c4e29666059216934c2 Mon Sep 17 00:00:00 2001 From: Stephan Date: Thu, 20 Dec 2018 13:29:57 +0100 Subject: [PATCH 11/11] Misc fixes --- src/Umbraco.Web/IPublishedContentQuery.cs | 15 +++++++++++++++ src/Umbraco.Web/PublishedContentQuery.cs | 13 ++++++------- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/src/Umbraco.Web/IPublishedContentQuery.cs b/src/Umbraco.Web/IPublishedContentQuery.cs index 72ca5d6ddb..c3a065b9dc 100644 --- a/src/Umbraco.Web/IPublishedContentQuery.cs +++ b/src/Umbraco.Web/IPublishedContentQuery.cs @@ -35,11 +35,26 @@ namespace Umbraco.Web /// /// Searches content. /// + /// Term to search. + /// Optional culture. + /// Optional index name. + /// + /// When the is not specified, all cultures are searched. + /// IEnumerable Search(string term, string culture = null, string indexName = null); /// /// Searches content. /// + /// Term to search. + /// Numbers of items to skip. + /// Numbers of items to return. + /// Total number of matching items. + /// Optional culture. + /// Optional index name. + /// + /// When the is not specified, all cultures are searched. + /// IEnumerable Search(string term, int skip, int take, out long totalRecords, string culture = null, string indexName = null); /// diff --git a/src/Umbraco.Web/PublishedContentQuery.cs b/src/Umbraco.Web/PublishedContentQuery.cs index 79f6e07282..3d8f36ec1a 100644 --- a/src/Umbraco.Web/PublishedContentQuery.cs +++ b/src/Umbraco.Web/PublishedContentQuery.cs @@ -198,12 +198,13 @@ namespace Umbraco.Web var searcher = umbIndex.GetSearcher(); + // default to max 500 results + var count = skip == 0 && take == 0 ? 500 : skip + take; + ISearchResults results; if (culture.IsNullOrWhiteSpace()) { - results = searcher.Search(term, (skip == 0 && take == 0 - ? 500 //default max results - : skip + take)); + results = searcher.Search(term, count); } else { @@ -219,10 +220,8 @@ namespace Umbraco.Web cultureFields.Add(field); } - results = qry.And().ManagedQuery(term, cultureFields.ToArray()).Execute((skip == 0 && take == 0 - ? 500 //default max results - : skip + take)); - + qry = qry.And().ManagedQuery(term, cultureFields.ToArray()); + results = qry.Execute(count); } totalRecords = results.TotalItemCount;