You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -144,12 +144,14 @@ Remember to register `ConfigureMemberIndexOptions` in your composer.
144
144
145
145
## Creating your own index
146
146
147
-
The following example will show how to create an index that will only include nodes based on the document type _product_.
147
+
### A custom Umbraco content index
148
+
149
+
The following example will show how to create an index that will only include nodes based on the **Product**.
148
150
149
151
{% hint style="info" %}
150
-
We always recommend that you use the existing builtin ExternalIndex. You should then query based on the NodeTypeAlias instead of creating a new separate index based on that particular node type. However, should the need arise, the example below will show you how to do it.
152
+
It is recommended to use the existing built-in `ExternalIndex`. You should then query based on the `NodeTypeAlias` instead of creating a new separate index based on that particular node type. However, should the need arise, the example below will show you how to do it.
151
153
152
-
Take a look at our[Examine Quick Start](quick-start.md) to see some examples of how to search the ExternalIndex.
154
+
Take a look at the[Examine Quick Start](quick-start.md) guide to see some examples of how to search the ExternalIndex.
153
155
{% endhint %}
154
156
155
157
To create this index we need five things:
@@ -161,7 +163,7 @@ To create this index we need five things:
161
163
5. An `INotificationHandler` implementation that updates the index when content changes.
162
164
6. A composer that adds all these services to the runtime.
163
165
164
-
### ProductIndex
166
+
####ProductIndex
165
167
166
168
```csharp
167
169
usingExamine.Lucene;
@@ -190,7 +192,7 @@ public class ProductIndex : UmbracoExamineIndex
190
192
}
191
193
```
192
194
193
-
### ConfigureProductIndexOptions
195
+
####ConfigureProductIndexOptions
194
196
195
197
```csharp
196
198
usingExamine;
@@ -238,7 +240,7 @@ public class ConfigureProductIndexOptions : IConfigureNamedOptions<LuceneDirecto
238
240
}
239
241
```
240
242
241
-
### ProductIndexValueSetBuilder
243
+
####ProductIndexValueSetBuilder
242
244
243
245
```csharp
244
246
usingExamine;
@@ -271,7 +273,7 @@ public class ProductIndexValueSetBuilder : IValueSetBuilder<IContent>
271
273
}
272
274
```
273
275
274
-
### ProductIndexPopulator
276
+
####ProductIndexPopulator
275
277
276
278
```csharp
277
279
usingExamine;
@@ -326,7 +328,7 @@ This is only an example of how you could do indexing. In this example, we're ind
326
328
In certain scenarios only published content should be added to the index. To achieve that, you will need to implement your own logic to filter out unpublished content. This can be somewhat tricky as the published state can vary throughout an entire structure of content nodes in the content tree. For inspiration on how to go about such filtering, you can look at the [ContentIndexPopulator in Umbraco](https://github.com/umbraco/Umbraco-CMS/blob/c878567633a6a3354c1414ccd130c9be518b25f0/src/Umbraco.Infrastructure/Examine/ContentIndexPopulator.cs#L115).
327
329
{% endhint %}
328
330
329
-
### ProductIndexingNotificationHandler
331
+
####ProductIndexingNotificationHandler
330
332
331
333
The index will only update its content when you manually trigger an index rebuild in the Examine dashboard. This is not always the desired behavior for a custom index.
332
334
@@ -452,7 +454,7 @@ public class ProductIndexingNotificationHandler : INotificationHandler<ContentCa
452
454
You can find further inspiration for implementing notification handlers (_for example, for media updates_) in the [UmbracoExamine.PDF package](https://github.com/umbraco/UmbracoExamine.PDF).
453
455
{% endhint %}
454
456
455
-
### ExamineComposer
457
+
####ExamineComposer
456
458
457
459
```csharp
458
460
usingExamine;
@@ -462,6 +464,7 @@ using Umbraco.Cms.Infrastructure.Examine;
462
464
463
465
namespaceUmbraco.Docs.Samples.Web.CustomIndexing;
464
466
467
+
[ComposeAfter(typeof(AddExamineComposer))]
465
468
publicclassExamineComposer : IComposer
466
469
{
467
470
publicvoidCompose(IUmbracoBuilderbuilder)
@@ -483,8 +486,192 @@ public class ExamineComposer : IComposer
483
486
The order of these registrations matters. It is important to register your index with `AddExamineLuceneIndex` before calling `ConfigureOptions`.
If you have a need, you can also use an Examine index for other data, that you aren't managing as Umbraco content.
498
+
499
+
As an illustrative example, consider a collection of books. This example uses a hardcoded collection. In a real-world scenario, the data would more likely come from a database.
500
+
501
+
```csharp
502
+
namespaceUmbraco.Docs.Samples.Web.CustomIndexing;
503
+
504
+
publicclassBook
505
+
{
506
+
publicintId { get; set; }
507
+
508
+
publicstringTitle { get; set; } =string.Empty;
509
+
510
+
publicstringAuthor { get; set; } =string.Empty;
511
+
512
+
publicintPublishedYear { get; set; }
513
+
}
514
+
515
+
publicstaticclassBookData
516
+
{
517
+
publicstaticList<Book> GetBooks() =>
518
+
[
519
+
new() { Id=1, Title="The Great Gatsby", Author="F. Scott Fitzgerald", PublishedYear=1925 },
new() { Id=4, Title="Pride and Prejudice", Author="Jane Austen", PublishedYear=1813 },
523
+
new() { Id=5, Title="The Catcher in the Rye", Author="J.D. Salinger", PublishedYear=1951 }
524
+
];
525
+
}
526
+
```
527
+
528
+
As with the previous example, define an index. At this time, Umbraco data isn't being indexed; the implementation inherits directly from `LuceneIndex`:
0 commit comments