diff --git a/src/Raven.Server/Documents/Indexes/Auto/IndexSearchEngineHelper.cs b/src/Raven.Server/Documents/Indexes/Auto/IndexSearchEngineHelper.cs new file mode 100644 index 00000000000..4d9b870312b --- /dev/null +++ b/src/Raven.Server/Documents/Indexes/Auto/IndexSearchEngineHelper.cs @@ -0,0 +1,28 @@ +using System.Linq; +using Raven.Client.Documents.Indexes; +using Raven.Server.Documents.Queries; + +namespace Raven.Server.Documents.Indexes.Auto; + +public static class IndexSearchEngineHelper +{ + public static SearchEngineType GetSearchEngineType(IndexQueryServerSide query, SearchEngineType defaultSearchEngineType) + { + if (query.Metadata.HasVectorSearch) + return SearchEngineType.Corax; + + return defaultSearchEngineType; + } + + public static SearchEngineType GetSearchEngineType(Index index) + { + return index.Type.IsAuto() switch + { + // We only support Vectors in Corax, so if an auto-index is using it, let's already set it up as such, regardless + // of what type of default storage engine is configured. + true when index.Definition.IndexFields.Any(x=> x.Value.Vector != null) => SearchEngineType.Corax, + true => index.Configuration.AutoIndexingEngineType, + false => index.Configuration.StaticIndexingEngineType + }; + } +} diff --git a/src/Raven.Server/Documents/Indexes/IndexStorage.cs b/src/Raven.Server/Documents/Indexes/IndexStorage.cs index 22d67299885..8880f4978ef 100644 --- a/src/Raven.Server/Documents/Indexes/IndexStorage.cs +++ b/src/Raven.Server/Documents/Indexes/IndexStorage.cs @@ -8,6 +8,7 @@ using Raven.Client.Util; using Raven.Server.Config; using Raven.Server.Config.Categories; +using Raven.Server.Documents.Indexes.Auto; using Raven.Server.Documents.Indexes.Static; using Raven.Server.Exceptions; using Raven.Server.Indexing; @@ -190,14 +191,7 @@ void PersistSearchEngine(Tree configurationTree) string configurationKey = nameof(SearchEngineType); string configurationName = _index.Type.IsAuto() ? RavenConfiguration.GetKey(x => x.Indexing.AutoIndexingEngineType) : RavenConfiguration.GetKey(x => x.Indexing.StaticIndexingEngineType); - SearchEngineType defaultEngineType = _index.Type.IsAuto() switch - { - // We only support Vectors in Corax, so if an auto-index is using it, let's already set it up as such, regardless - // of what type of default storage engine is configured. - true when _index.Definition.IndexFields.Any(x=> x.Value.Vector != null) => SearchEngineType.Corax, - true => _index.Configuration.AutoIndexingEngineType, - false => _index.Configuration.StaticIndexingEngineType - }; + SearchEngineType defaultEngineType = IndexSearchEngineHelper.GetSearchEngineType(_index); if (defaultEngineType == SearchEngineType.None) throw new InvalidDataException($"Default search engine is {SearchEngineType.None}. Please set {configurationName}."); diff --git a/src/Raven.Server/Documents/Queries/Dynamic/DynamicQueryMapping.cs b/src/Raven.Server/Documents/Queries/Dynamic/DynamicQueryMapping.cs index 1b418dc2ddc..b9ee07278a1 100644 --- a/src/Raven.Server/Documents/Queries/Dynamic/DynamicQueryMapping.cs +++ b/src/Raven.Server/Documents/Queries/Dynamic/DynamicQueryMapping.cs @@ -216,11 +216,8 @@ public static DynamicQueryMapping Create(IndexQueryServerSide query, SearchEngin var result = new DynamicQueryMapping { ForCollection = query.Metadata.CollectionName, - SearchEngineType = defaultSearchEngineType + SearchEngineType = IndexSearchEngineHelper.GetSearchEngineType(query, defaultSearchEngineType) }; - - if (query.Metadata.HasVectorSearch) - result.SearchEngineType = SearchEngineType.Corax; var mapFields = new Dictionary(StringComparer.Ordinal);