OrchardCMS / OrchardCore

Orchard Core is an open-source modular and multi-tenant application framework built with ASP.NET Core, and a content management system (CMS) built on top of that framework.
https://orchardcore.net
BSD 3-Clause "New" or "Revised" License
7.45k stars 2.41k forks source link

/api/lucene/documents endpoint fails when a multiselect TaxonomyField is part of a ContentType and the selected taxonomy values are stored in lucene #7665

Open issue-media-group opened 4 years ago

issue-media-group commented 4 years ago

To replicate:

Import the attached recipe which creates:

Hitting the lucene document API /api/lucene/documents?indexName=TestLuceneDocumentIndex&query={%20"query":%20{%20"match_all":%20{}%20}%20}

results in the exception below.

This can happen if the "Test Lucene API" content item has either 1) multiple values selected for "Tag" or 2) Any value is selected for "Article Type".

System.ArgumentException: Can not add property TestLuceneAPI.Tags to Newtonsoft.Json.Linq.JObject. Property with the same name already exists on object.
   at Newtonsoft.Json.Linq.JObject.ValidateToken(JToken o, JToken existing)
   at Newtonsoft.Json.Linq.JContainer.InsertItem(Int32 index, JToken item, Boolean skipParentCheck)
   at Newtonsoft.Json.Linq.JContainer.AddInternal(Int32 index, Object content, Boolean skipParentCheck)
   at OrchardCore.Lucene.LuceneQuerySource.<>c__DisplayClass11_0.<<ExecuteQueryAsync>b__0>d.MoveNext() in /home/runner/work/OrchardCore/OrchardCore/src/OrchardCore.Modules/OrchardCore.Lucene/Services/LuceneQuerySource.cs:line 100
--- End of stack trace from previous location where exception was thrown ---
   at OrchardCore.Lucene.LuceneIndexManager.SearchAsync(String indexName, Func`2 searcher) in /home/runner/work/OrchardCore/OrchardCore/src/OrchardCore.Modules/OrchardCore.Lucene/Services/LuceneIndexManager.cs:line 152
   at OrchardCore.Lucene.LuceneQuerySource.ExecuteQueryAsync(Query query, IDictionary`2 parameters) in /home/runner/work/OrchardCore/OrchardCore/src/OrchardCore.Modules/OrchardCore.Lucene/Services/LuceneQuerySource.cs:line 107
   at OrchardCore.Lucene.Controllers.ApiController.Documents(String indexName, String query, String parameters) in /home/runner/work/OrchardCore/OrchardCore/src/OrchardCore.Modules/OrchardCore.Lucene/Controllers/ApiController.cs:line 76
   at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.TaskOfIActionResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeActionMethodAsync>g__Awaited|12_0(ControllerActionInvoker invoker, ValueTask`1 actionResultValueTask)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeNextActionFilterAsync>g__Awaited|10_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeInnerFilterAsync()
--- End of stack trace from previous location where exception was thrown ---
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResourceFilter>g__Awaited|24_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResourceExecutedContextSealed context)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeFilterPipelineAsync()
--- End of stack trace from previous location where exception was thrown ---
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)
   at Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
   at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
   at SixLabors.ImageSharp.Web.Middleware.ImageSharpMiddleware.Invoke(HttpContext context)
   at OrchardCore.Apis.GraphQL.GraphQLMiddleware.Invoke(HttpContext context, IAuthorizationService authorizationService, IAuthenticationService authenticationService, ISchemaFactory schemaService) in /home/runner/work/OrchardCore/OrchardCore/src/OrchardCore.Modules/OrchardCore.Apis.GraphQL/GraphQLMiddleware.cs:line 69
   at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.ResponseCompression.ResponseCompressionMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Localization.RequestLocalizationMiddleware.Invoke(HttpContext context)
   at OrchardCore.Diagnostics.DiagnosticsStartupFilter.<>c__DisplayClass3_0.<<Configure>b__1>d.MoveNext() in /home/runner/work/OrchardCore/OrchardCore/src/OrchardCore.Modules/OrchardCore.Diagnostics/DiagnosticsStartupFilter.cs:line 47
--- End of stack trace from previous location where exception was thrown ---
   at Microsoft.AspNetCore.Diagnostics.StatusCodePagesMiddleware.Invoke(HttpContext context)
   at OrchardCore.ContentPreview.PreviewStartupFilter.<>c.<<Configure>b__1_1>d.MoveNext() in /home/runner/work/OrchardCore/OrchardCore/src/OrchardCore.Modules/OrchardCore.ContentPreview/PreviewStartupFilter.cs:line 51
--- End of stack trace from previous location where exception was thrown ---
   at OrchardCore.Modules.ModularTenantRouterMiddleware.Invoke(HttpContext httpContext) in /home/runner/work/OrchardCore/OrchardCore/src/OrchardCore/OrchardCore/Modules/ModularTenantRouterMiddleware.cs:line 64
   at OrchardCore.Environment.Shell.Scope.ShellScope.UsingAsync(Func`2 execute, Boolean activateShell) in /home/runner/work/OrchardCore/OrchardCore/src/OrchardCore/OrchardCore.Abstractions/Shell/Scope/ShellScope.cs:line 243
   at OrchardCore.Modules.ModularTenantContainerMiddleware.Invoke(HttpContext httpContext) in /home/runner/work/OrchardCore/OrchardCore/src/OrchardCore/OrchardCore/Modules/ModularTenantContainerMiddleware.cs:line 61
   at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)
issue-media-group commented 3 years ago

The error appeared (in OrchardCore.Lucene.LuceneQuerySource.cs for /api/lucene/document...) when a lucene document had multiple fields with the same key, i.e. for any multi-valued field. Adding a JProperty with a duplicate property name cuased the exception.

issue-media-group commented 3 years ago

A potential fix for this problem is in pull request #7825