Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lucene index rebuild and reset steps (Lombiq Technologies: OCORE-101) #12302

Closed
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace OrchardCore.Lucene.Deployment
{
/// <summary>
/// Adds rebuild lucene index task to a <see cref="DeploymentPlanResult"/>.
/// Adds rebuild Lucene index task to a <see cref="DeploymentPlanResult"/>.
/// </summary>
public class LuceneIndexRebuildDeploymentStep : DeploymentStep
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace OrchardCore.Lucene.Deployment
{
/// <summary>
/// Adds reset lucene index task to a <see cref="DeploymentPlanResult"/>.
/// Adds reset Lucene index task to a <see cref="DeploymentPlanResult"/>.
/// </summary>
public class LuceneIndexResetDeploymentStep : DeploymentStep
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using OrchardCore.BackgroundJobs;
using OrchardCore.Recipes.Models;
using OrchardCore.Recipes.Services;
Expand All @@ -11,29 +12,6 @@ namespace OrchardCore.Lucene.Recipes
/// </summary>
public class LuceneIndexRebuildStep : IRecipeStepHandler
{
private readonly LuceneIndexSettingsService _luceneIndexSettingsService;
private readonly LuceneIndexingService _luceneIndexingService;

public LuceneIndexRebuildStep(
LuceneIndexSettingsService luceneIndexSettingsService,
LuceneIndexingService luceneIndexingService
)
{
_luceneIndexSettingsService = luceneIndexSettingsService;
_luceneIndexingService = luceneIndexingService;
}

private async Task RebuildIndexAsync(string indexName)
{
var luceneIndexSettings = await _luceneIndexSettingsService.GetSettingsAsync(indexName);

if (luceneIndexSettings != null)
{
await _luceneIndexingService.RebuildIndexAsync(indexName);
await _luceneIndexingService.ProcessContentItemsAsync(indexName);
}
}

public async Task ExecuteAsync(RecipeExecutionContext context)
{
if (!String.Equals(context.Name, "lucene-index-rebuild", StringComparison.OrdinalIgnoreCase))
Expand All @@ -44,10 +22,18 @@ public async Task ExecuteAsync(RecipeExecutionContext context)
var indices = context.Step["Indices"];
if (indices != null)
{
await HttpBackgroundJob.ExecuteAfterEndOfRequestAsync("lucene-index-rebuild", async (shellScope) => {
foreach (var indexName in indices)
await HttpBackgroundJob.ExecuteAfterEndOfRequestAsync("lucene-index-rebuild", async (scope) => {
var luceneIndexSettingsService = scope.ServiceProvider.GetRequiredService<LuceneIndexSettingsService>();
var luceneIndexingService = scope.ServiceProvider.GetRequiredService<LuceneIndexingService>();
foreach (var indexToken in indices)
{
await RebuildIndexAsync(indexName.ToObject<string>());
var indexName = indexToken.ToObject<string>();
var luceneIndexSettings = await luceneIndexSettingsService.GetSettingsAsync(indexName);
if (luceneIndexSettings != null)
{
await luceneIndexingService.RebuildIndexAsync(indexName);
await luceneIndexingService.ProcessContentItemsAsync(indexName);
}
}
});
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using OrchardCore.BackgroundJobs;
using OrchardCore.Recipes.Models;
using OrchardCore.Recipes.Services;
Expand All @@ -11,41 +12,6 @@ namespace OrchardCore.Lucene.Recipes
/// </summary>
public class LuceneIndexResetStep : IRecipeStepHandler
{
private readonly LuceneIndexSettingsService _luceneIndexSettingsService;
private readonly LuceneIndexingService _luceneIndexingService;
private readonly LuceneIndexManager _luceneIndexManager;

public LuceneIndexResetStep(
LuceneIndexSettingsService luceneIndexSettingsService,
LuceneIndexingService luceneIndexingService,
LuceneIndexManager luceneIndexManager
)
{
_luceneIndexSettingsService = luceneIndexSettingsService;
_luceneIndexManager = luceneIndexManager;
_luceneIndexingService = luceneIndexingService;
}

private async Task ResetIndexAsync(string indexName)
{
var luceneIndexSettings = await _luceneIndexSettingsService.GetSettingsAsync(indexName);

if (luceneIndexSettings != null)
{
if (!_luceneIndexManager.Exists(indexName))
{
await _luceneIndexingService.CreateIndexAsync(luceneIndexSettings);
await _luceneIndexingService.ProcessContentItemsAsync(indexName);
}
else
{
_luceneIndexingService.ResetIndex(indexName);
await _luceneIndexingService.ProcessContentItemsAsync(indexName);
}
}
await Task.CompletedTask;
}

public async Task ExecuteAsync(RecipeExecutionContext context)
{
if (!String.Equals(context.Name, "lucene-index-reset", StringComparison.OrdinalIgnoreCase))
Expand All @@ -56,10 +22,26 @@ public async Task ExecuteAsync(RecipeExecutionContext context)
var indices = context.Step["Indices"];
if (indices != null)
{
await HttpBackgroundJob.ExecuteAfterEndOfRequestAsync("lucene-index-reset", async (shellScope) => {
foreach (var indexName in indices)
await HttpBackgroundJob.ExecuteAfterEndOfRequestAsync("lucene-index-reset", async (scope) => {
var luceneIndexSettingsService = scope.ServiceProvider.GetRequiredService<LuceneIndexSettingsService>();
var luceneIndexingService = scope.ServiceProvider.GetRequiredService<LuceneIndexingService>();
var luceneIndexManager = scope.ServiceProvider.GetRequiredService<LuceneIndexManager>();
foreach (var indexToken in indices)
{
await ResetIndexAsync(indexName.ToObject<string>());
var indexName = indexToken.ToObject<string>();
var luceneIndexSettings = await luceneIndexSettingsService.GetSettingsAsync(indexName);
if (luceneIndexSettings != null)
{
if (!luceneIndexManager.Exists(indexName))
{
await luceneIndexingService.CreateIndexAsync(luceneIndexSettings);
}
else
{
luceneIndexingService.ResetIndex(indexName);
}
await luceneIndexingService.ProcessContentItemsAsync(indexName);
}
}
});
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
@model LuceneIndexRebuildDeploymentStepViewModel

<h5>@T["Rebuild Search Indexes"]</h5>
<h5>@T["Rebuild Lucene Search Indices"]</h5>

<div class="mb-3 mt-4 mb-5">
<div class="row">
<div class="col">
<div class="form-check">
<label class="form-check-label">
<input class="form-check-input" asp-for="IncludeAll" data-element-id-to-collapse="indexes-list"/>
@T["Include all Search Indexes."]
@T["Include all Lucene search indices."]
</label>
</div>
</div>
Expand All @@ -18,7 +18,7 @@
<div id="indexes-list" class="mt-4 mb-5 collapse @(Model.IncludeAll ? "" : "show")">
<div class="row">
<div class="col-small">
<span class="hint">@T["The Search Indexes to rebuild as part of the plan."]</span>
<span class="hint">@T["The Lucene search indices to rebuild as part of the plan."]</span>
</div>
</div>
<div class="row">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
var indexNames = Model.Value.IndexNames;
}

<h5>@T["Rebuild Search Indexes"]</h5>
<h5>@T["Rebuild Lucene Search Indices"]</h5>

@if (includeAll)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@model dynamic

<h4 class="card-title">@T["Rebuild Search Indexes"]</h4>
<p>@T["Rebuild all or specified search indexes."]</p>
<h4 class="card-title">@T["Rebuild Lucene Search Indices"]</h4>
<p>@T["Rebuild all or specified Lucene search indices."]</p>
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
@model LuceneIndexResetDeploymentStepViewModel

<h5>@T["Reset Search Indexes"]</h5>
<h5>@T["Reset Lucene Search Indices"]</h5>

<div class="mb-3 mt-4 mb-5">
<div class="row">
<div class="col">
<div class="form-check">
<label class="form-check-label">
<input class="form-check-input" asp-for="IncludeAll" data-element-id-to-collapse="indexes-list" />
@T["Include all Search Indexes."]
@T["Include all Lucene search indices."]
</label>
</div>
</div>
Expand All @@ -18,7 +18,7 @@
<div id="indexes-list" class="mt-4 mb-5 collapse @(Model.IncludeAll ? "" : "show")">
<div class="row">
<div class="col-small">
<span class="hint">@T["The Search Indexes to reset as part of the plan."]</span>
<span class="hint">@T["The Lucene Search Indices to reset as part of the plan."]</span>
</div>
</div>
<div class="row">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
var indexNames = Model.Value.IndexNames;
}

<h5>@T["Reset Search Indexes"]</h5>
<h5>@T["Reset Lucene Search Indices"]</h5>

@if (includeAll)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@model dynamic

<h4 class="card-title">@T["Reset Search Indices"]</h4>
<p>@T["Reset all or specified search indexes."]</p>
<h4 class="card-title">@T["Reset Lucene Search Indices"]</h4>
<p>@T["Reset all or specified Lucene search indices."]</p>
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@
]
}
]
},
{
"name": "lucene-index-rebuild",
lampersky marked this conversation as resolved.
Show resolved Hide resolved
"Indices": [
"Search"
]
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -1292,6 +1292,6 @@
"Quality": 100
}
}
}
}
lampersky marked this conversation as resolved.
Show resolved Hide resolved
]
}
7 changes: 5 additions & 2 deletions src/docs/reference/modules/Recipes/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,11 @@ You can also set the default Lucene Settings.
}
```

### Reset Lucene Index Step
### Reset Lucene Search Index Step

This Reset Lucene Index Step resets a lucene index.
lampersky marked this conversation as resolved.
Show resolved Hide resolved
Restarts the indexing process from the beginning in order to update current content items.
It doesn't delete existing entries from the index.

```json
{
Expand All @@ -161,9 +163,10 @@ This Reset Lucene Index Step resets a lucene index.
}
```

### Rebuild Lucene Index Step
### Rebuild Lucene Search Index Step

This Rebuild Lucene Index Step rebuilds a lucene index.
Deletes and recreates the full index content.

```json
{
Expand Down