Simplifying LayoutPart indexing.

- Removed all the infrastructural code that enabled each element to contribute to the index.
- Indexing now happens in the LayoutPartHandler, where the LayoutPart is rendered to HTML, which is then being indexed.
This commit is contained in:
Sipke Schoorstra
2014-11-19 21:40:04 -08:00
parent 004caf387f
commit a7b0308e9a
12 changed files with 15 additions and 82 deletions

View File

@@ -1,6 +1,5 @@
using Orchard.Layouts.Elements;
using Orchard.Layouts.Framework.Drivers;
using Orchard.Layouts.Framework.Elements;
using Orchard.Layouts.ViewModels;
namespace Orchard.Layouts.Drivers {
@@ -19,11 +18,5 @@ namespace Orchard.Layouts.Drivers {
return Editor(context, editor);
}
protected override void OnIndexing(Html element, ElementIndexingContext context) {
context.DocumentIndex
.Add("body", element.Content).RemoveTags().Analyze()
.Add("format", "html").Store();
}
}
}

View File

@@ -1,7 +1,6 @@
using Orchard.Environment.Extensions;
using Orchard.Layouts.Framework.Display;
using Orchard.Layouts.Framework.Drivers;
using Orchard.Layouts.Framework.Elements;
using Orchard.Layouts.ViewModels;
using MarkdownElement = Orchard.Layouts.Elements.Markdown;
@@ -27,12 +26,6 @@ namespace Orchard.Layouts.Drivers {
context.ElementShape.ProcessedContent = ToHtml(element.Content);
}
protected override void OnIndexing(MarkdownElement element, ElementIndexingContext context) {
context.DocumentIndex
.Add("body", element.Content).RemoveTags().Analyze()
.Add("format", "markdown").Store();
}
private string ToHtml(string markdown) {
return new MarkdownSharp.Markdown().Transform(markdown);
}

View File

@@ -1,6 +1,5 @@
using Orchard.Layouts.Elements;
using Orchard.Layouts.Framework.Drivers;
using Orchard.Layouts.Framework.Elements;
using Orchard.Layouts.ViewModels;
namespace Orchard.Layouts.Drivers {
@@ -19,11 +18,5 @@ namespace Orchard.Layouts.Drivers {
return Editor(context, editor);
}
protected override void OnIndexing(Paragraph element, ElementIndexingContext context) {
context.DocumentIndex
.Add("body", element.Content).RemoveTags().Analyze()
.Add("format", "text").Store();
}
}
}

View File

@@ -45,15 +45,6 @@ namespace Orchard.Layouts.Drivers {
context.ElementShape.ProcessedText = processedText;
}
protected override void OnIndexing(Text element, ElementIndexingContext context) {
var layoutPart = context.Layout.As<LayoutPart>();
var flavor = GetFlavor(layoutPart);
context.DocumentIndex
.Add("body", element.Content).RemoveTags().Analyze()
.Add("format", flavor).Store();
}
private string ToHtml(string content, string flavor) {
return _htmlFilters.Aggregate(content, (t, filter) => filter.ProcessContent(t, flavor));
}

View File

@@ -29,10 +29,6 @@ namespace Orchard.Layouts.Framework.Drivers {
OnRemoving((TElement) context.Element, context);
}
public void Indexing(ElementIndexingContext context) {
OnIndexing((TElement)context.Element, context);
}
public void Exporting(ExportElementContext context) {
OnExporting((TElement)context.Element, context);
}
@@ -58,9 +54,6 @@ namespace Orchard.Layouts.Framework.Drivers {
protected virtual void OnRemoving(TElement element, ElementRemovingContext context) {
}
protected virtual void OnIndexing(TElement element, ElementIndexingContext context) {
}
protected virtual void OnExporting(TElement element, ExportElementContext context) {
}

View File

@@ -9,7 +9,6 @@ namespace Orchard.Layouts.Framework.Drivers {
void Displaying(ElementDisplayContext context);
void LayoutSaving(ElementSavingContext context);
void Removing(ElementRemovingContext context);
void Indexing(ElementIndexingContext context);
void Exporting(ExportElementContext context);
void Importing(ImportElementContext context);
}

View File

@@ -1,10 +0,0 @@
namespace Orchard.Layouts.Framework.Elements {
public class ElementIndexingContext : LayoutIndexingContext {
public ElementIndexingContext(LayoutIndexingContext stub) {
DocumentIndex = stub.DocumentIndex;
Layout = stub.Layout;
Elements = stub.Elements;
}
public IElement Element { get; set; }
}
}

View File

@@ -1,11 +0,0 @@
using System.Collections.Generic;
using Orchard.Indexing;
using Orchard.Layouts.Models;
namespace Orchard.Layouts.Framework.Elements {
public class LayoutIndexingContext {
public ILayoutAspect Layout { get; set; }
public IEnumerable<IElement> Elements { get; set; }
public IDocumentIndex DocumentIndex { get; set; }
}
}

View File

@@ -1,8 +1,7 @@
using Orchard.ContentManagement;
using Orchard.ContentManagement.Handlers;
using Orchard.Data;
using Orchard.Layouts.Framework.Elements;
using Orchard.Layouts.Helpers;
using Orchard.DisplayManagement;
using Orchard.Layouts.Models;
using Orchard.Layouts.Services;
@@ -10,29 +9,32 @@ namespace Orchard.Layouts.Handlers {
public class LayoutPartHandler : ContentHandler {
private readonly ILayoutManager _layoutManager;
private readonly IContentManager _contentManager;
private readonly IElementManager _elementManager;
private readonly IContentPartDisplay _contentPartDisplay;
private readonly IShapeDisplay _shapeDisplay;
public LayoutPartHandler(
IRepository<LayoutPartRecord> repository,
ILayoutManager layoutManager,
IContentManager contentManager,
IElementManager elementManager) {
IContentPartDisplay contentPartDisplay,
IShapeDisplay shapeDisplay) {
_layoutManager = layoutManager;
_contentManager = contentManager;
_elementManager = elementManager;
_contentPartDisplay = contentPartDisplay;
_shapeDisplay = shapeDisplay;
Filters.Add(StorageFilter.For(repository));
OnPublished<LayoutPart>(UpdateTemplateClients);
OnIndexing<LayoutPart>(IndexElements);
OnIndexing<LayoutPart>(IndexLayout);
}
private void IndexElements(IndexContentContext context, LayoutPart part) {
var elements = _layoutManager.LoadElements(part).Flatten();
_elementManager.Indexing(new LayoutIndexingContext {
Layout = part,
Elements = elements,
DocumentIndex = context.DocumentIndex
});
private void IndexLayout(IndexContentContext context, LayoutPart part) {
var layoutShape = _contentPartDisplay.BuildDisplay(part);
var layoutHtml = _shapeDisplay.Display(layoutShape);
context.DocumentIndex
.Add("body", layoutHtml).RemoveTags().Analyze()
.Add("format", "html").Store();
}
private void UpdateTemplateClients(PublishContentContext context, LayoutPart part) {

View File

@@ -230,8 +230,6 @@
<Compile Include="Framework\Display\ElementCreatingDisplayShapeContext.cs" />
<Compile Include="Framework\Drivers\ImportElementContext.cs" />
<Compile Include="Framework\Drivers\ImportLayoutContext.cs" />
<Compile Include="Framework\Elements\ElementIndexingContext.cs" />
<Compile Include="Framework\Elements\LayoutIndexingContext.cs" />
<Compile Include="Handlers\ElementDriversCoordinator.cs" />
<Compile Include="Helpers\DictionaryExtensions.cs" />
<Compile Include="Helpers\EditorResultExtensions.cs" />

View File

@@ -150,13 +150,6 @@ namespace Orchard.Layouts.Services {
}));
}
public void Indexing(LayoutIndexingContext context) {
var elementInstances = context.Elements.Flatten();
InvokeDriver(elementInstances, (driver, elementInstance) => driver.Indexing(new ElementIndexingContext(context) {
Element = elementInstance
}));
}
public void Exporting(IEnumerable<IElement> elements, ExportLayoutContext context) {
InvokeDriver(elements, (driver, element) => {
var exportElementContext = new ExportElementContext {

View File

@@ -22,7 +22,6 @@ namespace Orchard.Layouts.Services {
EditorResult UpdateEditor(ElementEditorContext context);
void Saving(LayoutSavingContext context);
void Removing(LayoutSavingContext context);
void Indexing(LayoutIndexingContext context);
void Exporting(IEnumerable<IElement> elements, ExportLayoutContext context);
void Importing(IEnumerable<IElement> elements, ImportLayoutContext context);
}