Merge branch 'dev-v7' into 7.3.0
This commit is contained in:
@@ -521,7 +521,6 @@
|
||||
<Compile Include="UmbracoExamine\ExamineBaseTest.cs" />
|
||||
<Compile Include="UmbracoExamine\IndexInitializer.cs" />
|
||||
<Compile Include="UmbracoExamine\IndexTest.cs" />
|
||||
<Compile Include="UmbracoExamine\PdfIndexerTests.cs" />
|
||||
<Compile Include="UmbracoExamine\SearchTests.cs" />
|
||||
<Compile Include="UmbracoExamine\TestDataService.cs" />
|
||||
<Compile Include="UmbracoExamine\TestFiles.Designer.cs">
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Net.Mime;
|
||||
using System.Xml.XPath;
|
||||
using Examine;
|
||||
using Examine.LuceneEngine.Config;
|
||||
using Examine.LuceneEngine.Providers;
|
||||
using Lucene.Net.Analysis;
|
||||
using Lucene.Net.Analysis.Standard;
|
||||
using Lucene.Net.Store;
|
||||
using Moq;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Models.Membership;
|
||||
@@ -15,9 +14,9 @@ using Umbraco.Core.Services;
|
||||
using UmbracoExamine;
|
||||
using UmbracoExamine.Config;
|
||||
using UmbracoExamine.DataServices;
|
||||
using UmbracoExamine.PDF;
|
||||
using IContentService = UmbracoExamine.DataServices.IContentService;
|
||||
using IMediaService = UmbracoExamine.DataServices.IMediaService;
|
||||
using IContentService = Umbraco.Core.Services.IContentService;
|
||||
using IMediaService = Umbraco.Core.Services.IMediaService;
|
||||
using Version = Lucene.Net.Util.Version;
|
||||
|
||||
namespace Umbraco.Tests.UmbracoExamine
|
||||
{
|
||||
@@ -27,11 +26,11 @@ namespace Umbraco.Tests.UmbracoExamine
|
||||
internal static class IndexInitializer
|
||||
{
|
||||
public static UmbracoContentIndexer GetUmbracoIndexer(
|
||||
Lucene.Net.Store.Directory luceneDir,
|
||||
Directory luceneDir,
|
||||
Analyzer analyzer = null,
|
||||
IDataService dataService = null,
|
||||
Umbraco.Core.Services.IContentService contentService = null,
|
||||
Umbraco.Core.Services.IMediaService mediaService = null,
|
||||
IContentService contentService = null,
|
||||
IMediaService mediaService = null,
|
||||
IDataTypeService dataTypeService = null,
|
||||
IMemberService memberService = null,
|
||||
IUserService userService = null)
|
||||
@@ -42,7 +41,7 @@ namespace Umbraco.Tests.UmbracoExamine
|
||||
}
|
||||
if (contentService == null)
|
||||
{
|
||||
contentService = Mock.Of<Umbraco.Core.Services.IContentService>();
|
||||
contentService = Mock.Of<IContentService>();
|
||||
}
|
||||
if (userService == null)
|
||||
{
|
||||
@@ -73,7 +72,7 @@ namespace Umbraco.Tests.UmbracoExamine
|
||||
.ToArray();
|
||||
|
||||
|
||||
mediaService = Mock.Of<Umbraco.Core.Services.IMediaService>(
|
||||
mediaService = Mock.Of<IMediaService>(
|
||||
x => x.GetPagedDescendants(
|
||||
It.IsAny<int>(), It.IsAny<int>(), It.IsAny<int>(), out totalRecs, It.IsAny<string>(), It.IsAny<Direction>(), It.IsAny<string>())
|
||||
==
|
||||
@@ -91,7 +90,7 @@ namespace Umbraco.Tests.UmbracoExamine
|
||||
|
||||
if (analyzer == null)
|
||||
{
|
||||
analyzer = new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_29);
|
||||
analyzer = new StandardAnalyzer(Version.LUCENE_29);
|
||||
}
|
||||
|
||||
var indexSet = new IndexSet();
|
||||
@@ -113,33 +112,23 @@ namespace Umbraco.Tests.UmbracoExamine
|
||||
|
||||
return i;
|
||||
}
|
||||
public static UmbracoExamineSearcher GetUmbracoSearcher(Lucene.Net.Store.Directory luceneDir, Analyzer analyzer = null)
|
||||
public static UmbracoExamineSearcher GetUmbracoSearcher(Directory luceneDir, Analyzer analyzer = null)
|
||||
{
|
||||
if (analyzer == null)
|
||||
{
|
||||
analyzer = new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_29);
|
||||
analyzer = new StandardAnalyzer(Version.LUCENE_29);
|
||||
}
|
||||
return new UmbracoExamineSearcher(luceneDir, analyzer);
|
||||
}
|
||||
|
||||
public static LuceneSearcher GetLuceneSearcher(Lucene.Net.Store.Directory luceneDir)
|
||||
public static LuceneSearcher GetLuceneSearcher(Directory luceneDir)
|
||||
{
|
||||
return new LuceneSearcher(luceneDir, new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_29));
|
||||
return new LuceneSearcher(luceneDir, new StandardAnalyzer(Version.LUCENE_29));
|
||||
}
|
||||
public static PDFIndexer GetPdfIndexer(Lucene.Net.Store.Directory luceneDir)
|
||||
|
||||
public static MultiIndexSearcher GetMultiSearcher(Directory pdfDir, Directory simpleDir, Directory conventionDir, Directory cwsDir)
|
||||
{
|
||||
var i = new PDFIndexer(luceneDir,
|
||||
new TestDataService(),
|
||||
new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_29),
|
||||
false);
|
||||
|
||||
i.IndexingError += IndexingError;
|
||||
|
||||
return i;
|
||||
}
|
||||
public static MultiIndexSearcher GetMultiSearcher(Lucene.Net.Store.Directory pdfDir, Lucene.Net.Store.Directory simpleDir, Lucene.Net.Store.Directory conventionDir, Lucene.Net.Store.Directory cwsDir)
|
||||
{
|
||||
var i = new MultiIndexSearcher(new[] { pdfDir, simpleDir, conventionDir, cwsDir }, new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_29));
|
||||
var i = new MultiIndexSearcher(new[] { pdfDir, simpleDir, conventionDir, cwsDir }, new StandardAnalyzer(Version.LUCENE_29));
|
||||
return i;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,116 +0,0 @@
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Xml.Linq;
|
||||
using Examine;
|
||||
using Lucene.Net.Search;
|
||||
using Lucene.Net.Store;
|
||||
using NUnit.Framework;
|
||||
using UmbracoExamine;
|
||||
using UmbracoExamine.PDF;
|
||||
|
||||
namespace Umbraco.Tests.UmbracoExamine
|
||||
{
|
||||
[TestFixture]
|
||||
public class PdfIndexerTests // itextsharp is not med trust safe so can't use hte base class: ExamineBaseTest<PdfIndexerTests>
|
||||
{
|
||||
|
||||
private readonly TestMediaService _mediaService = new TestMediaService();
|
||||
private static PDFIndexer _indexer;
|
||||
private static UmbracoExamineSearcher _searcher;
|
||||
private Lucene.Net.Store.Directory _luceneDir;
|
||||
|
||||
[SetUp]
|
||||
public void TestSetup()
|
||||
{
|
||||
UmbracoExamineSearcher.DisableInitializationCheck = true;
|
||||
BaseUmbracoIndexer.DisableInitializationCheck = true;
|
||||
//we'll copy over the pdf files first
|
||||
var svc = new TestDataService();
|
||||
var path = svc.MapPath("/App_Data/Converting_file_to_PDF.pdf");
|
||||
var f = new FileInfo(path);
|
||||
var dir = f.Directory;
|
||||
//ensure the folder is there
|
||||
System.IO.Directory.CreateDirectory(dir.FullName);
|
||||
var pdfs = new[] { TestFiles.Converting_file_to_PDF, TestFiles.PDFStandards, TestFiles.SurviorFlipCup, TestFiles.windows_vista };
|
||||
var names = new[] { "Converting_file_to_PDF.pdf", "PDFStandards.pdf", "SurviorFlipCup.pdf", "windows_vista.pdf" };
|
||||
for (int index = 0; index < pdfs.Length; index++)
|
||||
{
|
||||
var p = pdfs[index];
|
||||
using (var writer = File.Create(Path.Combine(dir.FullName, names[index])))
|
||||
{
|
||||
writer.Write(p, 0, p.Length);
|
||||
}
|
||||
}
|
||||
|
||||
_luceneDir = new RAMDirectory();
|
||||
_indexer = IndexInitializer.GetPdfIndexer(_luceneDir);
|
||||
_indexer.RebuildIndex();
|
||||
_searcher = IndexInitializer.GetUmbracoSearcher(_luceneDir);
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TestTearDown()
|
||||
{
|
||||
UmbracoExamineSearcher.DisableInitializationCheck = null;
|
||||
BaseUmbracoIndexer.DisableInitializationCheck = null;
|
||||
_luceneDir.Dispose();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PDFIndexer_Ensure_ParentID_Honored()
|
||||
{
|
||||
//change parent id to 1116
|
||||
var existingCriteria = ((IndexCriteria)_indexer.IndexerData);
|
||||
_indexer.IndexerData = new IndexCriteria(existingCriteria.StandardFields, existingCriteria.UserFields, existingCriteria.IncludeNodeTypes, existingCriteria.ExcludeNodeTypes,
|
||||
1116);
|
||||
|
||||
//get the 2112 pdf node: 2112
|
||||
var node = _mediaService.GetLatestMediaByXpath("//*[string-length(@id)>0 and number(@id)>0]")
|
||||
.Root
|
||||
.Elements()
|
||||
.Where(x => (int)x.Attribute("id") == 2112)
|
||||
.First();
|
||||
|
||||
//create a copy of 2112 undneath 1111 which is 'not indexable'
|
||||
var newpdf = XElement.Parse(node.ToString());
|
||||
newpdf.SetAttributeValue("id", "999999");
|
||||
newpdf.SetAttributeValue("path", "-1,1111,999999");
|
||||
newpdf.SetAttributeValue("parentID", "1111");
|
||||
|
||||
//now reindex
|
||||
_indexer.ReIndexNode(newpdf, IndexTypes.Media);
|
||||
|
||||
//make sure it doesn't exist
|
||||
|
||||
var results = _searcher.Search(_searcher.CreateSearchCriteria().Id(999999).Compile());
|
||||
Assert.AreEqual(0, results.Count());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PDFIndexer_Reindex()
|
||||
{
|
||||
|
||||
//search the pdf content to ensure it's there
|
||||
var contents = _searcher.Search(_searcher.CreateSearchCriteria().Id(1113).Compile()).Single()
|
||||
.Fields[PDFIndexer.TextContentFieldName];
|
||||
Assert.IsTrue(contents.Contains("Fonts are automatically embedded in Word 2008"));
|
||||
|
||||
contents = _searcher.Search(_searcher.CreateSearchCriteria().Id(1114).Compile()).Single()
|
||||
.Fields[PDFIndexer.TextContentFieldName];
|
||||
Assert.IsTrue(contents.Contains("Drink the beer and then flip the cup"));
|
||||
|
||||
//NOTE: This is one of those PDFs that cannot be read and not sure how to force it too.
|
||||
// Will leave this here as one day we might figure it out.
|
||||
//contents = _searcher.Search(_searcher.CreateSearchCriteria().Id(1115).Compile()).Single()
|
||||
// .Fields[PDFIndexer.TextContentFieldName];
|
||||
//Assert.IsTrue(contents.Contains("Activation associates the use of the software"));
|
||||
|
||||
contents = _searcher.Search(_searcher.CreateSearchCriteria().Id(1116).Compile()).Single()
|
||||
.Fields[PDFIndexer.TextContentFieldName];
|
||||
Assert.IsTrue(contents.Contains("This lack of standardization could be chaotic"));
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user