Skip to content

Commit

Permalink
Merge pull request #70 from dereklegenzoff/delegenz-track2
Browse files Browse the repository at this point in the history
Upgrading SDKs to Track 2
  • Loading branch information
Derek Legenzoff authored Sep 24, 2020
2 parents 09146e4 + 73b5eb1 commit da72250
Show file tree
Hide file tree
Showing 9 changed files with 244 additions and 176 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Azure.Search.Documents" Version="11.0.0" />
<PackageReference Include="Azure.Storage.Blobs" Version="12.4.2" />
<PackageReference Include="Microsoft.ApplicationInsights" Version="2.13.1" />
<PackageReference Include="Microsoft.Azure.Search" Version="10.1.0" />
<PackageReference Include="Microsoft.Spatial" Version="7.6.4" />
<PackageReference Include="Microsoft.VisualStudio.Web.BrowserLink" Version="2.2.0" />
<PackageReference Include="WindowsAzure.Storage" Version="9.3.3" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="System.Text.Json" Version="4.7.2" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public IActionResult Search([FromQuery]string q, [FromQuery]string facets = "",
.Select(g => new SearchFacet { Key = g.Key, Value = g.Select(f => f[1]).ToArray() })
.ToArray();

var viewModel = SearchView(new SearchParameters
var viewModel = SearchView(new SearchOptions
{
q = q,
searchFacets = searchFacets,
Expand All @@ -90,7 +90,7 @@ public IActionResult Search([FromQuery]string q, [FromQuery]string facets = "",
return View(viewModel);
}

public class SearchParameters
public class SearchOptions
{
public string q { get; set; }
public SearchFacet[] searchFacets { get; set; }
Expand All @@ -99,7 +99,7 @@ public class SearchParameters
}

[HttpPost]
public SearchResultViewModel SearchView([FromForm]SearchParameters searchParams)
public SearchResultViewModel SearchView([FromForm]SearchOptions searchParams)
{
if (searchParams.q == null)
searchParams.q = "*";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
using System.Linq;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Microsoft.WindowsAzure.Storage.Blob;
using Microsoft.WindowsAzure.Storage.Auth;
using System.Threading.Tasks;
using System.IO;
using System.Web;
using Azure.Storage.Blobs;
using Azure.Storage;

namespace CognitiveSearch.UI.Controllers
{
Expand All @@ -35,8 +35,8 @@ public async Task<IActionResult> Upload()
{
if (formFile.Length > 0)
{
var cloudBlockBlob = container.GetBlockBlobReference(formFile.FileName);
await cloudBlockBlob.UploadFromStreamAsync(formFile.OpenReadStream());
var blob = container.GetBlobClient(formFile.FileName);
await blob.UploadAsync(formFile.OpenReadStream());
}
}
}
Expand All @@ -59,16 +59,17 @@ public async Task<FileContentResult> GetDocumentInline(int storageIndex, string
{
var decodedFilename = HttpUtility.UrlDecode(fileName);
var container = GetStorageContainer(storageIndex);
var cloudBlockBlob = container.GetBlockBlobReference(decodedFilename);
var blob = container.GetBlobClient(decodedFilename);
using (var ms = new MemoryStream())
{
await cloudBlockBlob.DownloadToStreamAsync(ms);
var downlaodInfo = await blob.DownloadAsync();
await downlaodInfo.Value.Content.CopyToAsync(ms);
Response.Headers.Add("Content-Disposition", "inline; filename=" + decodedFilename);
return File(ms.ToArray(), HttpUtility.UrlDecode(mimeType));
}
}

private CloudBlobContainer GetStorageContainer(int storageIndex)
private BlobContainerClient GetStorageContainer(int storageIndex)
{
string accountName = _configuration.GetSection("StorageAccountName")?.Value;
string accountKey = _configuration.GetSection("StorageAccountKey")?.Value;
Expand All @@ -78,7 +79,7 @@ private CloudBlobContainer GetStorageContainer(int storageIndex)
containerKey += (storageIndex+1).ToString();
var containerAddress = _configuration.GetSection(containerKey)?.Value.ToLower();

var container = new CloudBlobContainer(new Uri(containerAddress), new StorageCredentials(accountName, accountKey));
var container = new BlobContainerClient(new Uri(containerAddress), new StorageSharedKeyCredential(accountName, accountKey));
return container;
}
}
Expand Down
23 changes: 19 additions & 4 deletions 02 - Web UI Template/CognitiveSearch.UI/Search/DocumentResult.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using Microsoft.Azure.Search.Models;
using Azure;
using Azure.Search.Documents;
using Azure.Search.Documents.Models;
using System;
using System.Collections.Generic;
using System.Linq;
Expand All @@ -11,9 +13,9 @@ namespace CognitiveSearch.UI
{
public class DocumentResult
{
public List<object> Facets { get; set; }
public Document Result { get; set; }
public IList<SearchResult<Document>> Results { get; set; }
public List<Facet> Facets { get; set; }
public SearchDocument Result { get; set; }
public Pageable<SearchResult<SearchDocument>> Results { get; set; }
public int? Count { get; set; }
public string Token { get; set; }
public int StorageIndex { get; set; }
Expand All @@ -23,4 +25,17 @@ public class DocumentResult
public string IdField { get; set; }
public bool IsPathBase64Encoded { get; set; }
}

public class Facet
{
public string key { get; set; }
public List<FacetValue> value { get; set; }
}

public class FacetValue
{
public string value { get; set; }
public long? count { get; set; }
}

}
Loading

0 comments on commit da72250

Please sign in to comment.