diff --git a/build/NuSpecs/UmbracoCms.Web.nuspec b/build/NuSpecs/UmbracoCms.Web.nuspec index adf090c69b..51d7e3b8d0 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 - + - + @@ -72,7 +72,7 @@ - + @@ -88,8 +88,8 @@ - + Properties\SolutionInfo.cs diff --git a/src/Umbraco.Examine/UmbracoContentIndex.cs b/src/Umbraco.Examine/UmbracoContentIndex.cs index 910941ea7b..c584f5bf51 100644 --- a/src/Umbraco.Examine/UmbracoContentIndex.cs +++ b/src/Umbraco.Examine/UmbracoContentIndex.cs @@ -52,13 +52,13 @@ namespace Umbraco.Examine /// public UmbracoContentIndex( string name, - IEnumerable fieldDefinitions, + FieldDefinitionCollection fieldDefinitions, Directory luceneDirectory, Analyzer defaultAnalyzer, 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)); @@ -122,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; } @@ -200,41 +200,17 @@ 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); //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); } - - /// - /// 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/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.Examine/UmbracoExamineIndex.cs b/src/Umbraco.Examine/UmbracoExamineIndex.cs index 15f1a75955..fc7f834a29 100644 --- a/src/Umbraco.Examine/UmbracoExamineIndex.cs +++ b/src/Umbraco.Examine/UmbracoExamineIndex.cs @@ -20,10 +20,9 @@ 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, IUmbracoIndexer, IIndexDiagnostics + public abstract class UmbracoExamineIndex : LuceneIndex, IUmbracoIndex, IIndexDiagnostics { // note // wrapping all operations that end up calling base.SafelyProcessQueueItems in a safe call @@ -53,6 +52,7 @@ namespace Umbraco.Examine { ProfilingLogger = Current.ProfilingLogger; _configBased = true; + _diagnostics = new UmbracoExamineIndexDiagnostics(this, ProfilingLogger.Logger); } /// @@ -67,12 +67,12 @@ namespace Umbraco.Examine /// protected UmbracoExamineIndex( string name, - IEnumerable fieldDefinitions, + FieldDefinitionCollection fieldDefinitions, Directory luceneDirectory, 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)); @@ -86,60 +86,10 @@ 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; } - /// - /// 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.Name, field); - } - } - - - return base.CreateFieldValueTypes(indexValueTypesFactory); - } - /// /// When set to true Umbraco will keep the index in sync with Umbraco data automatically /// @@ -147,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; } /// @@ -174,12 +132,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 UmbracoFieldDefinitionCollection.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 +161,29 @@ namespace Umbraco.Examine ConfigIndexCriteria = CreateFieldDefinitionsFromConfig(indexSet); foreach (var fieldDefinition in ConfigIndexCriteria.StandardFields.Union(ConfigIndexCriteria.UserFields)) { - FieldDefinitionCollection.TryAdd(fieldDefinition.Name, 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.Name, fieldDefinition); - } + //replace any existing or add + FieldDefinitionCollection.AddOrUpdate(fieldDefinition); } } 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.Examine/UmbracoFieldDefinitionCollection.cs b/src/Umbraco.Examine/UmbracoFieldDefinitionCollection.cs new file mode 100644 index 0000000000..97d1f68727 --- /dev/null +++ b/src/Umbraco.Examine/UmbracoFieldDefinitionCollection.cs @@ -0,0 +1,75 @@ +using Examine; + +namespace Umbraco.Examine +{ + /// + /// Custom allowing dynamic creation of + /// + public class UmbracoFieldDefinitionCollection : FieldDefinitionCollection + { + + public UmbracoFieldDefinitionCollection() + : 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 + ///// + ///// + ///// + ///// + //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 + + //} + } +} diff --git a/src/Umbraco.Examine/UmbracoMemberIndex.cs b/src/Umbraco.Examine/UmbracoMemberIndex.cs index 28b46f72dd..27490e0e18 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, @@ -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/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 ed2324e02c..7d1753a6b2 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/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.Tests/UmbracoExamine/IndexTest.cs b/src/Umbraco.Tests/UmbracoExamine/IndexTest.cs index 35e3524459..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(); @@ -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(); @@ -139,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); } @@ -210,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 @@ -222,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()); } } @@ -253,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 @@ -264,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()); } } @@ -283,14 +281,13 @@ namespace Umbraco.Tests.UmbracoExamine validator: new ContentValueSetValidator(false))) using (indexer.ProcessNonAsync()) { - rebuilder.RegisterIndex(indexer.Name); var searcher = indexer.GetSearcher(); //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 @@ -301,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); } } @@ -335,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 a01d49cc22..747bab3c6d 100644 --- a/src/Umbraco.Tests/UmbracoExamine/SearchTests.cs +++ b/src/Umbraco.Tests/UmbracoExamine/SearchTests.cs @@ -3,17 +3,15 @@ using System.Collections.Generic; using System.Linq; using LightInject; using Examine; +using Examine.Search; using NUnit.Framework; -using Examine.LuceneEngine.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 { @@ -62,21 +60,20 @@ namespace Umbraco.Tests.UmbracoExamine using (var indexer = IndexInitializer.GetUmbracoIndexer(ProfilingLogger, luceneDir)) using (indexer.ProcessNonAsync()) { - rebuilder.RegisterIndex(indexer.Name); indexer.CreateIndex(); rebuilder.Populate(indexer); 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() - .OrderBy("sortOrder"); //will default to string - var stringSortedResult = searcher.Search(stringSortedCriteria.Compile()); + var stringSortedCriteria = searcher.CreateQuery() + .ParentId(1148) + .OrderBy(new SortableField("sortOrder"));//will default to string + 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 f0663e54e2..ea5cbafcb0 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..b583babee3 100644 --- a/src/Umbraco.Web/Editors/ExamineManagementController.cs +++ b/src/Umbraco.Web/Editors/ExamineManagementController.cs @@ -74,8 +74,8 @@ 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.Search(query, true, 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); @@ -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/IPublishedContentQuery.cs b/src/Umbraco.Web/IPublishedContentQuery.cs index 3ab1c5e3ae..c3a065b9dc 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,36 @@ namespace Umbraco.Web /// /// Searches content. /// - IEnumerable Search(string term, bool useWildCards = true, string indexName = null); + /// 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. /// - IEnumerable Search(int skip, int take, out long totalRecords, string term, bool useWildCards = true, string indexName = null); + /// 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); /// - /// 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 f203d5d2c9..229a981510 100644 --- a/src/Umbraco.Web/PublishedCache/XmlPublishedCache/PublishedMediaCache.cs +++ b/src/Umbraco.Web/PublishedCache/XmlPublishedCache/PublishedMediaCache.cs @@ -6,8 +6,8 @@ using System.Linq; using System.Threading; using System.Xml.XPath; using Examine; -using Examine.LuceneEngine.SearchCriteria; using Examine.Providers; +using Examine.Search; using Lucene.Net.Store; using Umbraco.Core; using Umbraco.Core.Logging; @@ -15,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; @@ -107,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))); } @@ -293,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) @@ -507,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 f82c20fc4b..709b1ff9e6 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 @@ -266,7 +267,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 @@ -276,17 +277,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 @@ -296,28 +298,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 774393f3de..3d8f36ec1a 100644 --- a/src/Umbraco.Web/PublishedContentQuery.cs +++ b/src/Umbraco.Web/PublishedContentQuery.cs @@ -2,15 +2,15 @@ using System.Collections.Generic; using System.Linq; using System.Reflection; +using System.Text.RegularExpressions; 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; using Umbraco.Core.Xml; +using Umbraco.Examine; using Umbraco.Web.PublishedCache; namespace Umbraco.Web @@ -181,58 +181,78 @@ namespace Umbraco.Web #region Search /// - public IEnumerable Search(string term, bool useWildCards = true, string indexName = null) + public IEnumerable Search(string term, string culture = null, string indexName = null) { - return Search(0, 0, out _, term, useWildCards, indexName); + return Search(term, 0, 0, out _, culture, 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 culture = null, string indexName = null) { - //fixme: inject IExamineManager - 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, true) - : searcher.Search(term, true, maxResults: skip + take); + // default to max 500 results + var count = skip == 0 && take == 0 ? 500 : skip + take; - totalRecords = results.TotalItemCount; - return results.ToPublishedSearchResults(_contentCache); - } - - /// - public IEnumerable Search(ISearchCriteria criteria, ISearcher searchProvider = null) - { - return Search(0, 0, out _, criteria, searchProvider); - } - - /// - public IEnumerable Search(int skip, int take, out long totalRecords, ISearchCriteria criteria, ISearcher searcher = null) - { - //fixme: inject IExamineManager - if (searcher == null) + ISearchResults results; + if (culture.IsNullOrWhiteSpace()) { - if (!ExamineManager.Instance.TryGetIndex(Constants.UmbracoIndexes.ExternalIndexName, out var index)) - throw new InvalidOperationException($"No index found by name {Constants.UmbracoIndexes.ExternalIndexName}"); - searcher = index.GetSearcher(); + results = searcher.Search(term, count); + } + 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); + } + + qry = qry.And().ManagedQuery(term, cultureFields.ToArray()); + results = qry.Execute(count); } + totalRecords = results.TotalItemCount; + return results.ToPublishedSearchResults(_contentCache); + } + + /// + public IEnumerable Search(IQueryExecutor query) + { + return Search(query, 0, 0, out _); + } + + /// + public IEnumerable Search(IQueryExecutor query, int skip, int take, out long totalRecords) + { 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); } + /// + /// 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 } diff --git a/src/Umbraco.Web/Search/ExamineComponent.cs b/src/Umbraco.Web/Search/ExamineComponent.cs index 6d67169533..71061a5cb3 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; @@ -149,7 +150,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,10 +167,10 @@ 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); } - /// /// Called to rebuild empty indexes on startup /// @@ -480,7 +481,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(); @@ -489,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); @@ -686,7 +685,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)) @@ -723,7 +722,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)) @@ -752,7 +751,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)) { @@ -782,7 +781,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/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 7f469ddce6..4e792a456c 100755 --- a/src/Umbraco.Web/Umbraco.Web.csproj +++ b/src/Umbraco.Web/Umbraco.Web.csproj @@ -63,7 +63,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 ///