Skip to content

Commit

Permalink
bug fixes for sdk upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
dereklegenzoff committed Sep 24, 2020
1 parent e44c673 commit 73b5eb1
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<PackageReference Include="Microsoft.ApplicationInsights" Version="2.13.1" />
<PackageReference Include="Microsoft.Spatial" Version="7.6.4" />
<PackageReference Include="Microsoft.VisualStudio.Web.BrowserLink" Version="2.2.0" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="System.Text.Json" Version="4.7.2" />
</ItemGroup>

Expand Down
16 changes: 15 additions & 1 deletion 02 - Web UI Template/CognitiveSearch.UI/Search/DocumentResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the MIT License.

using Azure;
using Azure.Search.Documents;
using Azure.Search.Documents.Models;
using System;
using System.Collections.Generic;
Expand All @@ -12,7 +13,7 @@ namespace CognitiveSearch.UI
{
public class DocumentResult
{
public List<object> Facets { 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; }
Expand All @@ -24,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; }
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@
using Azure.Storage.Sas;
using Microsoft.ApplicationInsights;
using Microsoft.Extensions.Configuration;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text.Json.Serialization;
using System.Threading.Tasks;

namespace CognitiveSearch.UI
Expand Down Expand Up @@ -110,13 +112,27 @@ public SearchOptions GenerateSearchOptions(SearchFacet[] searchFacets = null, st
Skip = (currentPage - 1) * 10,
IncludeTotalCount = true,
QueryType = SearchQueryType.Full,
//Select = selectFilter,
//Facets = Model.Facets.Select(f => f.Name).ToList(),
//HighlightFields = Model.SearchableFields,
HighlightPreTag = "<b>",
HighlightPostTag = "</b>"
};

foreach (string s in selectFilter)
{
options.Select.Add(s);
}

var facets = Model.Facets.Select(f => f.Name).ToList();
foreach (string f in facets)
{
options.Facets.Add(f);
}

foreach (string h in Model.SearchableFields)
{
options.HighlightFields.Add(h);
}


string filter = null;
var filterStr = string.Empty;

Expand Down Expand Up @@ -267,6 +283,11 @@ public SearchResults<SearchDocument> GetFacets(string searchText, List<string> f
QueryType = SearchQueryType.Full
};

foreach (string s in facetNames)
{
options.Facets.Add(s);
}

return _searchIndexClient.GetSearchClient(IndexName).Search<SearchDocument>(searchText, options);
}
catch (Exception ex)
Expand All @@ -289,7 +310,7 @@ public DocumentResult GetDocuments(string q, SearchFacet[] searchFacets, int cur

var response = Search(q, searchFacets, selectFilter, currentPage, polygonString);
var searchId = GetSearchId().ToString();
var facetResults = new List<object>();
var facetResults = new List<Facet>();
var tagsResults = new List<object>();

if (response != null && response.Facets != null)
Expand All @@ -299,7 +320,7 @@ public DocumentResult GetDocuments(string q, SearchFacet[] searchFacets, int cur
{
var cleanValues = GetCleanFacetValues(facetResult);

facetResults.Add(new
facetResults.Add(new Facet
{
key = facetResult.Key,
value = cleanValues
Expand Down Expand Up @@ -329,6 +350,10 @@ public DocumentResult GetDocuments(string q, SearchFacet[] searchFacets, int cur
Token = s_tokens[0],
IsPathBase64Encoded = _isPathBase64Encoded
};

string json = JsonConvert.SerializeObject(facetResults);


return result;
}

Expand Down Expand Up @@ -481,9 +506,9 @@ private static string Base64Decode(string input)
/// </summary>
/// <param name="facetResult"></param>
/// <returns></returns>
private static IList<FacetResult> GetCleanFacetValues(KeyValuePair<string, IList<FacetResult>> facetResult)
private static List<FacetValue> GetCleanFacetValues(KeyValuePair<string, IList<FacetResult>> facetResult)
{
IList<FacetResult> cleanValues = new List<FacetResult>();
List<FacetValue> cleanValues = new List<FacetValue>();

if (facetResult.Key == "people")
{
Expand All @@ -492,15 +517,19 @@ private static IList<FacetResult> GetCleanFacetValues(KeyValuePair<string, IList
{
if (element.Values.ToString().Length >= 4)
{
cleanValues.Add(element);

cleanValues.Add(new FacetValue() { value = element.Value.ToString(), count = element.Count });
}
}

return cleanValues;
}
else
{
return facetResult.Value;
List<FacetValue> outputFacets = facetResult.Value
.Select(x => new FacetValue() { value = x.Value.ToString(), count = x.Count })
.ToList();
return outputFacets;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ public string GetFacetGraphNodes(string q, List<string> facetNames, int maxLevel

foreach (FacetResult facet in facetVals)
{
var facetValue = facet.Values.ToString();
var facetValue = facet.Value.ToString();

NodeInfo nodeInfo = new NodeInfo(-1, -1);
if (NodeMap.TryGetValue(facetValue, out nodeInfo) == false)
{
Expand Down
4 changes: 2 additions & 2 deletions 02 - Web UI Template/CognitiveSearch.UI/wwwroot/js/details.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,9 @@ function AuthenticateMap(result) {

if (latlon) {

if (latlon.isEmpty === false) {
if (latlon.coordinates !== null) {

var coordinates = [latlon.longitude, latlon.latitude];
var coordinates = [latlon.coordinates[0], latlon.coordinates[1]]; // longitude, latitude

// Authenticate the map using the key
var map = new atlas.Map('myMap', {
Expand Down
8 changes: 4 additions & 4 deletions 02 - Web UI Template/CognitiveSearch.UI/wwwroot/js/results.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,10 @@ function UpdatePOIs(results, dataSource) {
var coordinates;
for (var i = 0; i < results.length; i++) {
var result = results[i].document;
var latlon = result.geoLocation;
if (latlon !== null) {
if (latlon.isEmpty === false) {
coordinates = [latlon.longitude, latlon.latitude];
var latlon = result?.geoLocation;
if (latlon !== null && typeof latlon !== 'undefined') {
if (latlon.coordinates !== null) {
coordinates = [latlon.coordinates[0], latlon.coordinates[1]]; // longitude, latitude
//Add the symbol to the data source.
dataSource.add(new atlas.data.Feature(new atlas.data.Point(coordinates), {
name: result.metadata_storage_name,
Expand Down

0 comments on commit 73b5eb1

Please sign in to comment.