-
Notifications
You must be signed in to change notification settings - Fork 60
/
Copy pathColorFieldIndexHandler.cs
33 lines (26 loc) · 1.23 KB
/
ColorFieldIndexHandler.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/*
* IndexHandlers are different from IndexProviders. While IndexProviders will store indexed values in the SQL database
* to index documents, IndexHandlers will use a text search index provider (e.g. Lucene) to index data. This way the
* text search will be executed by the indexing service.
*/
using Lombiq.TrainingDemo.Fields;
using OrchardCore.Indexing;
using System.Threading.Tasks;
namespace Lombiq.TrainingDemo.Indexing;
// Don't forget to register this class with the service provider (see: Startup.cs).
public class ColorFieldIndexHandler : ContentFieldIndexHandler<ColorField>
{
public override Task BuildIndexAsync(ColorField field, BuildFieldIndexContext context)
{
var options = context.Settings.ToOptions();
foreach (var key in context.Keys)
{
// The color name will be indexed. Keys identify a piece of text in the index document of a given content
// item. So for example two fields (named differently of course) will have different keys.
context.DocumentIndex.Set(key, field.ColorName, options);
}
return Task.CompletedTask;
}
}
// END OF TRAINING SECTION: Indexing Content Fields in Lucene
// NEXT STATION: Views/ColorField.Option.cshtml