moves the local storage logic to the BaseUmbracoIndexer

This commit is contained in:
Shannon
2014-12-09 19:15:47 +11:00
parent 78bee017ca
commit d857743bf3
2 changed files with 47 additions and 41 deletions

View File

@@ -10,6 +10,7 @@ using Examine.LuceneEngine.Config;
using Examine.LuceneEngine.Providers;
using Lucene.Net.Analysis;
using Lucene.Net.Documents;
using Lucene.Net.Index;
using Umbraco.Core;
using umbraco.BasePages;
using umbraco.BusinessLogic;
@@ -17,6 +18,7 @@ using UmbracoExamine.DataServices;
using Examine;
using System.IO;
using System.Xml.Linq;
using UmbracoExamine.LocalStorage;
namespace UmbracoExamine
{
@@ -62,6 +64,7 @@ namespace UmbracoExamine
/// Used for unit tests
/// </summary>
internal static bool? DisableInitializationCheck = null;
private readonly LocalTempStorageIndexer _localTempStorageHelper = new LocalTempStorageIndexer();
#region Properties
@@ -97,7 +100,21 @@ namespace UmbracoExamine
/// <param name="name"></param>
/// <param name="config"></param>
public override void Initialize(string name, System.Collections.Specialized.NameValueCollection config)
{
{
if (config != null && config["useTempStorage"] != null)
{
//Use the temp storage directory which will store the index in the local/codegen folder, this is useful
// for websites that are running from a remove file server and file IO latency becomes an issue
var attemptUseTempStorage = config["useTempStorage"].TryConvertTo<bool>();
if (attemptUseTempStorage)
{
var indexSet = IndexSets.Instance.Sets[IndexSetName];
var configuredPath = indexSet.IndexPath;
_localTempStorageHelper.Initialize(config, configuredPath, base.GetLuceneDirectory(), IndexingAnalyzer);
}
}
if (config["dataService"] != null && !string.IsNullOrEmpty(config["dataService"]))
{
//this should be a fully qualified type
@@ -148,6 +165,32 @@ namespace UmbracoExamine
#endregion
public override Lucene.Net.Store.Directory GetLuceneDirectory()
{
//if temp local storage is configured use that, otherwise return the default
if (_localTempStorageHelper.LuceneDirectory != null)
{
return _localTempStorageHelper.LuceneDirectory;
}
return base.GetLuceneDirectory();
}
public override IndexWriter GetIndexWriter()
{
//if temp local storage is configured use that, otherwise return the default
if (_localTempStorageHelper.LuceneDirectory != null)
{
return new IndexWriter(GetLuceneDirectory(), IndexingAnalyzer,
//create the writer with the snapshotter, though that won't make too much a difference because we are not keeping the writer open unless using nrt
// which we are not currently.
_localTempStorageHelper.Snapshotter,
IndexWriter.MaxFieldLength.UNLIMITED);
}
return base.GetIndexWriter();
}
///// <summary>
///// Override to check if we can actually initialize.

View File

@@ -122,7 +122,7 @@ namespace UmbracoExamine
#region Constants & Fields
private readonly LocalTempStorageIndexer _localTempStorageHelper = new LocalTempStorageIndexer();
/// <summary>
/// Used to store the path of a content object
@@ -208,19 +208,7 @@ namespace UmbracoExamine
base.Initialize(name, config);
if (config != null && config["useTempStorage"] != null)
{
//Use the temp storage directory which will store the index in the local/codegen folder, this is useful
// for websites that are running from a remove file server and file IO latency becomes an issue
var attemptUseTempStorage = config["useTempStorage"].TryConvertTo<bool>();
if (attemptUseTempStorage)
{
var indexSet = IndexSets.Instance.Sets[IndexSetName];
var configuredPath = indexSet.IndexPath;
_localTempStorageHelper.Initialize(config, configuredPath, base.GetLuceneDirectory(), IndexingAnalyzer);
}
}
}
@@ -296,32 +284,7 @@ namespace UmbracoExamine
#region Public methods
public override Lucene.Net.Store.Directory GetLuceneDirectory()
{
//if temp local storage is configured use that, otherwise return the default
if (_localTempStorageHelper.LuceneDirectory != null)
{
return _localTempStorageHelper.LuceneDirectory;
}
return base.GetLuceneDirectory();
}
public override IndexWriter GetIndexWriter()
{
//if temp local storage is configured use that, otherwise return the default
if (_localTempStorageHelper.LuceneDirectory != null)
{
return new IndexWriter(GetLuceneDirectory(), IndexingAnalyzer,
//create the writer with the snapshotter, though that won't make too much a difference because we are not keeping the writer open unless using nrt
// which we are not currently.
_localTempStorageHelper.Snapshotter,
IndexWriter.MaxFieldLength.UNLIMITED);
}
return base.GetIndexWriter();
}
/// <summary>