Skip to content

Commit 0803fba

Browse files
authored
Improve documentations for the indexing module (#18016)
1 parent 47f455d commit 0803fba

File tree

13 files changed

+263
-58
lines changed

13 files changed

+263
-58
lines changed

src/OrchardCore.Modules/OrchardCore.Indexing/Deployments/IndexProfileDeploymentStepDisplayDriver.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public override IDisplayResult Edit(IndexProfileDeploymentStep step, BuildEditor
3939
model.IncludeAll = step.IncludeAll;
4040
model.Indexes = (await _store.GetAllAsync()).Select(x => new SelectListItem(x.Name, x.Id)
4141
{
42-
Selected = step.IndexeIds?.Contains(x.IndexName) ?? false,
42+
Selected = step.IndexIds?.Contains(x.IndexName) ?? false,
4343
}).OrderBy(x => x.Text)
4444
.ToArray();
4545
}).Location("Content");
@@ -56,7 +56,7 @@ await context.Updater.TryUpdateModelAsync(model, Prefix,
5656
if (model.IncludeAll)
5757
{
5858
step.IncludeAll = true;
59-
step.IndexeIds = [];
59+
step.IndexIds = [];
6060
}
6161
else
6262
{
@@ -66,7 +66,7 @@ await context.Updater.TryUpdateModelAsync(model, Prefix,
6666
}
6767

6868
step.IncludeAll = false;
69-
step.IndexeIds = model.Indexes.Where(x => x.Selected).Select(x => x.Value).ToArray();
69+
step.IndexIds = model.Indexes.Where(x => x.Selected).Select(x => x.Value).ToArray();
7070
}
7171

7272
return Edit(step, context);

src/OrchardCore.Modules/OrchardCore.Indexing/Startup.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public sealed class RecipesStartup : StartupBase
5454
{
5555
public override void ConfigureServices(IServiceCollection services)
5656
{
57-
services.AddRecipeExecutionStep<IndexingProfileStep>();
57+
services.AddRecipeExecutionStep<CreateOrUpdateIndexProfileStep>();
5858
services.AddRecipeExecutionStep<ResetIndexProfileStep>();
5959
services.AddRecipeExecutionStep<RebuildIndexProfileStep>();
6060
}

src/OrchardCore.Modules/OrchardCore.Indexing/Views/Items/IndexProfileDeploymentStep.Summary.cshtml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
{
1212
<span class="badge text-bg-success">@T["All Indexes"]</span>
1313
}
14-
else if (Model.Value.IndexeIds?.Length > 0)
14+
else if (Model.Value.IndexIds?.Length > 0)
1515
{
16-
<span class="badge text-bg-warning">@T.Plural(Model.Value.IndexeIds.Length, "1 selected index.", "{0} selected indexes.", Model.Value.IndexeIds.Length)</span>
16+
<span class="badge text-bg-warning">@T.Plural(Model.Value.IndexIds.Length, "1 selected index.", "{0} selected indexes.", Model.Value.IndexIds.Length)</span>
1717
}
1818
else
1919
{

src/OrchardCore/OrchardCore.Indexing.Core/Deployments/IndexProfileDeploymentSource.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ protected override async Task ProcessAsync(IndexProfileDeploymentStep step, Depl
3030

3131
var sourceIds = step.IncludeAll
3232
? []
33-
: step.IndexeIds ?? [];
33+
: step.IndexIds ?? [];
3434

3535
foreach (var index in indexes)
3636
{

src/OrchardCore/OrchardCore.Indexing.Core/Deployments/IndexProfileDeploymentStep.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ public sealed class IndexProfileDeploymentStep : DeploymentStep
77
{
88
public IndexProfileDeploymentStep()
99
{
10-
Name = IndexingProfileStep.StepKey;
10+
Name = CreateOrUpdateIndexProfileStep.StepKey;
1111
}
1212

1313
public bool IncludeAll { get; set; }
1414

15-
public string[] IndexeIds { get; set; }
15+
public string[] IndexIds { get; set; }
1616
}

src/OrchardCore/OrchardCore.Indexing.Core/Recipes/IndexingProfileStep.cs renamed to src/OrchardCore/OrchardCore.Indexing.Core/Recipes/CreateOrUpdateIndexProfileStep.cs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,19 @@
77

88
namespace OrchardCore.Indexing.Core.Recipes;
99

10-
public sealed class IndexingProfileStep : NamedRecipeStepHandler
10+
public sealed class CreateOrUpdateIndexProfileStep : NamedRecipeStepHandler
1111
{
12-
public const string StepKey = "IndexingProfile";
12+
public const string StepKey = "CreateOrUpdateIndexProfile";
1313

1414
private readonly IIndexProfileManager _indexProfileManager;
1515
private readonly IndexingOptions _indexingOptions;
1616

1717
internal readonly IStringLocalizer S;
1818

19-
public IndexingProfileStep(
19+
public CreateOrUpdateIndexProfileStep(
2020
IIndexProfileManager indexProfileManager,
2121
IOptions<IndexingOptions> indexingOptions,
22-
IStringLocalizer<IndexingProfileStep> stringLocalizer)
22+
IStringLocalizer<CreateOrUpdateIndexProfileStep> stringLocalizer)
2323
: base(StepKey)
2424
{
2525
_indexProfileManager = indexProfileManager;
@@ -37,8 +37,9 @@ protected override async Task HandleAsync(RecipeExecutionContext context)
3737
IndexProfile indexProfile = null;
3838

3939
var id = token[nameof(indexProfile.Id)]?.GetValue<string>();
40+
var hasId = !string.IsNullOrEmpty(id);
4041

41-
if (!string.IsNullOrEmpty(id))
42+
if (hasId)
4243
{
4344
indexProfile = await _indexProfileManager.FindByIdAsync(id);
4445
}
@@ -85,6 +86,11 @@ protected override async Task HandleAsync(RecipeExecutionContext context)
8586
}
8687

8788
indexProfile = await _indexProfileManager.NewAsync(providerName, type, token);
89+
90+
if (hasId)
91+
{
92+
indexProfile.Id = id;
93+
}
8894
}
8995

9096
var validationResult = await _indexProfileManager.ValidateAsync(indexProfile);

src/OrchardCore/OrchardCore.Indexing.Core/Recipes/RebuildIndexProfileStep.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ protected override async Task HandleAsync(RecipeExecutionContext context)
2525
return;
2626
}
2727

28-
if (!model.IncludeAll && (model.IndexeIds == null || model.IndexeIds.Length == 0))
28+
if (!model.IncludeAll && (model.IndexIds == null || model.IndexIds.Length == 0))
2929
{
3030
return;
3131
}
@@ -36,7 +36,7 @@ await HttpBackgroundJob.ExecuteAfterEndOfRequestAsync("rebuild-index-profile", a
3636

3737
var indexes = model.IncludeAll
3838
? await indexProfileManager.GetAllAsync()
39-
: (await indexProfileManager.GetAllAsync()).Where(x => model.IndexeIds.Contains(x.Id, StringComparer.OrdinalIgnoreCase));
39+
: (await indexProfileManager.GetAllAsync()).Where(x => model.IndexIds.Contains(x.Id, StringComparer.OrdinalIgnoreCase) || model.IndexIds.Contains(x.Name, StringComparer.OrdinalIgnoreCase));
4040

4141
Dictionary<string, IIndexManager> indexManagers = new();
4242

src/OrchardCore/OrchardCore.Indexing.Core/Recipes/ResetIndexProfileStep.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ protected override async Task HandleAsync(RecipeExecutionContext context)
2525
return;
2626
}
2727

28-
if (!model.IncludeAll && (model.IndexeIds == null || model.IndexeIds.Length == 0))
28+
if (!model.IncludeAll && (model.IndexIds == null || model.IndexIds.Length == 0))
2929
{
3030
return;
3131
}
@@ -36,7 +36,7 @@ await HttpBackgroundJob.ExecuteAfterEndOfRequestAsync("reset-index-profile", asy
3636

3737
var indexes = model.IncludeAll
3838
? await indexProfileManager.GetAllAsync()
39-
: (await indexProfileManager.GetAllAsync()).Where(x => model.IndexeIds.Contains(x.Id, StringComparer.OrdinalIgnoreCase));
39+
: (await indexProfileManager.GetAllAsync()).Where(x => model.IndexIds.Contains(x.Id, StringComparer.OrdinalIgnoreCase) || model.IndexIds.Contains(x.Name, StringComparer.OrdinalIgnoreCase));
4040

4141
foreach (var index in indexes)
4242
{

src/docs/reference/modules/AzureAISearch/README.md

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,44 @@ The `Create Index Step` create an Azure AI Search index if one does not already
8383
}
8484
```
8585

86-
note !!!
87-
It's recommended to use the `Indexing` recipe step instead as the `azureai-index-create` step is obsolete.
86+
!!! note
87+
It's recommended to use the `CreateOrUpdateIndexProfile` recipe step instead as the `azureai-index-create` step is obsolete.
8888

89+
Here is an example of how to create `AzureAISearch` index profile using the `IndexProfile` for Content items.
90+
91+
```json
92+
{
93+
"steps":[
94+
{
95+
"name":"CreateOrUpdateIndexProfile",
96+
"indexes": [
97+
{
98+
"Name": "BlogPostsAI",
99+
"IndexName": "blogposts",
100+
"ProviderName": "AzureAISearch",
101+
"Type": "Content",
102+
"Properties": {
103+
"ContentIndexMetadata": {
104+
"IndexLatest": false,
105+
"IndexedContentTypes": ["BlogPosts"],
106+
"Culture": "any"
107+
},
108+
"AzureAISearchIndexMetadata": {
109+
"AnalyzerName": "standard"
110+
},
111+
"AzureAISearchDefaultQueryMetadata": {
112+
"QueryAnalyzerName": "standard.lucene",
113+
"DefaultSearchFields": [
114+
"Content__ContentItem__FullText"
115+
]
116+
}
117+
}
118+
}
119+
]
120+
}
121+
]
122+
}
123+
```
89124

90125
### Reset Azure AI Search Index Step
91126

@@ -118,8 +153,8 @@ To reset all indices:
118153
}
119154
```
120155

121-
note !!!
122-
It's recommended to use the `ResetIndexing` recipe step instead as the `azureai-index-reset` step is obsolete.
156+
!!! note
157+
It's recommended to use the `ResetIndexProfile` recipe step instead as the `azureai-index-reset` step is obsolete.
123158

124159
### Rebuild Azure AI Search Index Step
125160

@@ -152,8 +187,8 @@ To rebuild all indices:
152187
}
153188
```
154189

155-
note !!!
156-
It's recommended to use the `RebuildIndexing` recipe step instead as the `azureai-index-rebuild` step is obsolete.
190+
!!! note
191+
It's recommended to use the `RebuildIndexProfile` recipe step instead as the `azureai-index-rebuild` step is obsolete.
157192

158193
## Search Module (`OrchardCore.Search`)
159194

src/docs/reference/modules/Elasticsearch/README.md

Lines changed: 46 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,48 @@ Here is a sample step:
7878
]
7979
}
8080
```
81-
note !!!
82-
It's recommended to use the `IndexProfile` recipe step instead as the `ElasticIndexSettings` step is obsolete.
81+
82+
!!! note
83+
It's recommended to use the `CreateOrUpdateIndexProfile` recipe step instead as the `ElasticIndexSettings` step is obsolete.
84+
85+
Here is an example of how to create `Elasticsearch` index profile using the `IndexProfile` for Content items.
86+
87+
```json
88+
{
89+
"steps":[
90+
{
91+
"name":"CreateOrUpdateIndexProfile",
92+
"indexes": [
93+
{
94+
"Name": "BlogPostsES",
95+
"IndexName": "blogposts",
96+
"ProviderName": "Elasticsearch",
97+
"Type": "Content",
98+
"Properties": {
99+
"ContentIndexMetadata": {
100+
"IndexLatest": false,
101+
"IndexedContentTypes": ["BlogPosts"],
102+
"Culture": "any"
103+
},
104+
"ElasticsearchIndexMetadata": {
105+
"AnalyzerName": "standard",
106+
"StoreSourceData": true,
107+
},
108+
"ElasticsearchDefaultQueryMetadata": {
109+
"QueryAnalyzerName": "standard",
110+
"SearchType": "", // The search type can be "query_string", "custom", or empty for default search type.
111+
"DefaultQuery": "", // When using "custom" search type, this is the query to use.
112+
"DefaultSearchFields": [
113+
"Content.ContentItem.FullText"
114+
]
115+
}
116+
}
117+
}
118+
]
119+
}
120+
]
121+
}
122+
```
83123

84124
### Reset Elasticsearch Index Step
85125

@@ -114,8 +154,8 @@ To reset all indices:
114154
}
115155
```
116156

117-
note !!!
118-
It's recommended to use the `ResetIndexProfile` recipe step instead as the `elastic-index-reset` step is obsolete.
157+
!!! note
158+
It's recommended to use the `ResetIndexProfile` recipe step instead as the `elastic-index-reset` step is obsolete.
119159

120160
### Rebuild Elasticsearch Index Step
121161

@@ -149,8 +189,8 @@ To rebuild all indices:
149189
}
150190
```
151191

152-
note !!!
153-
It's recommended to use the `RebuildIndexProfile` recipe step instead as the `elastic-index-rebuild` step is obsolete.
192+
!!! note
193+
It's recommended to use the `RebuildIndexProfile` recipe step instead as the `elastic-index-rebuild` step is obsolete.
154194

155195
### Queries recipe step
156196

0 commit comments

Comments
 (0)