-
Notifications
You must be signed in to change notification settings - Fork 455
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9987a06
commit 07816ae
Showing
40 changed files
with
1,440 additions
and
17 deletions.
There are no files selected for viewing
62 changes: 62 additions & 0 deletions
62
backend/src/Squidex.Domain.Apps.Entities.MongoDb/Contents/IndexParser.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// ========================================================================== | ||
// Squidex Headless CMS | ||
// ========================================================================== | ||
// Copyright (c) Squidex UG (haftungsbeschraenkt) | ||
// All rights reserved. Licensed under the MIT license. | ||
// ========================================================================== | ||
|
||
using System.Diagnostics.CodeAnalysis; | ||
using MongoDB.Bson; | ||
using Squidex.Domain.Apps.Entities.MongoDb.Contents.Operations; | ||
using Squidex.Infrastructure.Queries; | ||
using Squidex.Infrastructure.States; | ||
|
||
namespace Squidex.Domain.Apps.Entities.MongoDb.Contents; | ||
|
||
public static class IndexParser | ||
{ | ||
public static bool TryParse(BsonDocument source, string prefix, [MaybeNullWhen(false)] out IndexDefinition index) | ||
{ | ||
index = null!; | ||
|
||
if (!source.TryGetValue("name", out var name) || name.BsonType != BsonType.String) | ||
{ | ||
return false; | ||
} | ||
|
||
if (!name.AsString.StartsWith(prefix, StringComparison.Ordinal)) | ||
{ | ||
return false; | ||
} | ||
|
||
if (!source.TryGetValue("key", out var keys) || keys.BsonType != BsonType.Document) | ||
{ | ||
return false; | ||
} | ||
|
||
var definition = new IndexDefinition(); | ||
foreach (var property in keys.AsBsonDocument) | ||
{ | ||
if (property.Value.BsonType != BsonType.Int32) | ||
{ | ||
return false; | ||
} | ||
|
||
var fieldName = Adapt.MapPathReverse(property.Name).ToString(); | ||
|
||
var order = property.Value.AsInt32 < 0 ? | ||
SortOrder.Descending : | ||
SortOrder.Ascending; | ||
|
||
definition.Add(new IndexField(fieldName, order)); | ||
} | ||
|
||
if (definition.Count == 0) | ||
{ | ||
return false; | ||
} | ||
|
||
index = definition; | ||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.