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:
Sebastien Ros
2010-07-20 14:34:01 -07:00
parent e5d3357923
commit f97351ee59
3 changed files with 32 additions and 1 deletions

View File

@@ -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();
}
}
}
}
});
}
}
}

View File

@@ -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" />

View File

@@ -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; }
}
}