Adds parent id option, finally getting some examine tests passing
This commit is contained in:
@@ -457,7 +457,7 @@ namespace Umbraco.Core
|
||||
/// <returns>The is null or white space.</returns>
|
||||
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)
|
||||
|
||||
@@ -56,7 +56,7 @@
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="Examine, Version=2.0.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Examine.2.0.0-beta013\lib\net45\Examine.dll</HintPath>
|
||||
<HintPath>..\packages\Examine.2.0.0-beta014\lib\net45\Examine.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="ICSharpCode.SharpZipLib, Version=0.86.0.518, Culture=neutral, PublicKeyToken=1b03e6acf1164f73, processorArchitecture=MSIL">
|
||||
|
||||
@@ -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[]
|
||||
|
||||
@@ -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<string>();
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
<packages>
|
||||
<package id="AspNetWebApi.SelfHost" version="4.0.20710.0" targetFramework="net45" />
|
||||
<package id="AutoMapper" version="4.2.1" targetFramework="net461" />
|
||||
<package id="Examine" version="2.0.0-beta013" targetFramework="net461" />
|
||||
<package id="Examine" version="2.0.0-beta014" targetFramework="net461" />
|
||||
<package id="LightInject" version="4.0.8" targetFramework="net461" />
|
||||
<package id="log4net" version="2.0.5" targetFramework="net461" />
|
||||
<package id="Lucene.Net" version="3.0.3" targetFramework="net461" />
|
||||
|
||||
@@ -121,7 +121,7 @@
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="Examine, Version=2.0.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Examine.2.0.0-beta013\lib\net45\Examine.dll</HintPath>
|
||||
<HintPath>..\packages\Examine.2.0.0-beta014\lib\net45\Examine.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="ICSharpCode.SharpZipLib, Version=0.86.0.518, Culture=neutral, PublicKeyToken=1b03e6acf1164f73, processorArchitecture=MSIL">
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<package id="AutoMapper" version="4.2.1" targetFramework="net461" />
|
||||
<package id="ClientDependency" version="1.8.4" targetFramework="net45" />
|
||||
<package id="ClientDependency-Mvc5" version="1.8.0.0" targetFramework="net45" />
|
||||
<package id="Examine" version="2.0.0-beta013" targetFramework="net461" />
|
||||
<package id="Examine" version="2.0.0-beta014" targetFramework="net461" />
|
||||
<package id="ImageProcessor" version="2.3.3.0" targetFramework="net45" />
|
||||
<package id="ImageProcessor.Web" version="4.5.3.0" targetFramework="net45" />
|
||||
<package id="log4net" version="2.0.5" targetFramework="net461" />
|
||||
|
||||
@@ -114,7 +114,7 @@
|
||||
<HintPath>..\packages\dotless.1.4.1.0\lib\dotless.Core.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Examine, Version=2.0.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Examine.2.0.0-beta013\lib\net45\Examine.dll</HintPath>
|
||||
<HintPath>..\packages\Examine.2.0.0-beta014\lib\net45\Examine.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="HtmlAgilityPack, Version=1.4.9.0, Culture=neutral, PublicKeyToken=bd319b19eaf3b43a, processorArchitecture=MSIL">
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<package id="AutoMapper" version="4.2.1" targetFramework="net461" />
|
||||
<package id="ClientDependency" version="1.8.4" targetFramework="net45" />
|
||||
<package id="dotless" version="1.4.1.0" targetFramework="net45" />
|
||||
<package id="Examine" version="2.0.0-beta013" targetFramework="net461" />
|
||||
<package id="Examine" version="2.0.0-beta014" targetFramework="net461" />
|
||||
<package id="HtmlAgilityPack" version="1.4.9" targetFramework="net45" />
|
||||
<package id="LightInject" version="4.0.8" targetFramework="net461" />
|
||||
<package id="LightInject.Mvc" version="1.0.0.4" targetFramework="net45" />
|
||||
|
||||
@@ -281,22 +281,7 @@ namespace UmbracoExamine
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ensures that the node being indexed is of a correct type and is a descendent of the parent id specified.
|
||||
/// </summary>
|
||||
/// <param name="node"></param>
|
||||
/// <returns></returns>
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Reindexes all supported types
|
||||
/// </summary>
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
using System;
|
||||
|
||||
namespace UmbracoExamine
|
||||
{
|
||||
/// <summary>
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,7 +83,7 @@
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="Examine, Version=2.0.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Examine.2.0.0-beta013\lib\net45\Examine.dll</HintPath>
|
||||
<HintPath>..\packages\Examine.2.0.0-beta014\lib\net45\Examine.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="ICSharpCode.SharpZipLib, Version=0.86.0.518, Culture=neutral, PublicKeyToken=1b03e6acf1164f73, processorArchitecture=MSIL">
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="Examine" version="2.0.0-beta013" targetFramework="net461" />
|
||||
<package id="Examine" version="2.0.0-beta014" targetFramework="net461" />
|
||||
<package id="Lucene.Net" version="3.0.3" targetFramework="net461" />
|
||||
<package id="Lucene.Net.Contrib" version="3.0.3" targetFramework="net461" />
|
||||
<package id="SharpZipLib" version="0.86.0" targetFramework="net45" />
|
||||
|
||||
Reference in New Issue
Block a user