Updated configs to ensure that the correct (non-obsoleted) config section definition is used for Examine.

Updates Examine index configs to be simplified, don't need all of that config there!
Updates UmbracoExamine indexers to not initialize if the app/database is not ready.
Updates Examine event binders to not bind if the app/database is not ready.
Updates Examine events to use new 6.0+ events and removes binding entirely to the old api events (where we could)
This commit is contained in:
Shannon Deminick
2013-02-02 02:16:44 +06:00
parent e8d924cd2c
commit 6ee17dad03
7 changed files with 154 additions and 175 deletions

View File

@@ -8,36 +8,10 @@ More information and documentation can be found on CodePlex: http://umbracoexami
-->
<ExamineLuceneIndexSets>
<!-- The internal index set used by Umbraco back-office - DO NOT REMOVE -->
<IndexSet SetName="InternalIndexSet" IndexPath="~/App_Data/TEMP/ExamineIndexes/Internal/">
<IndexAttributeFields>
<add Name="id" />
<add Name="nodeName" />
<add Name="updateDate" />
<add Name="writerName" />
<add Name="path" />
<add Name="nodeTypeAlias" />
<add Name="parentID" />
</IndexAttributeFields>
<IndexUserFields />
<IncludeNodeTypes/>
<ExcludeNodeTypes />
</IndexSet>
<IndexSet SetName="InternalIndexSet" IndexPath="~/App_Data/TEMP/ExamineIndexes/Internal/" />
<!-- The internal index set used by Umbraco back-office for indexing members - DO NOT REMOVE -->
<IndexSet SetName="InternalMemberIndexSet" IndexPath="~/App_Data/TEMP/ExamineIndexes/InternalMember/">
<IndexAttributeFields>
<add Name="id" />
<add Name="nodeName"/>
<add Name="updateDate" />
<add Name="writerName" />
<add Name="loginName" />
<add Name="email" />
<add Name="nodeTypeAlias" />
</IndexAttributeFields>
<IndexUserFields/>
<IncludeNodeTypes/>
<ExcludeNodeTypes />
</IndexSet>
<IndexSet SetName="InternalMemberIndexSet" IndexPath="~/App_Data/TEMP/ExamineIndexes/InternalMember/" />
<!-- Default Indexset for external searches, this indexes all fields on all types of nodes-->
<IndexSet SetName="ExternalIndexSet" IndexPath="~/App_Data/TEMP/ExamineIndexes/External/" />

View File

@@ -6,37 +6,12 @@ Index/Search providers can be defined in the UmbracoSettings.config
More information and documentation can be found on CodePlex: http://umbracoexamine.codeplex.com
-->
<ExamineLuceneIndexSets>
<!-- The internal index set used by Umbraco back-office - DO NOT REMOVE -->
<IndexSet SetName="InternalIndexSet" IndexPath="~/App_Data/TEMP/ExamineIndexes/Internal/">
<IndexAttributeFields>
<add Name="id" />
<add Name="nodeName" />
<add Name="updateDate" />
<add Name="writerName" />
<add Name="path" />
<add Name="nodeTypeAlias" />
<add Name="parentID" />
</IndexAttributeFields>
<IndexUserFields />
<IncludeNodeTypes/>
<ExcludeNodeTypes />
</IndexSet>
<!-- The internal index set used by Umbraco back-office for indexing members - DO NOT REMOVE -->
<IndexSet SetName="InternalMemberIndexSet" IndexPath="~/App_Data/TEMP/ExamineIndexes/InternalMember/">
<IndexAttributeFields>
<add Name="id" />
<add Name="nodeName"/>
<add Name="updateDate" />
<add Name="writerName" />
<add Name="loginName" />
<add Name="email" />
<add Name="nodeTypeAlias" />
</IndexAttributeFields>
<IndexUserFields/>
<IncludeNodeTypes/>
<ExcludeNodeTypes />
</IndexSet>
<ExamineLuceneIndexSets>
<!-- The internal index set used by Umbraco back-office - DO NOT REMOVE -->
<IndexSet SetName="InternalIndexSet" IndexPath="~/App_Data/TEMP/ExamineIndexes/Internal/" />
<!-- The internal index set used by Umbraco back-office for indexing members - DO NOT REMOVE -->
<IndexSet SetName="InternalMemberIndexSet" IndexPath="~/App_Data/TEMP/ExamineIndexes/InternalMember/" />
</ExamineLuceneIndexSets>

View File

@@ -16,6 +16,12 @@
2012-11-08 SJ - Add Medium trust for everybody so we'll see any MedTrust related errors early on
-->
<configSections>
<section name="Examine" type="Examine.Config.ExamineSettings, Examine" xdt:Locator="Match(name)" xdt:Transform="SetAttributes(type)"/>
<section name="ExamineLuceneIndexSets" type="Examine.LuceneEngine.Config.IndexSets, Examine" xdt:Locator="Match(name)" xdt:Transform="SetAttributes(type)"/>
</configSections>
<appSettings>
<add key="umbracoDbDSN" xdt:Transform="Remove" xdt:Locator="Match(key)" />
</appSettings>

View File

@@ -8,12 +8,15 @@ using Examine.LuceneEngine;
using Lucene.Net.Documents;
using Umbraco.Core;
using Umbraco.Core.Logging;
using Umbraco.Core.Models;
using Umbraco.Core.Services;
using UmbracoExamine;
using umbraco;
using umbraco.BusinessLogic;
using umbraco.cms.businesslogic;
using umbraco.cms.businesslogic.member;
using umbraco.interfaces;
using Content = umbraco.cms.businesslogic.Content;
using Document = umbraco.cms.businesslogic.web.Document;
namespace Umbraco.Web.Search
@@ -42,6 +45,18 @@ namespace Umbraco.Web.Search
[SecuritySafeCritical]
public void OnApplicationStarted(UmbracoApplicationBase httpApplication, ApplicationContext applicationContext)
{
//do not initialize if the application is not configured
//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)
{
LogHelper.Info<ExamineEvents>("Not initializing Examine because the application and/or database is not configured");
return;
}
LogHelper.Info<ExamineEvents>("Initializing Examine and binding to business logic events");
var registeredProviders = ExamineManager.Instance.IndexProviderCollection
.OfType<BaseUmbracoIndexer>().Count(x => x.EnableDefaultEventHandler);
@@ -51,18 +66,17 @@ namespace Umbraco.Web.Search
if (registeredProviders == 0)
return;
global::umbraco.cms.businesslogic.media.Media.AfterSave += MediaAfterSave;
global::umbraco.cms.businesslogic.media.Media.AfterDelete += MediaAfterDelete;
CMSNode.AfterMove += MediaAfterMove;
MediaService.Saved += MediaServiceSaved;
MediaService.Deleted += MediaServiceDeleted;
MediaService.Moved += MediaServiceMoved;
ContentService.Saved += ContentServiceSaved;
ContentService.Deleted += ContentService_Deleted;
ContentService.Moved += ContentService_Moved;
//These should only fire for providers that DONT have SupportUnpublishedContent set to true
content.AfterUpdateDocumentCache += ContentAfterUpdateDocumentCache;
content.AfterClearDocumentCache += ContentAfterClearDocumentCache;
//These should only fire for providers that have SupportUnpublishedContent set to true
Document.AfterSave += DocumentAfterSave;
Document.AfterDelete += DocumentAfterDelete;
Member.AfterSave += MemberAfterSave;
Member.AfterDelete += MemberAfterDelete;
@@ -78,6 +92,50 @@ namespace Umbraco.Web.Search
}
}
[SecuritySafeCritical]
void ContentService_Moved(IContentService sender, Umbraco.Core.Events.MoveEventArgs<IContent> e)
{
IndexConent(e.Entity);
}
[SecuritySafeCritical]
void ContentService_Deleted(IContentService sender, Umbraco.Core.Events.DeleteEventArgs<IContent> e)
{
e.DeletedEntities.ForEach(
content =>
ExamineManager.Instance.DeleteFromIndex(
content.Id.ToString(),
ExamineManager.Instance.IndexProviderCollection.OfType<BaseUmbracoIndexer>().Where(x => x.EnableDefaultEventHandler)));
}
[SecuritySafeCritical]
void ContentServiceSaved(IContentService sender, Umbraco.Core.Events.SaveEventArgs<IContent> e)
{
e.SavedEntities.ForEach(IndexConent);
}
[SecuritySafeCritical]
void MediaServiceMoved(IMediaService sender, Umbraco.Core.Events.MoveEventArgs<IMedia> e)
{
IndexMedia(e.Entity);
}
[SecuritySafeCritical]
void MediaServiceDeleted(IMediaService sender, Umbraco.Core.Events.DeleteEventArgs<IMedia> e)
{
e.DeletedEntities.ForEach(
media =>
ExamineManager.Instance.DeleteFromIndex(
media.Id.ToString(),
ExamineManager.Instance.IndexProviderCollection.OfType<BaseUmbracoIndexer>().Where(x => x.EnableDefaultEventHandler)));
}
[SecuritySafeCritical]
void MediaServiceSaved(IMediaService sender, Umbraco.Core.Events.SaveEventArgs<IMedia> e)
{
e.SavedEntities.ForEach(IndexMedia);
}
[SecuritySafeCritical]
private static void MemberAfterSave(Member sender, SaveEventArgs e)
{
@@ -99,113 +157,6 @@ namespace Umbraco.Web.Search
.Where(x => x.EnableDefaultEventHandler));
}
/// <summary>
/// Only index using providers that SupportUnpublishedContent
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
[SecuritySafeCritical]
private static void DocumentAfterSave(Document sender, SaveEventArgs e)
{
//ensure that only the providers that have unpublishing support enabled
//that are also flagged to listen
//there's a bug in 4.0.x that fires the Document saving event handler for media when media is moved,
//therefore, we need to try to figure out if this is media or content. Currently one way to do this
//is by checking the creator ID property as it will be null if it is media. We then need to try to
//create the media object, see if it exists, and pass it to the media save event handler... yeah i know,
//pretty horrible but has to be done.
try
{
var creator = sender.Creator;
if (creator != null)
{
//it's def a Document
ExamineManager.Instance.ReIndexNode(ToXDocument(sender, false).Root, IndexTypes.Content,
ExamineManager.Instance.IndexProviderCollection.OfType<BaseUmbracoIndexer>()
.Where(x => x.SupportUnpublishedContent
&& x.EnableDefaultEventHandler));
return; //exit, we've indexed the content
}
}
catch (Exception)
{
//if we get this exception, it means it's most likely media, so well do our check next.
//TODO: Update this logic for 6.0 as we're not dealing with 4.0x
//this is most likely media, not sure what kind of exception might get thrown in 4.0.x or 4.1 if accessing a null
//creator, so we catch everything.
}
var m = new global::umbraco.cms.businesslogic.media.Media(sender.Id);
if (string.IsNullOrEmpty(m.Path)) return;
//this is a media item, no exception occurred on access to path and it's not empty which means it was found
MediaAfterSave(m, e);
}
/// <summary>
/// Only remove indexes using providers that SupportUnpublishedContent
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
[SecuritySafeCritical]
private static void DocumentAfterDelete(Document sender, DeleteEventArgs e)
{
var nodeId = sender.Id.ToString();
//ensure that only the providers that have unpublishing support enabled
//that are also flagged to listen
ExamineManager.Instance.DeleteFromIndex(nodeId,
ExamineManager.Instance.IndexProviderCollection.OfType<BaseUmbracoIndexer>()
.Where(x => x.SupportUnpublishedContent
&& x.EnableDefaultEventHandler));
}
[SecuritySafeCritical]
private static void MediaAfterDelete(global::umbraco.cms.businesslogic.media.Media sender, DeleteEventArgs e)
{
var nodeId = sender.Id.ToString();
//ensure that only the providers are flagged to listen execute
ExamineManager.Instance.DeleteFromIndex(nodeId,
ExamineManager.Instance.IndexProviderCollection.OfType<BaseUmbracoIndexer>()
.Where(x => x.EnableDefaultEventHandler));
}
[SecuritySafeCritical]
private static void MediaAfterSave(global::umbraco.cms.businesslogic.media.Media sender, SaveEventArgs e)
{
//ensure that only the providers are flagged to listen execute
IndexMedia(sender);
}
[SecuritySafeCritical]
private static void IndexMedia(global::umbraco.cms.businesslogic.media.Media sender)
{
ExamineManager.Instance.ReIndexNode(ToXDocument(sender, true).Root, IndexTypes.Media,
ExamineManager.Instance.IndexProviderCollection.OfType<BaseUmbracoIndexer>()
.Where(x => x.EnableDefaultEventHandler));
}
/// <summary>
/// When media is moved, re-index
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
[SecuritySafeCritical]
private static void MediaAfterMove(object sender, MoveEventArgs e)
{
var media = sender as global::umbraco.cms.businesslogic.media.Media;
if (media == null) return;
global::umbraco.cms.businesslogic.media.Media m = media;
IndexMedia(m);
}
/// <summary>
/// Only Update indexes for providers that dont SupportUnpublishedContent
/// </summary>
@@ -261,6 +212,20 @@ namespace Umbraco.Web.Search
}
private void IndexMedia(IMedia sender)
{
ExamineManager.Instance.ReIndexNode(
sender.ToXml(), "media",
ExamineManager.Instance.IndexProviderCollection.OfType<BaseUmbracoIndexer>().Where(x => x.EnableDefaultEventHandler));
}
private void IndexConent(IContent sender)
{
ExamineManager.Instance.ReIndexNode(
sender.ToXml(), "content",
ExamineManager.Instance.IndexProviderCollection.OfType<BaseUmbracoIndexer>().Where(x => x.EnableDefaultEventHandler));
}
/// <summary>
/// Converts a content node to XDocument
/// </summary>

View File

@@ -8,6 +8,7 @@ using System.Threading;
using System.Web;
using Examine.LuceneEngine.Providers;
using Lucene.Net.Analysis;
using Umbraco.Core;
using umbraco.BasePages;
using umbraco.BusinessLogic;
using UmbracoExamine.DataServices;
@@ -92,6 +93,14 @@ namespace UmbracoExamine
/// <param name="config"></param>
public override void Initialize(string name, System.Collections.Specialized.NameValueCollection config)
{
//We need to check if we actually can initialize, if not then don't continue
if (!CanInitialized())
{
return;
}
if (config["dataService"] != null && !string.IsNullOrEmpty(config["dataService"]))
{
//this should be a fully qualified type
@@ -160,6 +169,22 @@ namespace UmbracoExamine
#region Protected
/// <summary>
/// Returns true if the Umbraco application is in a state that we can initialize the examine indexes
/// </summary>
/// <returns></returns>
protected bool CanInitialized()
{
//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)
{
return false;
}
return true;
}
/////<summary>
///// Calls a web request in a worker thread to rebuild the indexes
/////</summary>

View File

@@ -120,6 +120,12 @@ namespace UmbracoExamine
public override void Initialize(string name, System.Collections.Specialized.NameValueCollection config)
{
//We need to check if we actually can initialize, if not then don't continue
if (!CanInitialized())
{
return;
}
//check if there's a flag specifying to support unpublished content,
//if not, set to false;
bool supportUnpublished;

View File

@@ -5,6 +5,7 @@ using System.Security;
using Examine;
using Examine.Providers;
using Examine.SearchCriteria;
using Umbraco.Core;
using UmbracoExamine.Config;
using Examine.LuceneEngine;
using Examine.LuceneEngine.Providers;
@@ -30,6 +31,17 @@ namespace UmbracoExamine
{
}
public override void Initialize(string name, System.Collections.Specialized.NameValueCollection config)
{
//We need to check if we actually can initialize, if not then don't continue
if (!CanInitialized())
{
return;
}
base.Initialize(name, config);
}
/// <summary>
/// Constructor to allow for creating an indexer at runtime
/// </summary>
@@ -54,6 +66,22 @@ namespace UmbracoExamine
#endregion
/// <summary>
/// Returns true if the Umbraco application is in a state that we can initialize the examine indexes
/// </summary>
/// <returns></returns>
protected bool CanInitialized()
{
//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)
{
return false;
}
return true;
}
/// <summary>
/// Override in order to set the nodeTypeAlias field name of the underlying SearchCriteria to __NodeTypeAlias
/// </summary>