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

Display indexed content fields in administration #9

Merged
merged 3 commits into from
Aug 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 1 addition & 12 deletions src/Kentico.Xperience.Lucene/Admin/UIPages/IndexListing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,7 @@ public override Task ConfigurePage()

PageConfiguration.ColumnConfigurations
.AddColumn(nameof(LuceneIndexStatisticsViewModel.Name), LocalizationService.GetString("integrations.lucene.listing.columns.name"), defaultSortDirection: SortTypeEnum.Asc, searchable: true)
.AddColumn(nameof(LuceneIndexStatisticsViewModel.Entries), LocalizationService.GetString("integrations.lucene.listing.columns.entries"))
//.AddColumn(nameof(LuceneIndexStatisticsViewModel.LastBuildTimes), LocalizationService.GetString("integrations.lucene.listing.columns.buildtime"))
.AddColumn(nameof(LuceneIndexStatisticsViewModel.UpdatedAt), LocalizationService.GetString("integrations.lucene.listing.columns.updatedat"));
.AddColumn(nameof(LuceneIndexStatisticsViewModel.Entries), LocalizationService.GetString("integrations.lucene.listing.columns.entries"));

PageConfiguration.TableActions.AddCommand(LocalizationService.GetString("integrations.lucene.listing.commands.rebuild"), nameof(Rebuild), Icons.RotateRight);

Expand Down Expand Up @@ -185,7 +183,6 @@ private static IEnumerable<LuceneIndexStatisticsViewModel> DoSearch(IEnumerable<
return statistics.Where(stat => stat.Name?.Contains(searchTerm, StringComparison.OrdinalIgnoreCase) ?? false);
}


private Row GetRow(LuceneIndexStatisticsViewModel statistics)
{
var luceneIndex = statistics.Name != null ? IndexStore.Instance.GetIndex(statistics.Name) : null;
Expand All @@ -208,14 +205,6 @@ private Row GetRow(LuceneIndexStatisticsViewModel statistics)
{
Value = statistics.Entries.ToString()
},
//new StringCell
//{
// Value = statistics.LastBuildTimes.ToString()
//},
new StringCell
{
Value = statistics.UpdatedAt.ToString()
},
new ActionCell
{
Actions = new List<Action>
Expand Down
72 changes: 48 additions & 24 deletions src/Kentico.Xperience.Lucene/Admin/UIPages/IndexedContent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,14 +111,12 @@ public override Task<PageValidationResult> ValidatePage()
};


private static Row GetProperty(PropertyInfo property)
private Row GetProperty(PropertyInfo property)
{
//var isSearchable = Attribute.IsDefined(property, typeof(SearchableAttribute));
//var isRetrievable = Attribute.IsDefined(property, typeof(RetrievableAttribute));
//var isFacetable = Attribute.IsDefined(property, typeof(FacetableAttribute));
// TODO: read from attributes
bool isSearchable = false;
bool isRetrievable = false;
var fieldAttribute = property.GetCustomAttributes<BaseFieldAttribute>(false).FirstOrDefault();
bool isSearchable = fieldAttribute != null;
string fieldType = fieldAttribute != null ? GetFieldType(fieldAttribute) : "-";
bool isStored = fieldAttribute?.Store ?? false;
bool hasSources = Attribute.IsDefined(property, typeof(SourceAttribute));
bool hasUrls = Attribute.IsDefined(property, typeof(MediaUrlsAttribute));
return new Row
Expand All @@ -142,19 +140,14 @@ private static Row GetProperty(PropertyInfo property)
Name = NamedComponentCellComponentNames.SIMPLE_STATUS_COMPONENT,
ComponentProps = new SimpleStatusNamedComponentCellProps
{
IconName = GetIconName(isRetrievable),
IconColor = GetIconColor(isRetrievable)
IconName = GetIconName(isStored),
IconColor = GetIconColor(isStored)
}
},
//new NamedComponentCell
//{
// Name = NamedComponentCellComponentNames.SIMPLE_STATUS_COMPONENT,
// ComponentProps = new SimpleStatusNamedComponentCellProps
// {
// IconName = GetIconName(isFacetable),
// IconColor = GetIconColor(isFacetable)
// }
//},
new StringCell
{
Value= fieldType,
},
new NamedComponentCell
{
Name = NamedComponentCellComponentNames.SIMPLE_STATUS_COMPONENT,
Expand All @@ -177,6 +170,37 @@ private static Row GetProperty(PropertyInfo property)
};
}

private string GetFieldType(BaseFieldAttribute attribute)
{
if (attribute is TextFieldAttribute)
{
return LocalizationService.GetString("integrations.lucene.content.fieldType.text");
}
else if (attribute is StringFieldAttribute)
{
return LocalizationService.GetString("integrations.lucene.content.fieldType.string");
}
else if (attribute is Int32FieldAttribute)
{
return LocalizationService.GetString("integrations.lucene.content.fieldType.int32");
}
else if (attribute is Int64FieldAttribute)
{
return LocalizationService.GetString("integrations.lucene.content.fieldType.int64");
}
else if (attribute is SingleFieldAttribute)
{
return LocalizationService.GetString("integrations.lucene.content.fieldType.single");
}
else if (attribute is DoubleFieldAttribute)
{
return LocalizationService.GetString("integrations.lucene.content.fieldType.double");
}
else
{
return "-";
}
}

private Column[] GetPropertyColumns() => new Column[] {
new Column
Expand All @@ -191,14 +215,14 @@ private static Row GetProperty(PropertyInfo property)
},
new Column
{
Caption = LocalizationService.GetString("integrations.lucene.content.columns.retrievable"),
Caption = LocalizationService.GetString("integrations.lucene.content.columns.stored"),
ContentType = ColumnContentType.Component
},
new Column
{
Caption = LocalizationService.GetString("integrations.lucene.content.columns.fieldType"),
ContentType = ColumnContentType.Component
},
//new Column
//{
// Caption = LocalizationService.GetString("integrations.lucene.content.columns.facetable"),
// ContentType = ColumnContentType.Component
//},
new Column
{
Caption = LocalizationService.GetString("integrations.lucene.content.columns.source"),
Expand Down
17 changes: 1 addition & 16 deletions src/Kentico.Xperience.Lucene/IndexStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ public void AddIndex(LuceneIndex index)
throw new InvalidOperationException($"Attempted to register Lucene index with name '{index.IndexName},' but it is already registered.");
}

//AddIncludedPaths(index);

index.Identifier = registeredIndexes.Count + 1;
registeredIndexes.Add(index);
}
Expand Down Expand Up @@ -94,24 +92,11 @@ public void AddCrawler(string crawlerId)
/// </summary>
public IEnumerable<string> GetAllCrawlers() => registeredCrawlers;


//private static void AddIncludedPaths(LuceneIndex index)
//{
// var paths = index.LuceneSearchModelType.GetCustomAttributes<IncludedPathAttribute>(false);
// foreach (var path in paths)
// {
// path.Identifier = Guid.NewGuid().ToString();
// }

// index.IncludedPaths = paths;
//}


internal void ClearCrawlers() => registeredCrawlers.Clear();


internal void ClearIndexes() => registeredIndexes.Clear();


internal LuceneIndex? GetIndex(int id) => registeredIndexes.FirstOrDefault(i => i.Identifier == id);
internal LuceneIndex? GetIndex(int id) => registeredIndexes.Find(i => i.Identifier == id);
}
1 change: 0 additions & 1 deletion src/Kentico.Xperience.Lucene/LuceneSearchModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ protected override void OnInit()
WorkflowEvents.Publish.After += HandleWorkflowEvent;
WorkflowEvents.Archive.Before += HandleWorkflowEvent;
RequestEvents.RunEndRequestTasks.Execute += (sender, eventArgs) => LuceneQueueWorker.Current.EnsureRunningThread();
//RequestEvents.RunEndRequestTasks.Execute += (sender, eventArgs) => LuceneCrawlerQueueWorker.Current.EnsureRunningThread();
}


Expand Down
24 changes: 24 additions & 0 deletions src/Kentico.Xperience.Lucene/Resources/LuceneResources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,9 @@
<data name="integrations.lucene.content.columns.facetable" xml:space="preserve">
<value>Facetable</value>
</data>
<data name="integrations.lucene.content.columns.fieldType" xml:space="preserve">
<value>Field type</value>
</data>
<data name="integrations.lucene.content.columns.pagetypes" xml:space="preserve">
<value>Content types</value>
</data>
Expand All @@ -147,9 +150,30 @@
<data name="integrations.lucene.content.columns.source" xml:space="preserve">
<value>Source</value>
</data>
<data name="integrations.lucene.content.columns.stored" xml:space="preserve">
<value>Stored</value>
</data>
<data name="integrations.lucene.content.columns.url" xml:space="preserve">
<value>URL</value>
</data>
<data name="integrations.lucene.content.fieldType.double" xml:space="preserve">
<value>Double</value>
</data>
<data name="integrations.lucene.content.fieldType.int32" xml:space="preserve">
<value>Int32</value>
</data>
<data name="integrations.lucene.content.fieldType.int64" xml:space="preserve">
<value>Int64</value>
</data>
<data name="integrations.lucene.content.fieldType.single" xml:space="preserve">
<value>Single</value>
</data>
<data name="integrations.lucene.content.fieldType.string" xml:space="preserve">
<value>String</value>
</data>
<data name="integrations.lucene.content.fieldType.text" xml:space="preserve">
<value>Text (tokenized string)</value>
</data>
<data name="integrations.lucene.content.multipletypes" xml:space="preserve">
<value>{0} content types</value>
</data>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using CMS.Core;
using CMS.DocumentEngine;
using CMS.Helpers;
using CMS.Helpers.Caching.Abstractions;

using Kentico.Content.Web.Mvc;
Expand All @@ -21,9 +20,8 @@
private readonly ILuceneSearchModelToDocumentMapper luceneSearchModelToDocumentMapper;

private readonly ICacheAccessor cacheAccessor;
private readonly IEventLogService eventLogService;

Check warning on line 23 in src/Kentico.Xperience.Lucene/Services/Implementations/DefaultLuceneClient.cs

View workflow job for this annotation

GitHub Actions / build

Remove this unread private field 'eventLogService' or refactor the code to use its value.
private readonly IPageRetriever pageRetriever;
private readonly IProgressiveCache progressiveCache;

internal const string CACHEKEY_STATISTICS = "Lucene|ListIndices";

Expand All @@ -34,14 +32,12 @@
ICacheAccessor cacheAccessor,
IEventLogService eventLogService,
IPageRetriever pageRetriever,
IProgressiveCache progressiveCache,
ILuceneIndexService luceneIndexService,
ILuceneSearchModelToDocumentMapper luceneSearchModelToDocumentMapper)
{
this.cacheAccessor = cacheAccessor;
this.eventLogService = eventLogService;
this.pageRetriever = pageRetriever;
this.progressiveCache = progressiveCache;
this.luceneIndexService = luceneIndexService;
this.luceneSearchModelToDocumentMapper = luceneSearchModelToDocumentMapper;
}
Expand All @@ -64,7 +60,7 @@


/// <inheritdoc/>
public async Task<ICollection<LuceneIndexStatisticsViewModel>> GetStatistics(CancellationToken cancellationToken) =>

Check warning on line 63 in src/Kentico.Xperience.Lucene/Services/Implementations/DefaultLuceneClient.cs

View workflow job for this annotation

GitHub Actions / build

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.
IndexStore.Instance.GetAllIndexes().Select(i =>
{
var statistics = luceneIndexService.UseSearcher(i, s => new LuceneIndexStatisticsViewModel()
Expand Down Expand Up @@ -107,7 +103,7 @@
return UpsertRecordsInternal(dataObjects, indexName);
}

private async Task<int> DeleteRecordsInternal(IEnumerable<string> objectIds, string indexName)

Check warning on line 106 in src/Kentico.Xperience.Lucene/Services/Implementations/DefaultLuceneClient.cs

View workflow job for this annotation

GitHub Actions / build

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.
{
var index = IndexStore.Instance.GetIndex(indexName);
if (index != null)
Expand All @@ -120,7 +116,7 @@
var termQuery = new TermQuery(new Term(nameof(LuceneSearchModel.ObjectID), objectId));
booleanQuery.Add(termQuery, Occur.SHOULD); // Match any of the object IDs
}
// todo use batches

Check warning on line 119 in src/Kentico.Xperience.Lucene/Services/Implementations/DefaultLuceneClient.cs

View workflow job for this annotation

GitHub Actions / build

Complete the task associated to this 'TODO' comment.
writer.DeleteDocuments(booleanQuery);
return "OK";
});
Expand Down Expand Up @@ -161,7 +157,7 @@
indexedNodes.ForEach(node => LuceneQueueWorker.EnqueueLuceneQueueItem(new LuceneQueueItem(node, LuceneTaskType.CREATE, luceneIndex.IndexName)));
}

private async Task<int> UpsertRecordsInternal(IEnumerable<LuceneSearchModel> dataObjects, string indexName)

Check warning on line 160 in src/Kentico.Xperience.Lucene/Services/Implementations/DefaultLuceneClient.cs

View workflow job for this annotation

GitHub Actions / build

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.
{
var index = IndexStore.Instance.GetIndex(indexName);
if (index != null)
Expand Down
Loading