Gets all index tests passing
This commit is contained in:
@@ -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-beta014\lib\net45\Examine.dll</HintPath>
|
||||
<HintPath>..\packages\Examine.2.0.0-beta019\lib\net45\Examine.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="ICSharpCode.SharpZipLib, Version=0.86.0.518, Culture=neutral, PublicKeyToken=1b03e6acf1164f73, processorArchitecture=MSIL">
|
||||
@@ -544,7 +544,7 @@
|
||||
<Compile Include="UmbracoExamine\TestIndexField.cs" />
|
||||
<Compile Include="UI\LegacyDialogTests.cs" />
|
||||
<Compile Include="UmbracoExamine\ExamineDemoDataMediaService.cs" />
|
||||
<Compile Include="UmbracoExamine\TestContentService.cs" />
|
||||
<Compile Include="UmbracoExamine\ExamineDemoDataContentService.cs" />
|
||||
<Compile Include="UriExtensionsTests.cs" />
|
||||
<Compile Include="UriUtilityTests.cs" />
|
||||
<Compile Include="Resolvers\PackageActionsResolverTests.cs" />
|
||||
|
||||
@@ -40,7 +40,7 @@ namespace Umbraco.Tests.UmbracoExamine
|
||||
|
||||
}
|
||||
|
||||
private readonly TestContentService _contentService = new TestContentService();
|
||||
private readonly ExamineDemoDataContentService _contentService = new ExamineDemoDataContentService();
|
||||
private static UmbracoContentIndexer _indexer;
|
||||
private Lucene.Net.Store.Directory _luceneDir;
|
||||
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Xml.Linq;
|
||||
using System.Xml.XPath;
|
||||
using Umbraco.Core.Persistence;
|
||||
using Umbraco.Core.Persistence.Repositories;
|
||||
using UmbracoExamine;
|
||||
|
||||
namespace Umbraco.Tests.UmbracoExamine
|
||||
{
|
||||
//TODO: This is ultra hack and still left over from legacy but still works for testing atm
|
||||
public class ExamineDemoDataContentService
|
||||
{
|
||||
public const int ProtectedNode = 1142;
|
||||
|
||||
public ExamineDemoDataContentService(string contentXml = null)
|
||||
{
|
||||
if (contentXml == null)
|
||||
{
|
||||
contentXml = TestFiles.umbraco;
|
||||
}
|
||||
_xContent = XDocument.Parse(contentXml);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Return the XDocument containing the xml from the umbraco.config xml file
|
||||
/// </summary>
|
||||
/// <param name="xpath"></param>
|
||||
/// <returns></returns>
|
||||
/// <remarks>
|
||||
/// This is no different in the test suite as published content
|
||||
/// </remarks>
|
||||
public XDocument GetLatestContentByXPath(string xpath)
|
||||
{
|
||||
var xdoc = XDocument.Parse("<content></content>");
|
||||
xdoc.Root.Add(_xContent.XPathSelectElements(xpath));
|
||||
|
||||
return xdoc;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Return the XDocument containing the xml from the umbraco.config xml file
|
||||
/// </summary>
|
||||
/// <param name="xpath"></param>
|
||||
/// <returns></returns>
|
||||
public XDocument GetPublishedContentByXPath(string xpath)
|
||||
{
|
||||
return GetContentByXPath(xpath, _xContent);
|
||||
}
|
||||
|
||||
private XDocument GetContentByXPath(string xpath, XDocument content)
|
||||
{
|
||||
var xdoc = XDocument.Parse("<content></content>");
|
||||
xdoc.Root.Add(content.XPathSelectElements(xpath));
|
||||
|
||||
return xdoc;
|
||||
}
|
||||
|
||||
private readonly XDocument _xContent;
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -38,7 +38,37 @@ namespace Umbraco.Tests.UmbracoExamine
|
||||
{
|
||||
if (contentService == null)
|
||||
{
|
||||
contentService = Mock.Of<IContentService>();
|
||||
long totalRecs;
|
||||
|
||||
var demoData = new ExamineDemoDataContentService();
|
||||
|
||||
var allRecs = demoData.GetLatestContentByXPath("//*[@isDoc]")
|
||||
.Root
|
||||
.Elements()
|
||||
.Select(x => Mock.Of<IContent>(
|
||||
m =>
|
||||
m.Id == (int)x.Attribute("id") &&
|
||||
m.ParentId == (int)x.Attribute("parentID") &&
|
||||
m.Level == (int)x.Attribute("level") &&
|
||||
m.CreatorId == 0 &&
|
||||
m.SortOrder == (int)x.Attribute("sortOrder") &&
|
||||
m.CreateDate == (DateTime)x.Attribute("createDate") &&
|
||||
m.UpdateDate == (DateTime)x.Attribute("updateDate") &&
|
||||
m.Name == (string)x.Attribute("nodeName") &&
|
||||
m.Path == (string)x.Attribute("path") &&
|
||||
m.Properties == new PropertyCollection() &&
|
||||
m.ContentType == Mock.Of<IContentType>(mt =>
|
||||
mt.Icon == "test" &&
|
||||
mt.Alias == x.Name.LocalName &&
|
||||
mt.Id == (int)x.Attribute("nodeType"))))
|
||||
.ToArray();
|
||||
|
||||
|
||||
contentService = Mock.Of<IContentService>(
|
||||
x => x.GetPagedDescendants(
|
||||
It.IsAny<int>(), It.IsAny<long>(), It.IsAny<int>(), out totalRecs, It.IsAny<string>(), It.IsAny<Direction>(), It.IsAny<string>())
|
||||
==
|
||||
allRecs);
|
||||
}
|
||||
if (userService == null)
|
||||
{
|
||||
|
||||
@@ -29,18 +29,43 @@ namespace Umbraco.Tests.UmbracoExamine
|
||||
public class IndexTest : ExamineBaseTest
|
||||
{
|
||||
|
||||
///// <summary>
|
||||
/// <summary>
|
||||
/// Check that the node signalled as protected in the content service is not present in the index.
|
||||
/// </summary>
|
||||
[Test]
|
||||
[Test]
|
||||
public void Rebuild_Index()
|
||||
{
|
||||
|
||||
using (var luceneDir = new RAMDirectory())
|
||||
using (var indexer = IndexInitializer.GetUmbracoIndexer(ProfilingLogger, luceneDir))
|
||||
using (var session = new ThreadScopedIndexSession(indexer.SearcherContext))
|
||||
{
|
||||
var searcher = indexer.GetSearcher();
|
||||
|
||||
//create the whole thing
|
||||
indexer.RebuildIndex();
|
||||
session.WaitForChanges();
|
||||
|
||||
var result = searcher.Find(searcher.CreateCriteria().All().Compile());
|
||||
|
||||
Assert.AreEqual(29, result.TotalItemCount);
|
||||
}
|
||||
}
|
||||
|
||||
///// <summary>
|
||||
/// <summary>
|
||||
/// Check that the node signalled as protected in the content service is not present in the index.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void Index_Protected_Content_Not_Indexed()
|
||||
{
|
||||
|
||||
using (var luceneDir = new RAMDirectory())
|
||||
using (var indexer = IndexInitializer.GetUmbracoIndexer(ProfilingLogger, luceneDir))
|
||||
using (var session = new ThreadScopedIndexSession(indexer.SearcherContext))
|
||||
using (var searcher = indexer.GetSearcher().GetSearcher())
|
||||
{
|
||||
//create the whole thing
|
||||
indexer.RebuildIndex();
|
||||
session.WaitForChanges();
|
||||
|
||||
var protectedQuery = new BooleanQuery();
|
||||
protectedQuery.Add(
|
||||
new BooleanClause(
|
||||
@@ -49,11 +74,11 @@ namespace Umbraco.Tests.UmbracoExamine
|
||||
|
||||
protectedQuery.Add(
|
||||
new BooleanClause(
|
||||
new TermQuery(new Term(LuceneIndexer.IndexNodeIdFieldName, TestContentService.ProtectedNode.ToString())),
|
||||
new TermQuery(new Term(LuceneIndexer.IndexNodeIdFieldName, ExamineDemoDataContentService.ProtectedNode.ToString())),
|
||||
Occur.MUST));
|
||||
|
||||
var collector = TopScoreDocCollector.Create(100, true);
|
||||
|
||||
|
||||
searcher.Search(protectedQuery, collector);
|
||||
|
||||
Assert.AreEqual(0, collector.TotalHits, "Protected node should not be indexed");
|
||||
@@ -65,22 +90,13 @@ namespace Umbraco.Tests.UmbracoExamine
|
||||
public void Index_Move_Media_From_Non_Indexable_To_Indexable_ParentID()
|
||||
{
|
||||
using (var luceneDir = new RAMDirectory())
|
||||
using (var indexer = IndexInitializer.GetUmbracoIndexer(ProfilingLogger, luceneDir))
|
||||
using (var indexer = IndexInitializer.GetUmbracoIndexer(ProfilingLogger, luceneDir,
|
||||
//make parent id 1116
|
||||
options: new UmbracoContentIndexerOptions(false, false, 1116)))
|
||||
using (var session = new ThreadScopedIndexSession(indexer.SearcherContext))
|
||||
{
|
||||
var searcher = indexer.GetSearcher();
|
||||
|
||||
//change parent id to 1116
|
||||
var existingCriteria = indexer.IndexerData;
|
||||
indexer.IndexerData = new IndexCriteria(existingCriteria.StandardFields, existingCriteria.UserFields, existingCriteria.IncludeNodeTypes, existingCriteria.ExcludeNodeTypes,
|
||||
1116);
|
||||
|
||||
//rebuild so it excludes children unless they are under 1116
|
||||
indexer.RebuildIndex();
|
||||
|
||||
//ensure that node 2112 doesn't exist
|
||||
var results = searcher.Search(searcher.CreateSearchCriteria().Id(2112).Compile());
|
||||
Assert.AreEqual(0, results.Count());
|
||||
|
||||
//get a node from the data repo (this one exists underneath 2222)
|
||||
var node = _mediaService.GetLatestMediaByXpath("//*[string-length(@id)>0 and number(@id)>0]")
|
||||
.Root
|
||||
@@ -91,6 +107,15 @@ namespace Umbraco.Tests.UmbracoExamine
|
||||
var currPath = (string)node.Attribute("path"); //should be : -1,1111,2222,2112
|
||||
Assert.AreEqual("-1,1111,2222,2112", currPath);
|
||||
|
||||
//ensure it's indexed
|
||||
indexer.ReIndexNode(node, IndexTypes.Media);
|
||||
|
||||
session.WaitForChanges();
|
||||
|
||||
//it will not exist because it exists under 2222
|
||||
var results = searcher.Search(searcher.CreateSearchCriteria().Id(2112).Compile());
|
||||
Assert.AreEqual(0, results.Count());
|
||||
|
||||
//now mimic moving 2112 to 1116
|
||||
//node.SetAttributeValue("path", currPath.Replace("2222", "1116"));
|
||||
node.SetAttributeValue("path", "-1,1116,2112");
|
||||
@@ -99,14 +124,11 @@ namespace Umbraco.Tests.UmbracoExamine
|
||||
//now reindex the node, this should first delete it and then WILL 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);
|
||||
session.WaitForChanges();
|
||||
|
||||
//now ensure it's deleted
|
||||
var newResults = searcher.Search(searcher.CreateSearchCriteria().Id(2112).Compile());
|
||||
Assert.AreEqual(1, newResults.Count());
|
||||
//now ensure it exists
|
||||
results = searcher.Search(searcher.CreateSearchCriteria().Id(2112).Compile());
|
||||
Assert.AreEqual(1, results.Count());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -166,42 +188,40 @@ namespace Umbraco.Tests.UmbracoExamine
|
||||
{
|
||||
using (var luceneDir = new RAMDirectory())
|
||||
using (var indexer = IndexInitializer.GetUmbracoIndexer(ProfilingLogger, luceneDir))
|
||||
using (var session = new ThreadScopedIndexSession(indexer.SearcherContext))
|
||||
{
|
||||
var searcher = indexer.GetSearcher();
|
||||
|
||||
|
||||
var s = searcher.GetSearcher();
|
||||
|
||||
//first delete all 'Content' (not media). This is done by directly manipulating the index with the Lucene API, not examine!
|
||||
//create the whole thing
|
||||
indexer.RebuildIndex();
|
||||
session.WaitForChanges();
|
||||
|
||||
var contentTerm = new Term(LuceneIndexer.IndexTypeFieldName, IndexTypes.Content);
|
||||
var writer = indexer.GetIndexWriter();
|
||||
writer.DeleteDocuments(contentTerm);
|
||||
writer.Commit();
|
||||
|
||||
//make sure the content is gone. This is done with lucene APIs, not examine!
|
||||
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);
|
||||
Assert.AreEqual(0, collector.TotalHits);
|
||||
var result = searcher.Find(searcher.CreateCriteria().Field(LuceneIndexer.IndexTypeFieldName, IndexTypes.Content).Compile());
|
||||
Assert.AreEqual(21, result.TotalItemCount);
|
||||
|
||||
//delete all content
|
||||
foreach (var r in result)
|
||||
{
|
||||
indexer.DeleteFromIndex(r.LongId);
|
||||
}
|
||||
session.WaitForChanges();
|
||||
|
||||
//ensure it's all gone
|
||||
result = searcher.Find(searcher.CreateCriteria().Field(LuceneIndexer.IndexTypeFieldName, IndexTypes.Content).Compile());
|
||||
Assert.AreEqual(0, result.TotalItemCount);
|
||||
|
||||
//call our indexing methods
|
||||
indexer.IndexAll(IndexTypes.Content);
|
||||
|
||||
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>();
|
||||
//for (var i = 0; i < collector.Count;i++)
|
||||
//{
|
||||
// ids.Add(s.Doc(collector.GetDocId(i)).GetValues("__NodeId")[0]);
|
||||
//}
|
||||
Assert.AreEqual(20, collector.TotalHits);
|
||||
session.WaitForChanges();
|
||||
|
||||
result = searcher.Find(searcher.CreateCriteria().Field(LuceneIndexer.IndexTypeFieldName, IndexTypes.Content).Compile());
|
||||
Assert.AreEqual(21, result.TotalItemCount);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This will delete an item from the index and ensure that all children of the node are deleted too!
|
||||
@@ -211,14 +231,21 @@ namespace Umbraco.Tests.UmbracoExamine
|
||||
{
|
||||
using (var luceneDir = new RAMDirectory())
|
||||
using (var indexer = IndexInitializer.GetUmbracoIndexer(ProfilingLogger, luceneDir))
|
||||
using (var session = new ThreadScopedIndexSession(indexer.SearcherContext))
|
||||
{
|
||||
var searcher = indexer.GetSearcher();
|
||||
|
||||
//create the whole thing
|
||||
indexer.RebuildIndex();
|
||||
session.WaitForChanges();
|
||||
|
||||
//now delete a node that has children
|
||||
|
||||
indexer.DeleteFromIndex(1140.ToString());
|
||||
//this node had children: 1141 & 1142, let's ensure they are also removed
|
||||
|
||||
session.WaitForChanges();
|
||||
|
||||
var results = searcher.Search(searcher.CreateSearchCriteria().Id(1141).Compile());
|
||||
Assert.AreEqual(0, results.Count());
|
||||
|
||||
|
||||
@@ -1,125 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Xml.Linq;
|
||||
using System.Xml.XPath;
|
||||
using Umbraco.Core.Persistence;
|
||||
using Umbraco.Core.Persistence.Repositories;
|
||||
using UmbracoExamine;
|
||||
|
||||
namespace Umbraco.Tests.UmbracoExamine
|
||||
{
|
||||
/// <summary>
|
||||
/// A mock data service used to return content from the XML data file created with CWS
|
||||
/// </summary>
|
||||
public class TestContentService
|
||||
{
|
||||
public const int ProtectedNode = 1142;
|
||||
|
||||
public TestContentService(string contentXml = null, string mediaXml = null)
|
||||
{
|
||||
if (contentXml == null)
|
||||
{
|
||||
contentXml = TestFiles.umbraco;
|
||||
}
|
||||
if (mediaXml == null)
|
||||
{
|
||||
mediaXml = TestFiles.media;
|
||||
}
|
||||
_xContent = XDocument.Parse(contentXml);
|
||||
_xMedia = XDocument.Parse(mediaXml);
|
||||
}
|
||||
|
||||
#region IContentService Members
|
||||
|
||||
/// <summary>
|
||||
/// Return the XDocument containing the xml from the umbraco.config xml file
|
||||
/// </summary>
|
||||
/// <param name="xpath"></param>
|
||||
/// <returns></returns>
|
||||
/// <remarks>
|
||||
/// This is no different in the test suite as published content
|
||||
/// </remarks>
|
||||
public XDocument GetLatestContentByXPath(string xpath)
|
||||
{
|
||||
var xdoc = XDocument.Parse("<content></content>");
|
||||
xdoc.Root.Add(_xContent.XPathSelectElements(xpath));
|
||||
|
||||
return xdoc;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Return the XDocument containing the xml from the umbraco.config xml file
|
||||
/// </summary>
|
||||
/// <param name="xpath"></param>
|
||||
/// <returns></returns>
|
||||
public XDocument GetPublishedContentByXPath(string xpath)
|
||||
{
|
||||
return GetContentByXPath(xpath, _xContent);
|
||||
}
|
||||
|
||||
private XDocument GetContentByXPath(string xpath, XDocument content)
|
||||
{
|
||||
var xdoc = XDocument.Parse("<content></content>");
|
||||
xdoc.Root.Add(content.XPathSelectElements(xpath));
|
||||
|
||||
return xdoc;
|
||||
}
|
||||
|
||||
public string StripHtml(string value)
|
||||
{
|
||||
const string pattern = @"<(.|\n)*?>";
|
||||
return Regex.Replace(value, pattern, string.Empty);
|
||||
}
|
||||
|
||||
public bool IsProtected(int nodeId, string path)
|
||||
{
|
||||
// single node is marked as protected for test indexer
|
||||
// hierarchy is not important for this test
|
||||
return nodeId == ProtectedNode;
|
||||
}
|
||||
|
||||
private List<string> _userPropNames;
|
||||
public IEnumerable<string> GetAllUserPropertyNames()
|
||||
{
|
||||
if (_userPropNames == null)
|
||||
{
|
||||
var xpath = "//*[count(@id)>0 and @id != -1]";
|
||||
_userPropNames = GetPublishedContentByXPath(xpath)
|
||||
.Root
|
||||
.Elements() //each page
|
||||
.SelectMany(x => x.Elements().Where(e => e.Attribute("id") == null)) //each page property (no @id)
|
||||
.Select(x => x.Name.LocalName) //the name of the property
|
||||
.Distinct()
|
||||
.Union(GetContentByXPath(xpath, _xMedia)
|
||||
.Root
|
||||
.Elements() //each page
|
||||
.SelectMany(x => x.Elements().Where(e => e.Attribute("id") == null)) //each page property (no @id)
|
||||
.Select(x => (string)x.Attribute("alias")) //the name of the property NOTE: We are using the legacy XML here.
|
||||
.Distinct()).ToList();
|
||||
}
|
||||
return _userPropNames;
|
||||
}
|
||||
|
||||
private List<string> _sysPropNames;
|
||||
public IEnumerable<string> GetAllSystemPropertyNames()
|
||||
{
|
||||
if (_sysPropNames == null)
|
||||
{
|
||||
_sysPropNames = UmbracoContentIndexer.IndexFieldPolicies.Select(x => x.Name).ToList();
|
||||
}
|
||||
return _sysPropNames;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private readonly XDocument _xContent;
|
||||
private readonly XDocument _xMedia;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -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-beta014" targetFramework="net461" />
|
||||
<package id="Examine" version="2.0.0-beta019" 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-beta014\lib\net45\Examine.dll</HintPath>
|
||||
<HintPath>..\packages\Examine.2.0.0-beta019\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-beta014" targetFramework="net461" />
|
||||
<package id="Examine" version="2.0.0-beta019" 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-beta014\lib\net45\Examine.dll</HintPath>
|
||||
<HintPath>..\packages\Examine.2.0.0-beta019\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-beta014" targetFramework="net461" />
|
||||
<package id="Examine" version="2.0.0-beta019" 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" />
|
||||
|
||||
@@ -52,10 +52,10 @@ namespace UmbracoExamine
|
||||
}
|
||||
|
||||
protected BaseUmbracoIndexer(
|
||||
IEnumerable<FieldDefinition> fieldDefinitions,
|
||||
Directory luceneDirectory,
|
||||
Analyzer defaultAnalyzer,
|
||||
ProfilingLogger profilingLogger,
|
||||
IEnumerable<FieldDefinition> fieldDefinitions,
|
||||
Directory luceneDirectory,
|
||||
Analyzer defaultAnalyzer,
|
||||
ProfilingLogger profilingLogger,
|
||||
IValueSetValidator validator = null,
|
||||
FacetConfiguration facetConfiguration = null, IDictionary<string, Func<string, IIndexValueType>> indexValueTypes = null)
|
||||
: base(fieldDefinitions, luceneDirectory, defaultAnalyzer, validator, facetConfiguration, indexValueTypes)
|
||||
@@ -97,6 +97,23 @@ namespace UmbracoExamine
|
||||
|
||||
protected ProfilingLogger ProfilingLogger { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Overridden to ensure that
|
||||
/// </summary>
|
||||
/// <param name="originalDefinitions"></param>
|
||||
/// <returns></returns>
|
||||
protected override IEnumerable<FieldDefinition> InitializeFieldDefinitions(IEnumerable<FieldDefinition> originalDefinitions)
|
||||
{
|
||||
var fd = base.InitializeFieldDefinitions(originalDefinitions).ToList();
|
||||
fd.AddRange(new[]
|
||||
{
|
||||
new FieldDefinition(IndexPathFieldName, FieldDefinitionTypes.Raw),
|
||||
new FieldDefinition(NodeTypeAliasFieldName, FieldDefinitionTypes.Raw),
|
||||
new FieldDefinition(IconFieldName, FieldDefinitionTypes.Raw)
|
||||
});
|
||||
return fd;
|
||||
}
|
||||
|
||||
public bool UseTempStorage
|
||||
{
|
||||
get { return _localTempStorageIndexer.LuceneDirectory != null; }
|
||||
|
||||
@@ -76,6 +76,11 @@ namespace UmbracoExamine
|
||||
|
||||
SupportProtectedContent = options.SupportProtectedContent;
|
||||
SupportUnpublishedContent = options.SupportUnpublishedContent;
|
||||
ParentId = options.ParentId;
|
||||
//backward compat hack:
|
||||
IndexerData = new IndexCriteria(Enumerable.Empty<IIndexField>(), Enumerable.Empty<IIndexField>(), Enumerable.Empty<string>(), Enumerable.Empty<string>(),
|
||||
//hack to set the parent Id for backwards compat, when using this ctor the IndexerData will (should) always be null
|
||||
options.ParentId);
|
||||
|
||||
ContentService = contentService;
|
||||
MediaService = mediaService;
|
||||
@@ -151,6 +156,11 @@ namespace UmbracoExamine
|
||||
/// </summary>
|
||||
public bool SupportUnpublishedContent { get; protected set; }
|
||||
|
||||
/// <summary>
|
||||
/// If set this will filter the content items allowed to be indexed
|
||||
/// </summary>
|
||||
public int? ParentId { get; protected set; }
|
||||
|
||||
protected override IEnumerable<string> SupportedTypes
|
||||
{
|
||||
get
|
||||
@@ -176,29 +186,28 @@ namespace UmbracoExamine
|
||||
/// <param name="nodeId">ID of the node to delete</param>
|
||||
public override void DeleteFromIndex(string nodeId)
|
||||
{
|
||||
throw new NotImplementedException("Fix DeleteFromIndex!");
|
||||
//find all descendants based on path
|
||||
var descendantPath = string.Format(@"\-1\,*{0}\,*", nodeId);
|
||||
var rawQuery = string.Format("{0}:{1}", IndexPathFieldName, descendantPath);
|
||||
var searcher = GetSearcher();
|
||||
var c = searcher.CreateSearchCriteria();
|
||||
var filtered = c.RawQuery(rawQuery);
|
||||
var results = searcher.Search(filtered);
|
||||
|
||||
////find all descendants based on path
|
||||
//var descendantPath = string.Format(@"\-1\,*{0}\,*", nodeId);
|
||||
//var rawQuery = string.Format("{0}:{1}", IndexPathFieldName, descendantPath);
|
||||
//var c = InternalSearcher.CreateSearchCriteria();
|
||||
//var filtered = c.RawQuery(rawQuery);
|
||||
//var results = InternalSearcher.Search(filtered);
|
||||
ProfilingLogger.Logger.Debug(GetType(), string.Format("DeleteFromIndex with query: {0} (found {1} results)", rawQuery, results.TotalItemCount));
|
||||
|
||||
//DataService.LogService.AddVerboseLog(int.Parse(nodeId), string.Format("DeleteFromIndex with query: {0} (found {1} results)", rawQuery, results.Count()));
|
||||
//need to create a delete queue item for each one found
|
||||
foreach (var r in results)
|
||||
{
|
||||
EnqueueIndexOperation(new IndexOperation()
|
||||
{
|
||||
Operation = IndexOperationType.Delete,
|
||||
Item = new IndexItem(null, "", r.Id.ToString())
|
||||
});
|
||||
//SaveDeleteIndexQueueItem(new KeyValuePair<string, string>(IndexNodeIdFieldName, r.Id.ToString()));
|
||||
}
|
||||
|
||||
////need to create a delete queue item for each one found
|
||||
//foreach (var r in results)
|
||||
//{
|
||||
// EnqueueIndexOperation(new IndexOperation()
|
||||
// {
|
||||
// Operation = IndexOperationType.Delete,
|
||||
// Item = new IndexItem(null, "", r.Id.ToString())
|
||||
// });
|
||||
// //SaveDeleteIndexQueueItem(new KeyValuePair<string, string>(IndexNodeIdFieldName, r.Id.ToString()));
|
||||
//}
|
||||
|
||||
//base.DeleteFromIndex(nodeId);
|
||||
base.DeleteFromIndex(nodeId);
|
||||
}
|
||||
#endregion
|
||||
|
||||
@@ -213,47 +222,40 @@ namespace UmbracoExamine
|
||||
switch (type)
|
||||
{
|
||||
case IndexTypes.Content:
|
||||
if (this.SupportUnpublishedContent == false)
|
||||
|
||||
var contentParentId = -1;
|
||||
if (IndexerData.ParentNodeId.HasValue && IndexerData.ParentNodeId.Value > 0)
|
||||
{
|
||||
//TODO: Need to deal with Published Content here
|
||||
|
||||
throw new NotImplementedException("NEED TO FIX PUBLISHED CONTENT INDEXING");
|
||||
|
||||
//use the base implementation which will use the published XML cache to perform the lookups
|
||||
//base.PerformIndexAll(type);
|
||||
contentParentId = IndexerData.ParentNodeId.Value;
|
||||
}
|
||||
else
|
||||
IContent[] content;
|
||||
|
||||
do
|
||||
{
|
||||
var contentParentId = -1;
|
||||
if (IndexerData.ParentNodeId.HasValue && IndexerData.ParentNodeId.Value > 0)
|
||||
long total;
|
||||
|
||||
var descendants = SupportUnpublishedContent == false
|
||||
? ContentService.GetPagedDescendants(contentParentId, pageIndex, pageSize, out total, filter: "published")
|
||||
: ContentService.GetPagedDescendants(contentParentId, pageIndex, pageSize, out total);
|
||||
|
||||
//if specific types are declared we need to post filter them
|
||||
//TODO: Update the service layer to join the cmsContentType table so we can query by content type too
|
||||
if (IndexerData.IncludeNodeTypes.Any())
|
||||
{
|
||||
contentParentId = IndexerData.ParentNodeId.Value;
|
||||
content = descendants.Where(x => IndexerData.IncludeNodeTypes.Contains(x.ContentType.Alias)).ToArray();
|
||||
}
|
||||
IContent[] content;
|
||||
|
||||
do
|
||||
else
|
||||
{
|
||||
long total;
|
||||
var descendants = ContentService.GetPagedDescendants(contentParentId, pageIndex, pageSize, out total);
|
||||
content = descendants.ToArray();
|
||||
}
|
||||
|
||||
//if specific types are declared we need to post filter them
|
||||
//TODO: Update the service layer to join the cmsContentType table so we can query by content type too
|
||||
if (IndexerData.IncludeNodeTypes.Any())
|
||||
{
|
||||
content = descendants.Where(x => IndexerData.IncludeNodeTypes.Contains(x.ContentType.Alias)).ToArray();
|
||||
}
|
||||
else
|
||||
{
|
||||
content = descendants.ToArray();
|
||||
}
|
||||
|
||||
AddNodesToIndex(GetSerializedContent(content), type);
|
||||
pageIndex++;
|
||||
AddNodesToIndex(GetSerializedContent(content), type);
|
||||
pageIndex++;
|
||||
|
||||
|
||||
} while (content.Length == pageSize);
|
||||
} while (content.Length == pageSize);
|
||||
|
||||
}
|
||||
|
||||
break;
|
||||
case IndexTypes.Media:
|
||||
|
||||
|
||||
@@ -83,7 +83,7 @@
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="Examine, Version=2.0.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Examine.2.0.0-beta014\lib\net45\Examine.dll</HintPath>
|
||||
<HintPath>..\packages\Examine.2.0.0-beta019\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-beta014" targetFramework="net461" />
|
||||
<package id="Examine" version="2.0.0-beta019" 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