mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-09-19 01:57:55 +08:00
Index dynamic content fields
- Create a new index field named {part}-{field} - Had to remove "protected" qualifier on Storage accessor --HG-- branch : dev
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.ContentManagement.FieldStorage.InfosetStorage;
|
||||
using Orchard.ContentManagement.Handlers;
|
||||
using Orchard.Indexing.Settings;
|
||||
|
||||
namespace Orchard.Indexing.Handlers {
|
||||
public class InfosetFieldIndexingHandler : ContentHandler {
|
||||
|
||||
public InfosetFieldIndexingHandler() {
|
||||
|
||||
OnIndexing<InfosetPart>(
|
||||
(context, cp) => {
|
||||
var infosetPart = context.ContentItem.As<InfosetPart>();
|
||||
if ( infosetPart != null ) {
|
||||
foreach ( var part in infosetPart.ContentItem.Parts ) {
|
||||
foreach ( var field in part.PartDefinition.Fields ) {
|
||||
if ( field.Settings.GetModel<FieldIndexing>().Included ) {
|
||||
var fieldName = field.Name;
|
||||
var value = part.Fields.Where(f => f.Name == fieldName).First().Storage.Get<string>(null);
|
||||
context.DocumentIndex.Add(String.Format("{0}-{1}", infosetPart.TypeDefinition.Name, fieldName.ToLower()), value).RemoveTags().Analyze();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
@@ -63,6 +63,7 @@
|
||||
<Compile Include="Controllers\AdminController.cs" />
|
||||
<Compile Include="DataMigrations\IndexingDataMigration.cs" />
|
||||
<Compile Include="Handlers\CreateIndexingTaskHandler.cs" />
|
||||
<Compile Include="Handlers\InfosetFieldIndexingHandler.cs" />
|
||||
<Compile Include="Models\IndexingTask.cs" />
|
||||
<Compile Include="Models\IndexingTaskRecord.cs" />
|
||||
<Compile Include="Permissions.cs" />
|
||||
|
@@ -9,6 +9,6 @@ namespace Orchard.ContentManagement {
|
||||
public ContentPartDefinition.Field PartFieldDefinition { get; set; }
|
||||
public ContentFieldDefinition FieldDefinition { get { return PartFieldDefinition.FieldDefinition; } }
|
||||
|
||||
public IFieldStorage Storage { protected get; set; }
|
||||
public IFieldStorage Storage { get; set; }
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user