diff --git a/src/Umbraco.Core/StringExtensions.cs b/src/Umbraco.Core/StringExtensions.cs index 6fed93deca..1580c7750c 100644 --- a/src/Umbraco.Core/StringExtensions.cs +++ b/src/Umbraco.Core/StringExtensions.cs @@ -457,7 +457,7 @@ namespace Umbraco.Core /// The is null or white space. public static bool IsNullOrWhiteSpace(this string str) { - return (str == null) || (str.Trim().Length == 0); + return string.IsNullOrWhiteSpace(str); } public static string IfNullOrWhiteSpace(this string str, string defaultValue) diff --git a/src/Umbraco.Tests/Umbraco.Tests.csproj b/src/Umbraco.Tests/Umbraco.Tests.csproj index 60821ba828..273915d1a3 100644 --- a/src/Umbraco.Tests/Umbraco.Tests.csproj +++ b/src/Umbraco.Tests/Umbraco.Tests.csproj @@ -56,7 +56,7 @@ True - ..\packages\Examine.2.0.0-beta013\lib\net45\Examine.dll + ..\packages\Examine.2.0.0-beta014\lib\net45\Examine.dll True diff --git a/src/Umbraco.Tests/UmbracoExamine/IndexInitializer.cs b/src/Umbraco.Tests/UmbracoExamine/IndexInitializer.cs index 110c091670..6be64990a6 100644 --- a/src/Umbraco.Tests/UmbracoExamine/IndexInitializer.cs +++ b/src/Umbraco.Tests/UmbracoExamine/IndexInitializer.cs @@ -33,7 +33,8 @@ namespace Umbraco.Tests.UmbracoExamine IMediaService mediaService = null, IDataTypeService dataTypeService = null, IMemberService memberService = null, - IUserService userService = null) + IUserService userService = null, + UmbracoContentIndexerOptions options = null) { if (contentService == null) { @@ -102,7 +103,10 @@ namespace Umbraco.Tests.UmbracoExamine //i.IndexSecondsInterval = 1; - var options = new UmbracoContentIndexerOptions(false, false); + if (options == null) + { + options = new UmbracoContentIndexerOptions(false, false, null); + } var i = new UmbracoContentIndexer( new[] diff --git a/src/Umbraco.Tests/UmbracoExamine/IndexTest.cs b/src/Umbraco.Tests/UmbracoExamine/IndexTest.cs index c4b2f4a6ba..46633c2756 100644 --- a/src/Umbraco.Tests/UmbracoExamine/IndexTest.cs +++ b/src/Umbraco.Tests/UmbracoExamine/IndexTest.cs @@ -52,7 +52,7 @@ namespace Umbraco.Tests.UmbracoExamine new TermQuery(new Term(LuceneIndexer.IndexNodeIdFieldName, TestContentService.ProtectedNode.ToString())), Occur.MUST)); - var collector = TopScoreDocCollector.Create(int.MaxValue, true); + var collector = TopScoreDocCollector.Create(100, true); searcher.Search(protectedQuery, collector); @@ -115,10 +115,12 @@ namespace Umbraco.Tests.UmbracoExamine public void Index_Move_Media_To_Non_Indexable_ParentID() { using (var luceneDir = new RAMDirectory()) - using (var indexer = IndexInitializer.GetUmbracoIndexer(ProfilingLogger, luceneDir)) - using (var session = new ThreadScopedIndexSession(indexer.SearcherContext)) + using (var indexer1 = IndexInitializer.GetUmbracoIndexer(ProfilingLogger, luceneDir, + //make parent id 2222 + options: new UmbracoContentIndexerOptions(false, false, 2222))) + using (var session = new ThreadScopedIndexSession(indexer1.SearcherContext)) { - var searcher = indexer.GetSearcher(); + var searcher = indexer1.GetSearcher(); //get a node from the data repo (this one exists underneath 2222) var node = _mediaService.GetLatestMediaByXpath("//*[string-length(@id)>0 and number(@id)>0]") @@ -131,30 +133,20 @@ namespace Umbraco.Tests.UmbracoExamine Assert.AreEqual("-1,1111,2222,2112", currPath); //ensure it's indexed - indexer.ReIndexNode(node, IndexTypes.Media); + indexer1.ReIndexNode(node, IndexTypes.Media); session.WaitForChanges(); - - //now ensure it's deleted + + //it will exist because it exists under 2222 var results = searcher.Search(searcher.CreateSearchCriteria().Id(2112).Compile()); Assert.AreEqual(1, results.Count()); - //change the parent node id to be the one it used to exist under - var existingCriteria = indexer.IndexerData; - indexer.IndexerData = new IndexCriteria(existingCriteria.StandardFields, existingCriteria.UserFields, existingCriteria.IncludeNodeTypes, existingCriteria.ExcludeNodeTypes, - 2222); - //now mimic moving the node underneath 1116 instead of 2222 node.SetAttributeValue("path", currPath.Replace("2222", "1116")); node.SetAttributeValue("parentID", "1116"); //now reindex the node, this should first delete it and then NOT add it because of the parent id constraint - indexer.ReIndexNode(node, IndexTypes.Media); - - //RESET the parent id - existingCriteria = ((IndexCriteria)indexer.IndexerData); - indexer.IndexerData = new IndexCriteria(existingCriteria.StandardFields, existingCriteria.UserFields, existingCriteria.IncludeNodeTypes, existingCriteria.ExcludeNodeTypes, - null); + indexer1.ReIndexNode(node, IndexTypes.Media); session.WaitForChanges(); @@ -188,7 +180,7 @@ namespace Umbraco.Tests.UmbracoExamine writer.Commit(); //make sure the content is gone. This is done with lucene APIs, not examine! - var collector = TopScoreDocCollector.Create(int.MaxValue, true); + var collector = TopScoreDocCollector.Create(100, true); var query = new TermQuery(contentTerm); s = (IndexSearcher)searcher.GetSearcher(); //make sure the searcher is up do date. s.Search(query, collector); @@ -197,7 +189,7 @@ namespace Umbraco.Tests.UmbracoExamine //call our indexing methods indexer.IndexAll(IndexTypes.Content); - collector = TopScoreDocCollector.Create(int.MaxValue, true); + collector = TopScoreDocCollector.Create(100, true); s = searcher.GetSearcher(); //make sure the searcher is up do date. s.Search(query, collector); //var ids = new List(); diff --git a/src/Umbraco.Tests/packages.config b/src/Umbraco.Tests/packages.config index a4f996aad3..636ba243f9 100644 --- a/src/Umbraco.Tests/packages.config +++ b/src/Umbraco.Tests/packages.config @@ -2,7 +2,7 @@ - + diff --git a/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj b/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj index 94b9fb5882..f5f41339d5 100644 --- a/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj +++ b/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj @@ -121,7 +121,7 @@ True - ..\packages\Examine.2.0.0-beta013\lib\net45\Examine.dll + ..\packages\Examine.2.0.0-beta014\lib\net45\Examine.dll True diff --git a/src/Umbraco.Web.UI/packages.config b/src/Umbraco.Web.UI/packages.config index 67a8067584..af0ac65e86 100644 --- a/src/Umbraco.Web.UI/packages.config +++ b/src/Umbraco.Web.UI/packages.config @@ -3,7 +3,7 @@ - + diff --git a/src/Umbraco.Web/Umbraco.Web.csproj b/src/Umbraco.Web/Umbraco.Web.csproj index c8d715911e..00d4cdb813 100644 --- a/src/Umbraco.Web/Umbraco.Web.csproj +++ b/src/Umbraco.Web/Umbraco.Web.csproj @@ -114,7 +114,7 @@ ..\packages\dotless.1.4.1.0\lib\dotless.Core.dll - ..\packages\Examine.2.0.0-beta013\lib\net45\Examine.dll + ..\packages\Examine.2.0.0-beta014\lib\net45\Examine.dll True diff --git a/src/Umbraco.Web/packages.config b/src/Umbraco.Web/packages.config index 92b488bcfe..7f6230500c 100644 --- a/src/Umbraco.Web/packages.config +++ b/src/Umbraco.Web/packages.config @@ -3,7 +3,7 @@ - + diff --git a/src/UmbracoExamine/BaseUmbracoIndexer.cs b/src/UmbracoExamine/BaseUmbracoIndexer.cs index a373cdecc8..9ac781acce 100644 --- a/src/UmbracoExamine/BaseUmbracoIndexer.cs +++ b/src/UmbracoExamine/BaseUmbracoIndexer.cs @@ -281,22 +281,7 @@ namespace UmbracoExamine return true; } - - /// - /// Ensures that the node being indexed is of a correct type and is a descendent of the parent id specified. - /// - /// - /// - protected override bool ValidateDocument(XElement node) - { - //check if this document is a descendent of the parent - if (IndexerData.ParentNodeId.HasValue && IndexerData.ParentNodeId.Value > 0) - if (!((string)node.Attribute("path")).Contains("," + IndexerData.ParentNodeId.Value.ToString() + ",")) - return false; - - return base.ValidateDocument(node); - } - + /// /// Reindexes all supported types /// diff --git a/src/UmbracoExamine/UmbracoContentIndexerOptions.cs b/src/UmbracoExamine/UmbracoContentIndexerOptions.cs index f71f972a76..7f7003a97d 100644 --- a/src/UmbracoExamine/UmbracoContentIndexerOptions.cs +++ b/src/UmbracoExamine/UmbracoContentIndexerOptions.cs @@ -1,3 +1,5 @@ +using System; + namespace UmbracoExamine { /// @@ -7,11 +9,14 @@ namespace UmbracoExamine { public bool SupportUnpublishedContent { get; private set; } public bool SupportProtectedContent { get; private set; } + //TODO: We should make this a GUID! But to do that we sort of need to store the 'Path' as a comma list of GUIDs instead of int + public int? ParentId { get; private set; } - public UmbracoContentIndexerOptions(bool supportUnpublishedContent, bool supportProtectedContent) + public UmbracoContentIndexerOptions(bool supportUnpublishedContent, bool supportProtectedContent, int? parentId) { SupportUnpublishedContent = supportUnpublishedContent; SupportProtectedContent = supportProtectedContent; + ParentId = parentId; } } } \ No newline at end of file diff --git a/src/UmbracoExamine/UmbracoContentValueSetValidator.cs b/src/UmbracoExamine/UmbracoContentValueSetValidator.cs index 5b38bc81e8..48f06809a6 100644 --- a/src/UmbracoExamine/UmbracoContentValueSetValidator.cs +++ b/src/UmbracoExamine/UmbracoContentValueSetValidator.cs @@ -1,6 +1,8 @@ +using System; using System.Linq; using Examine; using Examine.LuceneEngine.Providers; +using Umbraco.Core; using Umbraco.Core.Services; namespace UmbracoExamine @@ -24,16 +26,27 @@ namespace UmbracoExamine //must have a 'path' if (valueSet.Values.ContainsKey("path") == false) return false; - var path = valueSet.Values["path"]; + var path = valueSet.Values["path"] == null ? string.Empty : valueSet.Values["path"][0].ToString(); + + // Test for access if we're only indexing published content // return nothing if we're not supporting protected content and it is protected, and we're not supporting unpublished content if (_options.SupportUnpublishedContent == false && (_options.SupportProtectedContent == false && path != null - && _publicAccessService.IsProtected(path.First().ToString()))) + && _publicAccessService.IsProtected(path))) { return false; } + + //check if this document is a descendent of the parent + if (_options.ParentId.HasValue && _options.ParentId.Value > 0) + { + if (path.IsNullOrWhiteSpace()) return false; + if (path.Contains(string.Concat(",", _options.ParentId.Value, ",")) == false) + return false; + } + return true; } } diff --git a/src/UmbracoExamine/UmbracoExamine.csproj b/src/UmbracoExamine/UmbracoExamine.csproj index 5b82aad568..9ac6ebbe3e 100644 --- a/src/UmbracoExamine/UmbracoExamine.csproj +++ b/src/UmbracoExamine/UmbracoExamine.csproj @@ -83,7 +83,7 @@ - ..\packages\Examine.2.0.0-beta013\lib\net45\Examine.dll + ..\packages\Examine.2.0.0-beta014\lib\net45\Examine.dll True diff --git a/src/UmbracoExamine/packages.config b/src/UmbracoExamine/packages.config index 6ffe666e13..31be3468d2 100644 --- a/src/UmbracoExamine/packages.config +++ b/src/UmbracoExamine/packages.config @@ -1,6 +1,6 @@  - +