Skip to content

Commit

Permalink
Add Azure AI Search (Azure Cognitive Search) Module (OrchardCMS#14925)
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeAlhayek authored and urbanit committed Mar 18, 2024
1 parent 70526ff commit 63c5636
Show file tree
Hide file tree
Showing 104 changed files with 4,430 additions and 236 deletions.
16 changes: 15 additions & 1 deletion OrchardCore.sln
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OrchardCore.Sms.Abstraction
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OrchardCore.Sms", "src\OrchardCore.Modules\OrchardCore.Sms\OrchardCore.Sms.csproj", "{CBF6DB53-FD0C-47F8-9E60-A1D247ACFD05}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OrchardCore.Sms.Core", "src\OrchardCore\OrchardCore.Sms.Core\OrchardCore.Sms.Core.csproj", "{20356393-B16D-466C-8203-877A534E287D}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OrchardCore.Sms.Core", "src\OrchardCore\OrchardCore.Sms.Core\OrchardCore.Sms.Core.csproj", "{20356393-B16D-466C-8203-877A534E287D}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OrchardCore.Search.AzureAI", "src\OrchardCore.Modules\OrchardCore.Search.AzureAI\OrchardCore.Search.AzureAI.csproj", "{5527BACF-FA5D-4617-978B-7EDE8942E6F6}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OrchardCore.Search.AzureAI.Core", "src\OrchardCore\OrchardCore.Search.AzureAI.Core\OrchardCore.Search.AzureAI.Core.csproj", "{E9428DE8-5D81-4359-BF84-31435041FF1A}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -1335,6 +1339,14 @@ Global
{20356393-B16D-466C-8203-877A534E287D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{20356393-B16D-466C-8203-877A534E287D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{20356393-B16D-466C-8203-877A534E287D}.Release|Any CPU.Build.0 = Release|Any CPU
{5527BACF-FA5D-4617-978B-7EDE8942E6F6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5527BACF-FA5D-4617-978B-7EDE8942E6F6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5527BACF-FA5D-4617-978B-7EDE8942E6F6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5527BACF-FA5D-4617-978B-7EDE8942E6F6}.Release|Any CPU.Build.0 = Release|Any CPU
{E9428DE8-5D81-4359-BF84-31435041FF1A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E9428DE8-5D81-4359-BF84-31435041FF1A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E9428DE8-5D81-4359-BF84-31435041FF1A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E9428DE8-5D81-4359-BF84-31435041FF1A}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -1566,6 +1578,8 @@ Global
{2D93F509-1FB3-4E22-92F0-588D0EFBA921} = {F23AC6C2-DE44-4699-999D-3C478EF3D691}
{CBF6DB53-FD0C-47F8-9E60-A1D247ACFD05} = {A066395F-6F73-45DC-B5A6-B4E306110DCE}
{20356393-B16D-466C-8203-877A534E287D} = {F23AC6C2-DE44-4699-999D-3C478EF3D691}
{5527BACF-FA5D-4617-978B-7EDE8942E6F6} = {90030E85-0C4F-456F-B879-443E8A3F220D}
{E9428DE8-5D81-4359-BF84-31435041FF1A} = {F23AC6C2-DE44-4699-999D-3C478EF3D691}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {46A1D25A-78D1-4476-9CBF-25B75E296341}
Expand Down
2 changes: 2 additions & 0 deletions src/OrchardCore.Build/Dependencies.props
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<PackageManagement Include="Azure.Extensions.AspNetCore.Configuration.Secrets" Version="1.3.0" />
<PackageManagement Include="Azure.Extensions.AspNetCore.DataProtection.Blobs" Version="1.3.2" />
<PackageManagement Include="Azure.Identity" Version="1.10.4" />
<PackageManagement Include="Azure.Search.Documents" Version="11.5.1" />
<PackageManagement Include="Azure.Storage.Blobs" Version="12.19.1" />
<PackageManagement Include="BenchmarkDotNet" Version="0.13.11" />
<PackageManagement Include="Castle.Core" Version="5.1.1" />
Expand All @@ -36,6 +37,7 @@
<PackageManagement Include="MailKit" Version="4.3.0" />
<PackageManagement Include="Markdig" Version="0.34.0" />
<PackageManagement Include="MessagePack" Version="2.2.60" />
<PackageManagement Include="Microsoft.Extensions.Azure" Version="1.7.1" />
<PackageManagement Include="Microsoft.Identity.Web" Version="2.16.0" />
<PackageManagement Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageManagement Include="Microsoft.SourceLink.GitHub" Version="8.0.0" />
Expand Down
18 changes: 17 additions & 1 deletion src/OrchardCore.Cms.Web/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,22 @@
// "MaxPagedCount": 500
// }
//},
// Provides Azure AI Search Connection
//"OrchardCore_AzureAISearch": {
// "Endpoint": "",
// "IndexesPrefix": "",
// "Credential": {
// "Key": ""
// }
//},
// "Url": "http://localhost",
// "Ports": [ 9200 ],
// "Username": "admin",
// "Password": "admin",
// "CloudId": "Orchard_Core_deployment:ZWFzdHVzMi5henVyZS5lbGFzdGljLWNsb3VkLmNvbTo0NDMkNmMxZGQ4YzAzN2=",
// "CertificateFingerprint": "75:21:E7:92:8F:D5:7A:27:06:38:8E:A4:35:FE:F5:17:D7:37:F4:DF:F0:9A:D2:C0:C4:B6:FF:EE:D1:EA:2B:A7",
// "EnableApiVersioningHeader": false
//},
// Provides Elasticsearch Connection
//"OrchardCore_Elasticsearch": {
// "ConnectionType": "SingleNodeConnectionPool",
Expand All @@ -143,7 +159,7 @@
// "CloudId": "Orchard_Core_deployment:ZWFzdHVzMi5henVyZS5lbGFzdGljLWNsb3VkLmNvbTo0NDMkNmMxZGQ4YzAzN2=",
// "CertificateFingerprint": "75:21:E7:92:8F:D5:7A:27:06:38:8E:A4:35:FE:F5:17:D7:37:F4:DF:F0:9A:D2:C0:C4:B6:FF:EE:D1:EA:2B:A7",
// "EnableApiVersioningHeader": false
//}
//},
// WARNING: AutoSetup section given as an example for Development only, for Production use "Environment Variables" instead
//"OrchardCore_AutoSetup": {
// "AutoSetupPath": "",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,18 @@ public override Task BuildIndexAsync(NumericField field, BuildFieldIndexContext
var settings = context.ContentPartFieldDefinition.GetSettings<NumericFieldSettings>();
var options = context.Settings.ToOptions();

if (settings.Scale == 0)
var isInteger = settings.Scale == 0;

foreach (var key in context.Keys)
{
foreach (var key in context.Keys)
if (isInteger)
{
context.DocumentIndex.Set(key, (int?)field.Value, options);

continue;
}
}
else
{
foreach (var key in context.Keys)
{
context.DocumentIndex.Set(key, field.Value, options);
}

context.DocumentIndex.Set(key, field.Value, options);
}

return Task.CompletedTask;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public async override Task BuildIndexAsync(MediaField field, BuildFieldIndexCont
var options = context.Settings.ToOptions();
var settings = context.ContentPartFieldDefinition.GetSettings<MediaFieldSettings>();

if (field.Paths?.Length == 0)
if (field.Paths?.Length is null || field.Paths.Length == 0)
{
foreach (var key in context.Keys)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using Microsoft.Extensions.Localization;
using Microsoft.Extensions.Options;
using OrchardCore.DisplayManagement;
using OrchardCore.DisplayManagement.Extensions;
using OrchardCore.DisplayManagement.ModelBinding;
using OrchardCore.DisplayManagement.Notify;
using OrchardCore.Entities;
Expand Down Expand Up @@ -106,19 +107,11 @@ public async Task<IActionResult> List(
new(S["Remove"], nameof(NotificationBulkAction.Remove)),
];

var routeData = new RouteData(options.RouteValues);
var pager = new Pager(pagerParameters, _pagerOptions.GetPageSize());

var queryResult = await _notificationsAdminListQueryService.QueryAsync(pager.Page, pager.PageSize, options, this);

dynamic pagerShape = await _shapeFactory.CreateAsync("Pager", Arguments.From(new
{
pager.Page,
pager.PageSize,
TotalItemCount = queryResult.TotalCount
}));

pagerShape.RouteData(routeData);
dynamic pagerShape = await _shapeFactory.PagerAsync(pager, queryResult.TotalCount, options.RouteValues);

var notificationSummaries = new List<dynamic>();

Expand Down
34 changes: 34 additions & 0 deletions src/OrchardCore.Modules/OrchardCore.Search.AzureAI/AdminMenu.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using System;
using System.Threading.Tasks;
using Microsoft.Extensions.Localization;
using OrchardCore.Navigation;

namespace OrchardCore.Search.AzureAI;

public class AdminMenu(IStringLocalizer<AdminMenu> stringLocalizer) : INavigationProvider
{
protected readonly IStringLocalizer S = stringLocalizer;

public Task BuildNavigationAsync(string name, NavigationBuilder builder)
{
if (!string.Equals(name, "admin", StringComparison.OrdinalIgnoreCase))
{
return Task.CompletedTask;
}

builder
.Add(S["Search"], NavigationConstants.AdminMenuSearchPosition, search => search
.AddClass("azure-ai-service")
.Id("azureaiservice")
.Add(S["Indexing"], S["Indexing"].PrefixPosition(), indexing => indexing
.Add(S["Azure AI Indices"], S["Azure AI Indices"].PrefixPosition(), indexes => indexes
.Action("Index", "Admin", new { area = "OrchardCore.Search.AzureAI" })
.Permission(AzureAISearchIndexPermissionHelper.ManageAzureAISearchIndexes)
.LocalNav()
)
)
);

return Task.CompletedTask;
}
}
Loading

0 comments on commit 63c5636

Please sign in to comment.