2013-01-05 03:28:47 +03:00
|
|
|
|
using System;
|
2013-01-05 23:36:38 +03:00
|
|
|
|
using System.Linq;
|
2014-09-30 15:13:10 +10:00
|
|
|
|
using System.Net.Mime;
|
2014-09-30 18:46:02 +10:00
|
|
|
|
using System.Xml.XPath;
|
2013-01-05 03:28:47 +03:00
|
|
|
|
using Examine;
|
2013-02-20 02:50:08 +06:00
|
|
|
|
using Examine.LuceneEngine.Config;
|
2013-01-05 03:28:47 +03:00
|
|
|
|
using Examine.LuceneEngine.Providers;
|
2013-02-14 06:33:48 +06:00
|
|
|
|
using Lucene.Net.Analysis;
|
2013-01-05 03:28:47 +03:00
|
|
|
|
using Lucene.Net.Analysis.Standard;
|
2014-09-30 15:13:10 +10:00
|
|
|
|
using Moq;
|
2014-09-30 18:46:02 +10:00
|
|
|
|
using Umbraco.Core.Models;
|
|
|
|
|
|
using Umbraco.Core.Models.Membership;
|
|
|
|
|
|
using Umbraco.Core.Persistence.DatabaseModelDefinitions;
|
2014-09-30 15:13:10 +10:00
|
|
|
|
using Umbraco.Core.Services;
|
2013-01-05 03:28:47 +03:00
|
|
|
|
using UmbracoExamine;
|
2013-02-20 02:50:08 +06:00
|
|
|
|
using UmbracoExamine.Config;
|
2013-02-14 23:06:28 +06:00
|
|
|
|
using UmbracoExamine.DataServices;
|
2013-01-05 04:43:15 +03:00
|
|
|
|
using UmbracoExamine.PDF;
|
2014-09-30 15:13:10 +10:00
|
|
|
|
using IContentService = UmbracoExamine.DataServices.IContentService;
|
|
|
|
|
|
using IMediaService = UmbracoExamine.DataServices.IMediaService;
|
2013-01-05 03:28:47 +03:00
|
|
|
|
|
|
|
|
|
|
namespace Umbraco.Tests.UmbracoExamine
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Used internally by test classes to initialize a new index from the template
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
internal static class IndexInitializer
|
|
|
|
|
|
{
|
2013-02-14 06:33:48 +06:00
|
|
|
|
public static UmbracoContentIndexer GetUmbracoIndexer(
|
|
|
|
|
|
Lucene.Net.Store.Directory luceneDir,
|
2013-02-14 23:06:28 +06:00
|
|
|
|
Analyzer analyzer = null,
|
2014-09-30 15:13:10 +10:00
|
|
|
|
IDataService dataService = null,
|
|
|
|
|
|
Umbraco.Core.Services.IContentService contentService = null,
|
|
|
|
|
|
Umbraco.Core.Services.IMediaService mediaService = null,
|
|
|
|
|
|
IDataTypeService dataTypeService = null,
|
2014-09-30 18:46:02 +10:00
|
|
|
|
IMemberService memberService = null,
|
|
|
|
|
|
IUserService userService = null)
|
2013-01-05 03:28:47 +03:00
|
|
|
|
{
|
2013-02-14 23:06:28 +06:00
|
|
|
|
if (dataService == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
dataService = new TestDataService();
|
|
|
|
|
|
}
|
2014-09-30 15:13:10 +10:00
|
|
|
|
if (contentService == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
contentService = Mock.Of<Umbraco.Core.Services.IContentService>();
|
|
|
|
|
|
}
|
2014-09-30 18:46:02 +10:00
|
|
|
|
if (userService == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
userService = Mock.Of<IUserService>(x => x.GetProfileById(It.IsAny<int>()) == Mock.Of<IProfile>(p => p.Id == (object)0 && p.Name == "admin"));
|
|
|
|
|
|
}
|
2014-09-30 15:13:10 +10:00
|
|
|
|
if (mediaService == null)
|
|
|
|
|
|
{
|
2014-09-30 18:46:02 +10:00
|
|
|
|
int totalRecs;
|
|
|
|
|
|
|
|
|
|
|
|
var allRecs = dataService.MediaService.GetLatestMediaByXpath("//node")
|
|
|
|
|
|
.Root
|
|
|
|
|
|
.Elements()
|
|
|
|
|
|
.Select(x => Mock.Of<IMedia>(
|
|
|
|
|
|
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<IMediaType>(mt =>
|
|
|
|
|
|
mt.Alias == (string) x.Attribute("nodeTypeAlias") &&
|
|
|
|
|
|
mt.Id == (int) x.Attribute("nodeType"))))
|
|
|
|
|
|
.ToArray();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mediaService = Mock.Of<Umbraco.Core.Services.IMediaService>(
|
|
|
|
|
|
x => x.GetPagedDescendants(
|
|
|
|
|
|
It.IsAny<int>(), It.IsAny<int>(), It.IsAny<int>(), out totalRecs, It.IsAny<string>(), It.IsAny<Direction>(), It.IsAny<string>())
|
|
|
|
|
|
==
|
|
|
|
|
|
allRecs);
|
2014-09-30 15:13:10 +10:00
|
|
|
|
}
|
|
|
|
|
|
if (dataTypeService == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
dataTypeService = Mock.Of<IDataTypeService>();
|
|
|
|
|
|
}
|
2014-09-30 18:46:02 +10:00
|
|
|
|
|
2014-09-30 15:13:10 +10:00
|
|
|
|
if (memberService == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
memberService = Mock.Of<IMemberService>();
|
|
|
|
|
|
}
|
2013-01-05 03:28:47 +03:00
|
|
|
|
|
2013-02-14 06:33:48 +06:00
|
|
|
|
if (analyzer == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
analyzer = new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_29);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2013-02-20 02:50:08 +06:00
|
|
|
|
var indexSet = new IndexSet();
|
2013-02-20 05:01:40 +06:00
|
|
|
|
var indexCriteria = indexSet.ToIndexCriteria(dataService, UmbracoContentIndexer.IndexFieldPolicies);
|
2013-02-20 02:50:08 +06:00
|
|
|
|
|
|
|
|
|
|
var i = new UmbracoContentIndexer(indexCriteria,
|
2013-02-14 23:06:28 +06:00
|
|
|
|
luceneDir, //custom lucene directory
|
|
|
|
|
|
dataService,
|
2014-09-30 15:13:10 +10:00
|
|
|
|
contentService,
|
|
|
|
|
|
mediaService,
|
|
|
|
|
|
dataTypeService,
|
2014-09-30 18:46:02 +10:00
|
|
|
|
userService,
|
2013-02-14 23:06:28 +06:00
|
|
|
|
analyzer,
|
|
|
|
|
|
false);
|
2013-01-05 03:28:47 +03:00
|
|
|
|
|
|
|
|
|
|
//i.IndexSecondsInterval = 1;
|
|
|
|
|
|
|
|
|
|
|
|
i.IndexingError += IndexingError;
|
|
|
|
|
|
|
|
|
|
|
|
return i;
|
|
|
|
|
|
}
|
2013-02-14 06:33:48 +06:00
|
|
|
|
public static UmbracoExamineSearcher GetUmbracoSearcher(Lucene.Net.Store.Directory luceneDir, Analyzer analyzer = null)
|
2013-01-05 03:28:47 +03:00
|
|
|
|
{
|
2013-02-14 06:33:48 +06:00
|
|
|
|
if (analyzer == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
analyzer = new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_29);
|
|
|
|
|
|
}
|
|
|
|
|
|
return new UmbracoExamineSearcher(luceneDir, analyzer);
|
2013-01-05 03:28:47 +03:00
|
|
|
|
}
|
2013-02-20 05:01:40 +06:00
|
|
|
|
|
2013-01-05 03:28:47 +03:00
|
|
|
|
public static LuceneSearcher GetLuceneSearcher(Lucene.Net.Store.Directory luceneDir)
|
|
|
|
|
|
{
|
|
|
|
|
|
return new LuceneSearcher(luceneDir, new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_29));
|
|
|
|
|
|
}
|
2013-01-05 04:43:15 +03:00
|
|
|
|
public static PDFIndexer GetPdfIndexer(Lucene.Net.Store.Directory luceneDir)
|
|
|
|
|
|
{
|
|
|
|
|
|
var i = new PDFIndexer(luceneDir,
|
|
|
|
|
|
new TestDataService(),
|
|
|
|
|
|
new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_29),
|
|
|
|
|
|
false);
|
2013-01-05 03:28:47 +03:00
|
|
|
|
|
2013-01-05 04:43:15 +03:00
|
|
|
|
i.IndexingError += IndexingError;
|
2013-01-05 03:28:47 +03:00
|
|
|
|
|
2013-01-05 04:43:15 +03:00
|
|
|
|
return i;
|
|
|
|
|
|
}
|
2013-01-05 03:28:47 +03:00
|
|
|
|
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));
|
|
|
|
|
|
return i;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
internal static void IndexingError(object sender, IndexingErrorEventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
throw new ApplicationException(e.Message, e.InnerException);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|