cleans up the UmbracoExamineSearcher class
makes sure the temp storage stuff works - but this will be only configuration based searchers (legacy)
This commit is contained in:
@@ -298,17 +298,14 @@ namespace UmbracoExamine
|
||||
/// </remarks>
|
||||
protected bool CanInitialize()
|
||||
{
|
||||
if (_configBased)
|
||||
//We need to check if we actually can initialize, if not then don't continue
|
||||
if (_configBased
|
||||
&& (ApplicationContext.Current == null
|
||||
|| ApplicationContext.Current.IsConfigured == false
|
||||
|| ApplicationContext.Current.DatabaseContext.IsDatabaseConfigured == false))
|
||||
{
|
||||
//We need to check if we actually can initialize, if not then don't continue
|
||||
if (ApplicationContext.Current == null
|
||||
|| ApplicationContext.Current.IsConfigured == false
|
||||
|| ApplicationContext.Current.DatabaseContext.IsDatabaseConfigured == false)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ namespace UmbracoExamine.LocalStorage
|
||||
{
|
||||
internal class LocalTempStorageDirectoryTracker
|
||||
{
|
||||
private readonly static LocalTempStorageDirectoryTracker Instance = new LocalTempStorageDirectoryTracker();
|
||||
private static readonly LocalTempStorageDirectoryTracker Instance = new LocalTempStorageDirectoryTracker();
|
||||
private readonly ConcurrentDictionary<string, LocalTempStorageDirectory> _directories = new ConcurrentDictionary<string, LocalTempStorageDirectory>();
|
||||
|
||||
public static LocalTempStorageDirectoryTracker Current
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Security;
|
||||
@@ -17,6 +18,7 @@ using Examine.LuceneEngine.SearchCriteria;
|
||||
using Lucene.Net.Analysis;
|
||||
using Umbraco.Core.Logging;
|
||||
using UmbracoExamine.LocalStorage;
|
||||
using Directory = Lucene.Net.Store.Directory;
|
||||
|
||||
|
||||
namespace UmbracoExamine
|
||||
@@ -27,22 +29,42 @@ namespace UmbracoExamine
|
||||
public class UmbracoExamineSearcher : LuceneSearcher
|
||||
{
|
||||
|
||||
private volatile Lucene.Net.Store.Directory _localTempDirectory;
|
||||
private static readonly object Locker = new object();
|
||||
private string _localTempPath = null;
|
||||
private Lazy<Directory> _localTempDirectory;
|
||||
private LocalStorageType _localStorageType = LocalStorageType.Sync;
|
||||
|
||||
#region Constructors
|
||||
private string _name;
|
||||
private readonly bool _configBased = false;
|
||||
|
||||
/// <summary>
|
||||
/// Default constructor
|
||||
/// Default constructor for config based construction
|
||||
/// </summary>
|
||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||
public UmbracoExamineSearcher()
|
||||
: base()
|
||||
{
|
||||
_configBased = true;
|
||||
}
|
||||
|
||||
private string _name;
|
||||
/// <summary>
|
||||
/// Constructor to allow for creating an indexer at runtime
|
||||
/// </summary>
|
||||
/// <param name="indexPath"></param>
|
||||
/// <param name="analyzer"></param>
|
||||
public UmbracoExamineSearcher(DirectoryInfo indexPath, Analyzer analyzer)
|
||||
: base(indexPath, analyzer)
|
||||
{
|
||||
_configBased = false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructor to allow for creating an indexer at runtime
|
||||
/// </summary>
|
||||
/// <param name="luceneDirectory"></param>
|
||||
/// <param name="analyzer"></param>
|
||||
public UmbracoExamineSearcher(Directory luceneDirectory, Analyzer analyzer)
|
||||
: base(luceneDirectory, analyzer)
|
||||
{
|
||||
_configBased = false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// we override name because we need to manually set it if !CanInitialize()
|
||||
@@ -50,13 +72,14 @@ namespace UmbracoExamine
|
||||
/// </summary>
|
||||
public override string Name
|
||||
{
|
||||
get
|
||||
{
|
||||
return _name;
|
||||
}
|
||||
get { return _name; }
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Method used for initializing based on a configuration based searcher
|
||||
/// </summary>
|
||||
/// <param name="name"></param>
|
||||
/// <param name="config"></param>
|
||||
public override void Initialize(string name, System.Collections.Specialized.NameValueCollection config)
|
||||
{
|
||||
if (name == null) throw new ArgumentNullException("name");
|
||||
@@ -103,36 +126,33 @@ namespace UmbracoExamine
|
||||
var configuredPath = indexSet.IndexPath;
|
||||
var tempPath = localStorageDir.GetLocalStorageDirectory(config, configuredPath);
|
||||
if (tempPath == null) throw new InvalidOperationException("Could not resolve a temp location from the " + localStorageDir.GetType() + " specified");
|
||||
_localTempPath = tempPath.FullName;
|
||||
var localTempPath = tempPath.FullName;
|
||||
_localStorageType = attemptUseTempStorage.Result;
|
||||
|
||||
//initialize the lazy callback
|
||||
_localTempDirectory = new Lazy<Directory>(() =>
|
||||
{
|
||||
switch (_localStorageType)
|
||||
{
|
||||
case LocalStorageType.Sync:
|
||||
var fsDir = base.GetLuceneDirectory() as FSDirectory;
|
||||
if (fsDir != null)
|
||||
{
|
||||
return LocalTempStorageDirectoryTracker.Current.GetDirectory(
|
||||
new DirectoryInfo(localTempPath),
|
||||
fsDir);
|
||||
}
|
||||
return base.GetLuceneDirectory();
|
||||
case LocalStorageType.LocalOnly:
|
||||
return new SimpleFSDirectory(new DirectoryInfo(localTempPath));
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructor to allow for creating an indexer at runtime
|
||||
/// </summary>
|
||||
/// <param name="indexPath"></param>
|
||||
/// <param name="analyzer"></param>
|
||||
|
||||
public UmbracoExamineSearcher(DirectoryInfo indexPath, Analyzer analyzer)
|
||||
: base(indexPath, analyzer)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructor to allow for creating an indexer at runtime
|
||||
/// </summary>
|
||||
/// <param name="luceneDirectory"></param>
|
||||
/// <param name="analyzer"></param>
|
||||
|
||||
public UmbracoExamineSearcher(Lucene.Net.Store.Directory luceneDirectory, Analyzer analyzer)
|
||||
: base(luceneDirectory, analyzer)
|
||||
{
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Returns true if the Umbraco application is in a state that we can initialize the examine indexes
|
||||
/// </summary>
|
||||
@@ -141,29 +161,15 @@ namespace UmbracoExamine
|
||||
protected bool CanInitialize()
|
||||
{
|
||||
//We need to check if we actually can initialize, if not then don't continue
|
||||
if (ApplicationContext.Current == null
|
||||
|| !ApplicationContext.Current.IsConfigured
|
||||
|| !ApplicationContext.Current.DatabaseContext.IsDatabaseConfigured)
|
||||
if (_configBased
|
||||
&& (ApplicationContext.Current == null
|
||||
|| ApplicationContext.Current.IsConfigured == false
|
||||
|| ApplicationContext.Current.DatabaseContext.IsDatabaseConfigured == false))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Override in order to set the nodeTypeAlias field name of the underlying SearchCriteria to __NodeTypeAlias
|
||||
/// </summary>
|
||||
/// <param name="type"></param>
|
||||
/// <param name="defaultOperation"></param>
|
||||
/// <returns></returns>
|
||||
public override ISearchCriteria CreateSearchCriteria(string type, BooleanOperation defaultOperation)
|
||||
{
|
||||
throw new NotImplementedException("Fix strongly typed CreateSearchCriteria");
|
||||
|
||||
var criteria = base.CreateSearchCriteria(type, defaultOperation) as LuceneSearchCriteria;
|
||||
//criteria.NodeTypeAliasField = UmbracoContentIndexer.NodeTypeAliasFieldName;
|
||||
return criteria;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a list of fields to search on, this will also exclude the IndexPathFieldName and node type alias
|
||||
@@ -173,53 +179,17 @@ namespace UmbracoExamine
|
||||
{
|
||||
var fields = base.GetSearchFields();
|
||||
return fields
|
||||
.Where(x => x != UmbracoContentIndexer.IndexPathFieldName)
|
||||
.Where(x => x != UmbracoContentIndexer.NodeTypeAliasFieldName)
|
||||
.Where(x => x != BaseUmbracoIndexer.IndexPathFieldName)
|
||||
.Where(x => x != LuceneIndexer.NodeTypeAliasFieldName)
|
||||
.ToArray();
|
||||
}
|
||||
|
||||
protected override Lucene.Net.Store.Directory GetLuceneDirectory()
|
||||
protected override Directory GetLuceneDirectory()
|
||||
{
|
||||
throw new NotImplementedException("Fix local storage stuff");
|
||||
|
||||
////local temp storage is not enabled, just return the default
|
||||
//if (_localTempPath == null) return base.GetLuceneDirectory();
|
||||
|
||||
////local temp storage is enabled, configure the local directory instance
|
||||
//if (_localTempDirectory == null)
|
||||
//{
|
||||
// lock (Locker)
|
||||
// {
|
||||
// if (_localTempDirectory == null)
|
||||
// {
|
||||
// switch (_localStorageType)
|
||||
// {
|
||||
// case LocalStorageType.Sync:
|
||||
// var fsDir = base.GetLuceneDirectory() as FSDirectory;
|
||||
// if (fsDir != null)
|
||||
// {
|
||||
// _localTempDirectory = LocalTempStorageDirectoryTracker.Current.GetDirectory(
|
||||
// new DirectoryInfo(_localTempPath),
|
||||
// fsDir);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// return base.GetLuceneDirectory();
|
||||
// }
|
||||
// break;
|
||||
// case LocalStorageType.LocalOnly:
|
||||
// _localTempDirectory = DirectoryTracker.Current.GetDirectory(new DirectoryInfo(_localTempPath));
|
||||
// break;
|
||||
// default:
|
||||
// throw new ArgumentOutOfRangeException();
|
||||
// }
|
||||
|
||||
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
|
||||
//return _localTempDirectory;
|
||||
//local temp storage is not enabled, just return the default
|
||||
return _localTempDirectory.IsValueCreated == false
|
||||
? base.GetLuceneDirectory()
|
||||
: _localTempDirectory.Value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user