Skip to content

Commit

Permalink
RavenDB-23361 Added helper for determining search engine type
Browse files Browse the repository at this point in the history
  • Loading branch information
Lwiel authored and ppekrol committed Dec 20, 2024
1 parent 9948890 commit 75b89b1
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 12 deletions.
28 changes: 28 additions & 0 deletions src/Raven.Server/Documents/Indexes/Auto/IndexSearchEngineHelper.cs
Original file line number Diff line number Diff line change
@@ -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
};
}
}
10 changes: 2 additions & 8 deletions src/Raven.Server/Documents/Indexes/IndexStorage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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}.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, DynamicQueryMappingItem>(StringComparer.Ordinal);

Expand Down

0 comments on commit 75b89b1

Please sign in to comment.