From 278502e9fb202f4a07ab648f7b3445972c598e5f Mon Sep 17 00:00:00 2001 From: Jasmin Savard Date: Sun, 23 Oct 2022 13:38:28 -0400 Subject: [PATCH 1/3] Indexing Latest not working as intended --- .../OrchardCore.Search.Lucene/Services/LuceneIndexingService.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OrchardCore.Modules/OrchardCore.Search.Lucene/Services/LuceneIndexingService.cs b/src/OrchardCore.Modules/OrchardCore.Search.Lucene/Services/LuceneIndexingService.cs index 75e353ff60f..c656ea45892 100644 --- a/src/OrchardCore.Modules/OrchardCore.Search.Lucene/Services/LuceneIndexingService.cs +++ b/src/OrchardCore.Modules/OrchardCore.Search.Lucene/Services/LuceneIndexingService.cs @@ -129,7 +129,7 @@ await shellScope.UsingAsync(async scope => var allPublishedContentItems = await contentManager.GetAsync(updatedContentItemIds); allPublished = allPublishedContentItems.DistinctBy(x => x.ContentItemId).ToDictionary(k => k.ContentItemId, v => v); var allLatestContentItems = await contentManager.GetAsync(updatedContentItemIds, latest: true); - allLatest = allLatestContentItems.DistinctBy(x => x.ContentItemId).ToDictionary(k => k.ContentItemVersionId, v => v); + allLatest = allLatestContentItems.DistinctBy(x => x.ContentItemId).ToDictionary(k => k.ContentItemId, v => v); // Group all DocumentIndex by index to batch update them var updatedDocumentsByIndex = new Dictionary>(); From 894e5ce20f40166391e812846b86c7e4da0e9137 Mon Sep 17 00:00:00 2001 From: Jasmin Savard Date: Sun, 23 Oct 2022 14:01:04 -0400 Subject: [PATCH 2/3] Fix draft pruning issue --- .../Services/LuceneIndexManager.cs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/OrchardCore.Modules/OrchardCore.Search.Lucene/Services/LuceneIndexManager.cs b/src/OrchardCore.Modules/OrchardCore.Search.Lucene/Services/LuceneIndexManager.cs index d03ea9934ec..316e36bb64b 100644 --- a/src/OrchardCore.Modules/OrchardCore.Search.Lucene/Services/LuceneIndexManager.cs +++ b/src/OrchardCore.Modules/OrchardCore.Search.Lucene/Services/LuceneIndexManager.cs @@ -199,14 +199,17 @@ private Document CreateLuceneDocument(DocumentIndex documentIndex, LuceneIndexSe var doc = new Document { // Always store the content item id and version id - new StoredField("ContentItemId", documentIndex.ContentItemId.ToString()), - new StoredField("ContentItemVersionId", documentIndex.ContentItemVersionId.ToString()) + // These fields need to be indexed as a StringField because it needs to be searchable for the writer.DeleteDocuments method. + // Else it won't be able to prune oldest draft from the indexes. + // Maybe eventually find a way to remove a document from a StoredDocument. + new StringField("ContentItemId", documentIndex.ContentItemId.ToString(), Field.Store.YES), + new StringField("ContentItemVersionId", documentIndex.ContentItemVersionId.ToString(), Field.Store.YES) }; if (indexSettings.StoreSourceData) { - doc.Add(new StoredField(IndexingConstants.SourceKey + "ContentItemId", documentIndex.ContentItemId.ToString())); - doc.Add(new StoredField(IndexingConstants.SourceKey + "ContentItemVersionId", documentIndex.ContentItemVersionId.ToString())); + doc.Add(new StringField(IndexingConstants.SourceKey + "ContentItemId", documentIndex.ContentItemId.ToString(), Field.Store.YES)); + doc.Add(new StringField(IndexingConstants.SourceKey + "ContentItemVersionId", documentIndex.ContentItemVersionId.ToString(), Field.Store.YES)); } foreach (var entry in documentIndex.Entries) From 966e37be63b42700fb0bdf1f85a8e2710ecb8f23 Mon Sep 17 00:00:00 2001 From: Jasmin Savard Date: Sun, 23 Oct 2022 14:15:01 -0400 Subject: [PATCH 3/3] keep it as StoredField for source fields --- .../OrchardCore.Search.Lucene/Services/LuceneIndexManager.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/OrchardCore.Modules/OrchardCore.Search.Lucene/Services/LuceneIndexManager.cs b/src/OrchardCore.Modules/OrchardCore.Search.Lucene/Services/LuceneIndexManager.cs index 316e36bb64b..13292f5ebf4 100644 --- a/src/OrchardCore.Modules/OrchardCore.Search.Lucene/Services/LuceneIndexManager.cs +++ b/src/OrchardCore.Modules/OrchardCore.Search.Lucene/Services/LuceneIndexManager.cs @@ -208,8 +208,8 @@ private Document CreateLuceneDocument(DocumentIndex documentIndex, LuceneIndexSe if (indexSettings.StoreSourceData) { - doc.Add(new StringField(IndexingConstants.SourceKey + "ContentItemId", documentIndex.ContentItemId.ToString(), Field.Store.YES)); - doc.Add(new StringField(IndexingConstants.SourceKey + "ContentItemVersionId", documentIndex.ContentItemVersionId.ToString(), Field.Store.YES)); + doc.Add(new StoredField(IndexingConstants.SourceKey + "ContentItemId", documentIndex.ContentItemId.ToString())); + doc.Add(new StoredField(IndexingConstants.SourceKey + "ContentItemVersionId", documentIndex.ContentItemVersionId.ToString())); } foreach (var entry in documentIndex.Entries)