From bec80d144267bf1f9bab26b0da86e195f36b73e6 Mon Sep 17 00:00:00 2001 From: Shannon Date: Fri, 21 Jul 2023 12:40:04 -0600 Subject: [PATCH] Cherry pick some doc updates --- docs/articles/indexing.md | 102 +++++++++++++++++++- src/Examine.Lucene/Providers/LuceneIndex.cs | 3 + 2 files changed, 102 insertions(+), 3 deletions(-) diff --git a/docs/articles/indexing.md b/docs/articles/indexing.md index 2358cb8b8..946328376 100644 --- a/docs/articles/indexing.md +++ b/docs/articles/indexing.md @@ -144,16 +144,112 @@ Data is easily deleted from the index by the unique identifier you provided in y This event is part of the base interface [`IIndex`](xref:Examine.IIndex) so it is available to use on any implementation of an Examine index. This can be useful to know when an indexing operation is completed. +Example of how to listen the event: + +```csharp +if (!_examineManager.TryGetIndex(indexName, out var index)) +{ + throw new ArgumentException($"Index '{indexName}' not found"); +} + +index.IndexOperationComplete += IndexOperationComplete; +``` + +```csharp +private void IndexOperationComplete(object sender, IndexOperationEventArgs e) +{ + // Index operation completed +} +``` + #### [IIndex.TransformingIndexValues](xref:Examine.IIndex#Examine_IIndex_TransformingIndexValues) -This event allows for customizing the [`ValueSet`](xref:Examine.ValueSet) before it is passed to the indexer to be indexed. You can use this event to add additional field values or modify existing field values. +This event is part of the base interface [`IIndex`](xref:Examine.IIndex) so it is available to use on any implementation of an Examine index. This event allows for customizing the [`ValueSet`](xref:Examine.ValueSet) before it is passed to the indexer to be indexed. You can use this event to add additional field values or modify existing field values. + +Example of how to listen the event: + +```csharp +if (!_examineManager.TryGetIndex(indexName, out var index)) +{ + throw new ArgumentException($"Index '{indexName}' not found"); +} + +index.TransformingIndexValues += TransformingIndexValues; +``` + +```csharp +private void TransformingIndexValues(object sender, IndexingItemEventArgs e) +{ + // Customize the ValueSet +} +``` #### [IIndex.IndexingError](xref:Examine.IIndex#Examine_IIndex_IndexingError) -This event can be used for reacting to when an error occurs during index. For example, you could add an event handler for this event to facilitate error logging. +This event is part of the base interface [`IIndex`](xref:Examine.IIndex) so it is available to use on any implementation of an Examine index. This event can be used for reacting to when an error occurs during index. For example, you could add an event handler for this event to facilitate error logging. + +Example of how to listen the event: + +```csharp +if (!_examineManager.TryGetIndex(indexName, out var index)) +{ + throw new ArgumentException($"Index '{indexName}' not found"); +} + +index.IndexingError += IndexingError; +``` + +```csharp +private void IndexingError(object sender, IndexingErrorEventArgs e) +{ + // An indexing error occored +} +``` #### [LuceneIndex.DocumentWriting](xref:Examine.Lucene.Providers.LuceneIndex#Examine_Lucene_Providers_LuceneIndex_DocumentWriting) If using Examine with the default Lucene implementation then the [`IIndex`](xref:Examine.IIndex) implementation will be [`LuceneIndex`](xref:Examine.Lucene.Providers.LuceneIndex). This event provides access to the Lucene [`Document`](https://lucenenet.apache.org/docs/4.8.0-beta00016/api/core/Lucene.Net.Documents.Document.html) object before it gets added to the Lucene Index. -You can use this event to entirely customize how the data is stored in the Lucene index, including adding custom boosting profiles, changing the [`Document`](https://lucenenet.apache.org/docs/4.8.0-beta00016/api/core/Lucene.Net.Documents.Document.html)'s field values or types, etc... \ No newline at end of file +You can use this event to entirely customize how the data is stored in the Lucene index, including adding custom boosting profiles, changing the [`Document`](https://lucenenet.apache.org/docs/4.8.0-beta00016/api/core/Lucene.Net.Documents.Document.html)'s field values or types, etc... + +Example of how to listen the event: + +```csharp +if (!_examineManager.TryGetIndex(indexName, out var index)) +{ + throw new ArgumentException($"Index '{indexName}' not found"); +} + +if (index is LuceneIndex luceneIndex){ + luceneIndex.DocumentWriting += DocumentWriting; +} +``` + +```csharp +private void DocumentWriting(object sender, DocumentWritingEventArgs e) +{ + // Customize how the data is stored in the Lucene index +} +``` + +### [LuceneIndex.IndexCommitted](xref:Examine.Lucene.Providers.LuceneIndex#Examine_Lucene_Providers_LuceneIndex_IndexCommitted) +If using Examine with the default Lucene implementation then the [`IIndex`](xref:Examine.IIndex) implementation will be [`LuceneIndex`](xref:Examine.Lucene.Providers.LuceneIndex). This event is triggered when the index is commited. For example when clearing the index this event is run once when commiting. When rebuilding the event will be run once the rebuild commits a clearing of the index and when it's commiting the rebuilt index. +Example of how to listen the event: + +```csharp +if (!_examineManager.TryGetIndex(indexName, out var index)) +{ + throw new ArgumentException($"Index '{indexName}' not found"); +} + +if (index is LuceneIndex luceneIndex){ + luceneIndex.IndexCommitted += IndexCommited; +} +``` + +```csharp +private void IndexCommited(object sender, EventArgs e) +{ + // Triggered when the index is commited +} +``` \ No newline at end of file diff --git a/src/Examine.Lucene/Providers/LuceneIndex.cs b/src/Examine.Lucene/Providers/LuceneIndex.cs index 6ac9124eb..66958bf20 100644 --- a/src/Examine.Lucene/Providers/LuceneIndex.cs +++ b/src/Examine.Lucene/Providers/LuceneIndex.cs @@ -183,6 +183,9 @@ internal LuceneIndex( /// public event EventHandler DocumentWriting; + /// + /// Occors when the index is commited + /// public event EventHandler IndexCommitted; #endregion