Skip to content

Commit da72250

Browse files
author
Derek Legenzoff
authored
Merge pull request #70 from dereklegenzoff/delegenz-track2
Upgrading SDKs to Track 2
2 parents 09146e4 + 73b5eb1 commit da72250

File tree

9 files changed

+244
-176
lines changed

9 files changed

+244
-176
lines changed

02 - Web UI Template/CognitiveSearch.UI/CognitiveSearch.UI.csproj

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,13 @@
55
</PropertyGroup>
66

77
<ItemGroup>
8+
<PackageReference Include="Azure.Search.Documents" Version="11.0.0" />
9+
<PackageReference Include="Azure.Storage.Blobs" Version="12.4.2" />
810
<PackageReference Include="Microsoft.ApplicationInsights" Version="2.13.1" />
9-
<PackageReference Include="Microsoft.Azure.Search" Version="10.1.0" />
11+
<PackageReference Include="Microsoft.Spatial" Version="7.6.4" />
1012
<PackageReference Include="Microsoft.VisualStudio.Web.BrowserLink" Version="2.2.0" />
11-
<PackageReference Include="WindowsAzure.Storage" Version="9.3.3" />
13+
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
14+
<PackageReference Include="System.Text.Json" Version="4.7.2" />
1215
</ItemGroup>
1316

1417
<ItemGroup>

02 - Web UI Template/CognitiveSearch.UI/Controllers/HomeController.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public IActionResult Search([FromQuery]string q, [FromQuery]string facets = "",
8080
.Select(g => new SearchFacet { Key = g.Key, Value = g.Select(f => f[1]).ToArray() })
8181
.ToArray();
8282

83-
var viewModel = SearchView(new SearchParameters
83+
var viewModel = SearchView(new SearchOptions
8484
{
8585
q = q,
8686
searchFacets = searchFacets,
@@ -90,7 +90,7 @@ public IActionResult Search([FromQuery]string q, [FromQuery]string facets = "",
9090
return View(viewModel);
9191
}
9292

93-
public class SearchParameters
93+
public class SearchOptions
9494
{
9595
public string q { get; set; }
9696
public SearchFacet[] searchFacets { get; set; }
@@ -99,7 +99,7 @@ public class SearchParameters
9999
}
100100

101101
[HttpPost]
102-
public SearchResultViewModel SearchView([FromForm]SearchParameters searchParams)
102+
public SearchResultViewModel SearchView([FromForm]SearchOptions searchParams)
103103
{
104104
if (searchParams.q == null)
105105
searchParams.q = "*";

02 - Web UI Template/CognitiveSearch.UI/Controllers/StorageController.cs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
using System.Linq;
66
using Microsoft.AspNetCore.Mvc;
77
using Microsoft.Extensions.Configuration;
8-
using Microsoft.WindowsAzure.Storage.Blob;
9-
using Microsoft.WindowsAzure.Storage.Auth;
108
using System.Threading.Tasks;
119
using System.IO;
1210
using System.Web;
11+
using Azure.Storage.Blobs;
12+
using Azure.Storage;
1313

1414
namespace CognitiveSearch.UI.Controllers
1515
{
@@ -35,8 +35,8 @@ public async Task<IActionResult> Upload()
3535
{
3636
if (formFile.Length > 0)
3737
{
38-
var cloudBlockBlob = container.GetBlockBlobReference(formFile.FileName);
39-
await cloudBlockBlob.UploadFromStreamAsync(formFile.OpenReadStream());
38+
var blob = container.GetBlobClient(formFile.FileName);
39+
await blob.UploadAsync(formFile.OpenReadStream());
4040
}
4141
}
4242
}
@@ -59,16 +59,17 @@ public async Task<FileContentResult> GetDocumentInline(int storageIndex, string
5959
{
6060
var decodedFilename = HttpUtility.UrlDecode(fileName);
6161
var container = GetStorageContainer(storageIndex);
62-
var cloudBlockBlob = container.GetBlockBlobReference(decodedFilename);
62+
var blob = container.GetBlobClient(decodedFilename);
6363
using (var ms = new MemoryStream())
6464
{
65-
await cloudBlockBlob.DownloadToStreamAsync(ms);
65+
var downlaodInfo = await blob.DownloadAsync();
66+
await downlaodInfo.Value.Content.CopyToAsync(ms);
6667
Response.Headers.Add("Content-Disposition", "inline; filename=" + decodedFilename);
6768
return File(ms.ToArray(), HttpUtility.UrlDecode(mimeType));
6869
}
6970
}
7071

71-
private CloudBlobContainer GetStorageContainer(int storageIndex)
72+
private BlobContainerClient GetStorageContainer(int storageIndex)
7273
{
7374
string accountName = _configuration.GetSection("StorageAccountName")?.Value;
7475
string accountKey = _configuration.GetSection("StorageAccountKey")?.Value;
@@ -78,7 +79,7 @@ private CloudBlobContainer GetStorageContainer(int storageIndex)
7879
containerKey += (storageIndex+1).ToString();
7980
var containerAddress = _configuration.GetSection(containerKey)?.Value.ToLower();
8081

81-
var container = new CloudBlobContainer(new Uri(containerAddress), new StorageCredentials(accountName, accountKey));
82+
var container = new BlobContainerClient(new Uri(containerAddress), new StorageSharedKeyCredential(accountName, accountKey));
8283
return container;
8384
}
8485
}
Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License.
33

4-
using Microsoft.Azure.Search.Models;
4+
using Azure;
5+
using Azure.Search.Documents;
6+
using Azure.Search.Documents.Models;
57
using System;
68
using System.Collections.Generic;
79
using System.Linq;
@@ -11,9 +13,9 @@ namespace CognitiveSearch.UI
1113
{
1214
public class DocumentResult
1315
{
14-
public List<object> Facets { get; set; }
15-
public Document Result { get; set; }
16-
public IList<SearchResult<Document>> Results { get; set; }
16+
public List<Facet> Facets { get; set; }
17+
public SearchDocument Result { get; set; }
18+
public Pageable<SearchResult<SearchDocument>> Results { get; set; }
1719
public int? Count { get; set; }
1820
public string Token { get; set; }
1921
public int StorageIndex { get; set; }
@@ -23,4 +25,17 @@ public class DocumentResult
2325
public string IdField { get; set; }
2426
public bool IsPathBase64Encoded { get; set; }
2527
}
28+
29+
public class Facet
30+
{
31+
public string key { get; set; }
32+
public List<FacetValue> value { get; set; }
33+
}
34+
35+
public class FacetValue
36+
{
37+
public string value { get; set; }
38+
public long? count { get; set; }
39+
}
40+
2641
}

0 commit comments

Comments
 (0)