generated from Kentico/repo-template
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
27 changed files
with
2,305 additions
and
2,305 deletions.
There are no files selected for viewing
Binary file modified
BIN
-18 Bytes
(100%)
images/xperience-administration-search-index-edit-form-paths-edit.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
136 changes: 68 additions & 68 deletions
136
src/Kentico.Xperience.Lucene.Admin/LuceneConfigurationModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,68 +1,68 @@ | ||
using System.ComponentModel.DataAnnotations; | ||
|
||
using Kentico.Xperience.Admin.Base.FormAnnotations; | ||
using Kentico.Xperience.Admin.Base.Forms; | ||
using Kentico.Xperience.Lucene.Admin.Providers; | ||
using Kentico.Xperience.Lucene.Core.Indexing; | ||
|
||
namespace Kentico.Xperience.Lucene.Admin; | ||
|
||
public class LuceneConfigurationModel | ||
{ | ||
public int Id { get; set; } | ||
|
||
[TextInputComponent( | ||
Label = "Index Name", | ||
ExplanationText = "Changing this value on an existing index without changing application code will cause the search experience to stop working.", | ||
Order = 1)] | ||
[Required] | ||
[MinLength(1)] | ||
public string IndexName { get; set; } = ""; | ||
|
||
[GeneralSelectorComponent(dataProviderType: typeof(LanguageOptionsProvider), Label = "Indexed Languages", Order = 2)] | ||
public IEnumerable<string> LanguageNames { get; set; } = Enumerable.Empty<string>(); | ||
|
||
[DropDownComponent(Label = "Channel Name", DataProviderType = typeof(ChannelOptionsProvider), Order = 3)] | ||
public string ChannelName { get; set; } = ""; | ||
|
||
[DropDownComponent(Label = "Indexing Strategy", DataProviderType = typeof(IndexingStrategyOptionsProvider), Order = 4)] | ||
public string StrategyName { get; set; } = ""; | ||
|
||
[DropDownComponent(Label = "Lucene Analyzer", DataProviderType = typeof(AnalyzerOptionsProvider), Order = 5)] | ||
public string AnalyzerName { get; set; } = ""; | ||
|
||
[TextInputComponent(Label = "Rebuild Hook")] | ||
public string RebuildHook { get; set; } = ""; | ||
|
||
[LuceneIndexConfigurationComponent(Label = "Included Paths")] | ||
public IEnumerable<LuceneIndexIncludedPath> Paths { get; set; } = Enumerable.Empty<LuceneIndexIncludedPath>(); | ||
|
||
public LuceneConfigurationModel() { } | ||
|
||
public LuceneConfigurationModel( | ||
LuceneIndexModel luceneModel | ||
) | ||
{ | ||
Id = luceneModel.Id; | ||
IndexName = luceneModel.IndexName; | ||
LanguageNames = luceneModel.LanguageNames; | ||
ChannelName = luceneModel.ChannelName; | ||
StrategyName = luceneModel.StrategyName; | ||
AnalyzerName = luceneModel.AnalyzerName; | ||
RebuildHook = luceneModel.RebuildHook; | ||
Paths = luceneModel.Paths; | ||
} | ||
|
||
public LuceneIndexModel ToLuceneModel() => | ||
new() | ||
{ | ||
Id = Id, | ||
IndexName = IndexName, | ||
LanguageNames = LanguageNames, | ||
ChannelName = ChannelName, | ||
AnalyzerName = AnalyzerName, | ||
StrategyName = StrategyName, | ||
RebuildHook = RebuildHook, | ||
Paths = Paths | ||
}; | ||
} | ||
using System.ComponentModel.DataAnnotations; | ||
|
||
using Kentico.Xperience.Admin.Base.FormAnnotations; | ||
using Kentico.Xperience.Admin.Base.Forms; | ||
using Kentico.Xperience.Lucene.Admin.Providers; | ||
using Kentico.Xperience.Lucene.Core.Indexing; | ||
|
||
namespace Kentico.Xperience.Lucene.Admin; | ||
|
||
public class LuceneConfigurationModel | ||
{ | ||
public int Id { get; set; } | ||
|
||
[TextInputComponent( | ||
Label = "Index Name", | ||
ExplanationText = "Changing this value on an existing index without changing application code will cause the search experience to stop working.", | ||
Order = 1)] | ||
[Required] | ||
[MinLength(1)] | ||
public string IndexName { get; set; } = ""; | ||
|
||
[GeneralSelectorComponent(dataProviderType: typeof(LanguageOptionsProvider), Label = "Indexed Languages", Order = 2)] | ||
public IEnumerable<string> LanguageNames { get; set; } = Enumerable.Empty<string>(); | ||
|
||
[DropDownComponent(Label = "Channel Name", DataProviderType = typeof(ChannelOptionsProvider), Order = 3)] | ||
public string ChannelName { get; set; } = ""; | ||
|
||
[DropDownComponent(Label = "Indexing Strategy", DataProviderType = typeof(IndexingStrategyOptionsProvider), Order = 4)] | ||
public string StrategyName { get; set; } = ""; | ||
|
||
[DropDownComponent(Label = "Lucene Analyzer", DataProviderType = typeof(AnalyzerOptionsProvider), Order = 5)] | ||
public string AnalyzerName { get; set; } = ""; | ||
|
||
[TextInputComponent(Label = "Rebuild Hook")] | ||
public string RebuildHook { get; set; } = ""; | ||
|
||
[LuceneIndexConfigurationComponent(Label = "Included Paths")] | ||
public IEnumerable<LuceneIndexIncludedPath> Paths { get; set; } = Enumerable.Empty<LuceneIndexIncludedPath>(); | ||
|
||
public LuceneConfigurationModel() { } | ||
|
||
public LuceneConfigurationModel( | ||
LuceneIndexModel luceneModel | ||
) | ||
{ | ||
Id = luceneModel.Id; | ||
IndexName = luceneModel.IndexName; | ||
LanguageNames = luceneModel.LanguageNames; | ||
ChannelName = luceneModel.ChannelName; | ||
StrategyName = luceneModel.StrategyName; | ||
AnalyzerName = luceneModel.AnalyzerName; | ||
RebuildHook = luceneModel.RebuildHook; | ||
Paths = luceneModel.Paths; | ||
} | ||
|
||
public LuceneIndexModel ToLuceneModel() => | ||
new() | ||
{ | ||
Id = Id, | ||
IndexName = IndexName, | ||
LanguageNames = LanguageNames, | ||
ChannelName = ChannelName, | ||
AnalyzerName = AnalyzerName, | ||
StrategyName = StrategyName, | ||
RebuildHook = RebuildHook, | ||
Paths = Paths | ||
}; | ||
} |
150 changes: 75 additions & 75 deletions
150
src/Kentico.Xperience.Lucene.Admin/UIPages/BaseIndexEditPage.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,75 +1,75 @@ | ||
using System.Text; | ||
|
||
using Kentico.Xperience.Admin.Base; | ||
using Kentico.Xperience.Admin.Base.Forms; | ||
using Kentico.Xperience.Lucene.Core.Indexing; | ||
|
||
using IFormItemCollectionProvider = Kentico.Xperience.Admin.Base.Forms.Internal.IFormItemCollectionProvider; | ||
|
||
namespace Kentico.Xperience.Lucene.Admin; | ||
|
||
internal abstract class BaseIndexEditPage : ModelEditPage<LuceneConfigurationModel> | ||
{ | ||
protected readonly ILuceneConfigurationStorageService StorageService; | ||
|
||
private readonly ILuceneIndexManager indexManager; | ||
|
||
protected BaseIndexEditPage( | ||
IFormItemCollectionProvider formItemCollectionProvider, | ||
IFormDataBinder formDataBinder, | ||
ILuceneConfigurationStorageService storageService, | ||
ILuceneIndexManager indexManager) | ||
: base(formItemCollectionProvider, formDataBinder) | ||
{ | ||
this.indexManager = indexManager; | ||
StorageService = storageService; | ||
} | ||
|
||
protected async Task<IndexModificationResult> ValidateAndProcess(LuceneConfigurationModel configuration) | ||
{ | ||
configuration.IndexName = RemoveWhitespacesUsingStringBuilder(configuration.IndexName ?? ""); | ||
|
||
if (StorageService.GetIndexIds().Exists(x => x == configuration.Id)) | ||
{ | ||
bool edited = await StorageService.TryEditIndexAsync(configuration.ToLuceneModel()); | ||
|
||
if (edited) | ||
{ | ||
return IndexModificationResult.Success; | ||
} | ||
|
||
return IndexModificationResult.Failure; | ||
} | ||
else | ||
{ | ||
if (!string.IsNullOrWhiteSpace(configuration.IndexName)) | ||
{ | ||
indexManager.AddIndex(configuration.ToLuceneModel()); | ||
|
||
return IndexModificationResult.Success; | ||
} | ||
|
||
return IndexModificationResult.Failure; | ||
} | ||
} | ||
|
||
protected static string RemoveWhitespacesUsingStringBuilder(string source) | ||
{ | ||
var builder = new StringBuilder(source.Length); | ||
for (int i = 0; i < source.Length; i++) | ||
{ | ||
char c = source[i]; | ||
if (!char.IsWhiteSpace(c)) | ||
{ | ||
builder.Append(c); | ||
} | ||
} | ||
return source.Length == builder.Length ? source : builder.ToString(); | ||
} | ||
} | ||
|
||
internal enum IndexModificationResult | ||
{ | ||
Success, | ||
Failure | ||
} | ||
using System.Text; | ||
|
||
using Kentico.Xperience.Admin.Base; | ||
using Kentico.Xperience.Admin.Base.Forms; | ||
using Kentico.Xperience.Lucene.Core.Indexing; | ||
|
||
using IFormItemCollectionProvider = Kentico.Xperience.Admin.Base.Forms.Internal.IFormItemCollectionProvider; | ||
|
||
namespace Kentico.Xperience.Lucene.Admin; | ||
|
||
internal abstract class BaseIndexEditPage : ModelEditPage<LuceneConfigurationModel> | ||
{ | ||
protected readonly ILuceneConfigurationStorageService StorageService; | ||
|
||
private readonly ILuceneIndexManager indexManager; | ||
|
||
protected BaseIndexEditPage( | ||
IFormItemCollectionProvider formItemCollectionProvider, | ||
IFormDataBinder formDataBinder, | ||
ILuceneConfigurationStorageService storageService, | ||
ILuceneIndexManager indexManager) | ||
: base(formItemCollectionProvider, formDataBinder) | ||
{ | ||
this.indexManager = indexManager; | ||
StorageService = storageService; | ||
} | ||
|
||
protected async Task<IndexModificationResult> ValidateAndProcess(LuceneConfigurationModel configuration) | ||
{ | ||
configuration.IndexName = RemoveWhitespacesUsingStringBuilder(configuration.IndexName ?? ""); | ||
|
||
if (StorageService.GetIndexIds().Exists(x => x == configuration.Id)) | ||
{ | ||
bool edited = await StorageService.TryEditIndexAsync(configuration.ToLuceneModel()); | ||
|
||
if (edited) | ||
{ | ||
return IndexModificationResult.Success; | ||
} | ||
|
||
return IndexModificationResult.Failure; | ||
} | ||
else | ||
{ | ||
if (!string.IsNullOrWhiteSpace(configuration.IndexName)) | ||
{ | ||
indexManager.AddIndex(configuration.ToLuceneModel()); | ||
|
||
return IndexModificationResult.Success; | ||
} | ||
|
||
return IndexModificationResult.Failure; | ||
} | ||
} | ||
|
||
protected static string RemoveWhitespacesUsingStringBuilder(string source) | ||
{ | ||
var builder = new StringBuilder(source.Length); | ||
for (int i = 0; i < source.Length; i++) | ||
{ | ||
char c = source[i]; | ||
if (!char.IsWhiteSpace(c)) | ||
{ | ||
builder.Append(c); | ||
} | ||
} | ||
return source.Length == builder.Length ? source : builder.ToString(); | ||
} | ||
} | ||
|
||
internal enum IndexModificationResult | ||
{ | ||
Success, | ||
Failure | ||
} |
Oops, something went wrong.