From 5a1fc848e48cb80d11ce94c99ffc07c58c12c691 Mon Sep 17 00:00:00 2001 From: Marc Goodson Date: Thu, 27 Apr 2023 21:31:53 +0100 Subject: [PATCH] path and __Published are required to be in the index if you want to use ContentSetValueValidator This code checks path and published when deciding whether to filter the document without them nothing is indexed! --- .../CustomIndexing/ConfigureProductIndexOptions.cs | 10 ++++++++-- .../CustomIndexing/ProductIndexValueSetBuilder.cs | 8 +++++++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/Umbraco.Docs.Samples.Web/CustomIndexing/ConfigureProductIndexOptions.cs b/Umbraco.Docs.Samples.Web/CustomIndexing/ConfigureProductIndexOptions.cs index 3722e7b..4caff1c 100644 --- a/Umbraco.Docs.Samples.Web/CustomIndexing/ConfigureProductIndexOptions.cs +++ b/Umbraco.Docs.Samples.Web/CustomIndexing/ConfigureProductIndexOptions.cs @@ -35,12 +35,18 @@ public void Configure(string name, LuceneDirectoryIndexOptions options) options.FieldDefinitions = new( new("id", FieldDefinitionTypes.Integer), - new("name", FieldDefinitionTypes.FullText) + new("name", FieldDefinitionTypes.FullText), + //the examine dashboard uses nodeName in search results + new("nodeName", FieldDefinitionTypes.InvariantCultureIgnoreCase), + //__Published and path both required if using the ContentValueSetValidator + new("__Published", FieldDefinitionTypes.Raw), + new("path",FieldDefinitionTypes.InvariantCultureIgnoreCase) ); options.UnlockIndex = true; - options.Validator = new ContentValueSetValidator(true, false, _publicAccessService, _scopeProvider, includeItemTypes: new[] { "product" }); + //ContentValueSetValidator - requires Path, and ParentId + options.Validator = new ContentValueSetValidator(true,false, _publicAccessService, _scopeProvider, includeItemTypes: new[] { "product" }); if (_settings.Value.LuceneDirectoryFactory == LuceneDirectoryFactory.SyncedTempFileSystemDirectoryFactory) { diff --git a/Umbraco.Docs.Samples.Web/CustomIndexing/ProductIndexValueSetBuilder.cs b/Umbraco.Docs.Samples.Web/CustomIndexing/ProductIndexValueSetBuilder.cs index 336a0c9..362cac0 100644 --- a/Umbraco.Docs.Samples.Web/CustomIndexing/ProductIndexValueSetBuilder.cs +++ b/Umbraco.Docs.Samples.Web/CustomIndexing/ProductIndexValueSetBuilder.cs @@ -1,4 +1,4 @@ -using Examine; +using Examine; using Umbraco.Cms.Core.Models; using Umbraco.Cms.Infrastructure.Examine; @@ -14,6 +14,12 @@ public IEnumerable GetValueSets(params IContent[] contents) { ["name"] = content.Name, ["id"] = content.Id, + // nodeName used in the Examine Dashboard backoffice search results + ["nodeName"] = content.Name, + //__Published and path are required if using core ContentValueSetValidator to apply a Validation option to filter results + ["__Published"] = content.Published ? "y" : "n", + ["path"] = content.Path + }; yield return new ValueSet(content.Id.ToString(), "content",content.ContentType.Alias,indexValues);