If using a query in the data source field of a rendering on a regular (non-SXA) site, the data source might fail to be resolved with an error in the search log files on the Content Delivery instance:
ERROR Solr Error : ["undefined field query"] - Query attempted: <Sitecore Query syntax>
The issue occurs because the Sitecore Query syntax cannot be used for rendering data sources on non-SXA sites.
To resolve the issue, consider one of the following options:
Note: The solution provided in this article does not imply adding support for the Sitecore Query syntax. It prevents attempts to resolve data sources using the search indexes if the Sitecore Query syntax has been applied.
Alternatively, consider the following options:
SELECT [ItemId] ,[Language] ,[FieldId] ,[Value] FROM [dbo].[Fields] WHERE (FieldId = '{F1A1FE9E-A60C-4DDB-A3A0-BB5B29FE732E}' OR FieldId = '{04BF00DB-F5FB-41F7-8AB7-22408372A981}') AND ([Value] like '%ds="query%')
using Sitecore.Pipelines.ParseDataSource; using System; using System.Linq; namespace Sitecore.ContentSearch.Client.Pipelines.ParseDataSource { public class AbortIfDatasourceIsPrefixed { private readonly string[] _prefixes = { DatasourcePrefixes.QueryPrefix, DatasourcePrefixes.LocalPrefix, DatasourcePrefixes.PageRelativePrefix, DatasourcePrefixes.FieldPrefix, DatasourcePrefixes.CodePrefix, }; public void Process([NotNull] ParseDataSourceArgs args) { if (IsDataSourcePrefixed(args.DataSource)) { args.AbortPipeline(); } } protected virtual bool IsDataSourcePrefixed(string dataSource) { return dataSource.Length > 1 && dataSource.Contains(":") && _prefixes.Any(s => dataSource.StartsWith(s, StringComparison.OrdinalIgnoreCase)); } internal static class DatasourcePrefixes { public const string PageRelativePrefix = "page:"; public const string LocalPrefix = "local:"; public const string FieldPrefix = "field:"; public const string CodePrefix = "code:"; public const string QueryPrefix = "query:"; } } }
<?xml version="1.0" encoding="utf-8"?> <configuration xmlns:patch="http://www.sitecore.net/xmlconfig/" xmlns:role="http://www.sitecore.net/xmlconfig/role/"> <sitecore role:require="Standalone or ContentManagement or ContentDelivery"> <pipelines> <parseDataSource> <processor type="Sitecore.ContentSearch.Client.Pipelines.ParseDataSource.CustomProcessor, Custom.Assembly" patch:before="processor[@type='Sitecore.ContentSearch.Client.Pipelines.ParseDataSource.GetDataSourceItemByQuery, Sitecore.ContentSearch.Client']" /> </parseDataSource> </pipelines> </sitecore> </configuration>