mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
Handle indexing settings modifications to refresh the index
--HG-- branch : dev
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using Orchard.Environment;
|
||||
using Orchard.Tasks.Indexing;
|
||||
using Orchard.ContentManagement;
|
||||
|
||||
namespace Orchard.Indexing {
|
||||
public class DefaultIndexingUpdater : IFeatureEventHandler {
|
||||
|
||||
private readonly IIndexingTaskManager _indexingTaskManager;
|
||||
private readonly IContentManager _contentManager;
|
||||
|
||||
public DefaultIndexingUpdater (IIndexingTaskManager indexingTaskManager, IContentManager contentManager){
|
||||
_indexingTaskManager = indexingTaskManager;
|
||||
_contentManager = contentManager;
|
||||
}
|
||||
|
||||
public void Install(Environment.Extensions.Models.Feature feature) {
|
||||
}
|
||||
|
||||
public void Enable(Environment.Extensions.Models.Feature feature) {
|
||||
// create indexing tasks for all currently existing content, even when the module is enabled again
|
||||
// as some content might have been created while this module was not active, and indexing tasks
|
||||
// would not exist for them, resulting in an uncomplete index.
|
||||
|
||||
foreach (var contentItem in _contentManager.Query(VersionOptions.Published).List()) {
|
||||
_indexingTaskManager.CreateUpdateIndexTask(contentItem);
|
||||
}
|
||||
}
|
||||
|
||||
public void Disable(Environment.Extensions.Models.Feature feature) {
|
||||
}
|
||||
|
||||
public void Uninstall(Environment.Extensions.Models.Feature feature) {
|
||||
}
|
||||
}
|
||||
}
|
@@ -62,6 +62,7 @@
|
||||
<Compile Include="Commands\IndexingCommands.cs" />
|
||||
<Compile Include="Controllers\AdminController.cs" />
|
||||
<Compile Include="DataMigrations\IndexingDataMigration.cs" />
|
||||
<Compile Include="DefaultIndexingUpdater.cs" />
|
||||
<Compile Include="Handlers\CreateIndexingTaskHandler.cs" />
|
||||
<Compile Include="Handlers\InfosetFieldIndexingHandler.cs" />
|
||||
<Compile Include="Models\IndexingTask.cs" />
|
||||
|
@@ -4,11 +4,24 @@ using Orchard.ContentManagement.MetaData;
|
||||
using Orchard.ContentManagement.MetaData.Builders;
|
||||
using Orchard.ContentManagement.MetaData.Models;
|
||||
using Orchard.ContentManagement.ViewModels;
|
||||
using Orchard.Tasks.Indexing;
|
||||
|
||||
namespace Orchard.Indexing.Settings {
|
||||
public class EditorEvents : ContentDefinitionEditorEventsBase {
|
||||
private readonly IIndexingTaskManager _indexingTaskManager;
|
||||
private readonly IContentManager _contentManager;
|
||||
|
||||
public EditorEvents(IIndexingTaskManager indexingTaskManager, IContentManager contentManager){
|
||||
_indexingTaskManager = indexingTaskManager;
|
||||
_contentManager = contentManager;
|
||||
}
|
||||
|
||||
private string _contentTypeName;
|
||||
private bool _tasksCreated = false;
|
||||
|
||||
public override IEnumerable<TemplateViewModel> TypeEditor(ContentTypeDefinition definition) {
|
||||
var model = definition.Settings.GetModel<TypeIndexing>();
|
||||
_contentTypeName = definition.Name;
|
||||
yield return DefinitionTemplate(model);
|
||||
}
|
||||
|
||||
@@ -16,9 +29,24 @@ namespace Orchard.Indexing.Settings {
|
||||
var model = new TypeIndexing();
|
||||
updateModel.TryUpdateModel(model, "TypeIndexing", null, null);
|
||||
builder.WithSetting("TypeIndexing.Included", model.Included ? true.ToString() : null);
|
||||
|
||||
CreateIndexingTasks();
|
||||
|
||||
yield return DefinitionTemplate(model);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates new indexing tasks to update the index document for these content items
|
||||
/// </summary>
|
||||
private void CreateIndexingTasks()
|
||||
{
|
||||
if (!_tasksCreated)
|
||||
{
|
||||
CreateTasksForType(_contentTypeName);
|
||||
_tasksCreated = true;
|
||||
}
|
||||
}
|
||||
|
||||
public override IEnumerable<TemplateViewModel> PartFieldEditor(ContentPartFieldDefinition definition) {
|
||||
var model = definition.Settings.GetModel<FieldIndexing>();
|
||||
yield return DefinitionTemplate(model);
|
||||
@@ -28,7 +56,16 @@ namespace Orchard.Indexing.Settings {
|
||||
var model = new FieldIndexing();
|
||||
updateModel.TryUpdateModel(model, "FieldIndexing", null, null);
|
||||
builder.WithSetting("FieldIndexing.Included", model.Included ? true.ToString() : null);
|
||||
|
||||
CreateIndexingTasks();
|
||||
|
||||
yield return DefinitionTemplate(model);
|
||||
}
|
||||
|
||||
private void CreateTasksForType(string type) {
|
||||
foreach (var contentItem in _contentManager.Query(VersionOptions.Published, new [] { type }).List()) {
|
||||
_indexingTaskManager.CreateUpdateIndexTask(contentItem);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user