public async Task <IActionResult> NameSearch([FromQuery] string name, CancellationToken cancellationToken) { var criteria = new DatasetSearch { Page = 0, SortOrder = SortOrder.Name, Terms = name, }; var response = await this.DataSearchService.SearchAsync(criteria, cancellationToken).ConfigureAwait(false); if (response == null) { return(this.NoContent()); } var results = response.Value .Select(ds => new DatasetNameSearchResult { Id = ds.Id, Name = ds.Name, }) .ToList(); return(this.Ok(results)); }
private static StringBuilder AppendDomainFilterString(DatasetSearch criteria, StringBuilder sb) { var domainValues = criteria.Facets[FacetKey.DomainId].Where(t => !string.IsNullOrEmpty(t)).ToList(); if (!domainValues.Any()) { return(sb); } sb.Append($" ( "); bool needsOr = false; foreach (var value in domainValues) { if (!needsOr) { needsOr = true; } else { sb.Append($" or "); } sb.Append($"{FacetKey.DomainId} eq '{value}'"); } sb.Append($" ) "); return(sb); }
public async Task <IActionResult> GetDatasetList([FromQuery] int page, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); var result = await DatasetSearch.GetAsync(Math.Max(0, page - 1), cancellationToken).ConfigureAwait(false); return(Ok(result)); }
private static string CreateFilterString(DatasetSearch criteria) { StringBuilder sb = new StringBuilder(); // Convert the facets into OData formatted query members foreach (var facetKey in criteria.Facets.Keys.Where(t => !string.IsNullOrEmpty(t))) { var key = UpdateFacetKey(facetKey); if (sb.Length > 0) { sb.Append(" and "); } if (key == FacetKey.DomainId) { sb = AppendDomainFilterString(criteria, sb); } else if (key == FacetKey.LicenseId) { sb = AppendLicenseFilterString(criteria, sb); } else { bool needsOr = false; foreach (var value in criteria.Facets[key].Where(t => !string.IsNullOrEmpty(t))) { if (!needsOr) { needsOr = true; } else { sb.Append($" and "); } sb.Append($"{key}/any(t:"); sb.Append($"t eq '{value.Replace("'", "''")}'"); sb.Append(")"); } } } return(sb.ToString()); }
public async Task <IActionResult> Search([FromBody] DatasetSearch criteria, CancellationToken cancellationToken) { criteria.Page = Math.Max(0, criteria.Page - 1); var response = await this.DataSearchService.SearchAsync(criteria, cancellationToken) .ConfigureAwait(false); if (response == null) { return(this.NoContent()); } return(this.Ok(new PagedResult <DatasetViewModel> { RecordCount = response.RecordCount, PageCount = response.PageCount, Value = response.Value.Select(d => d.ToDatasetViewModel()).ToList() })); }
/// <summary> /// Searches the asynchronous. /// </summary> /// <param name="criteria">The criteria.</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns>The search results.</returns> public async Task <PagedResult <Dataset> > SearchAsync(DatasetSearch criteria, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); var orderBy = string.Empty; switch (criteria.SortOrder) { case SortOrder.LastModified: orderBy = "modified desc"; break; case SortOrder.Featured: orderBy = "isFeatured desc, name asc"; break; default: orderBy = "name asc"; break; } var parameters = new SearchParameters() { OrderBy = new[] { orderBy }, Top = PageHelper.PageSize, Skip = criteria.Page * PageHelper.PageSize, IncludeTotalResultCount = true, ScoringProfile = "textBoostScoring" }; parameters.Facets = criteria.Facets.Keys.ToList(); parameters.Filter = CreateFilterString(criteria); var results = await this.Client.Documents.SearchAsync <DatasetStorageItem>(criteria.Terms, parameters, null, cancellationToken); return(new PagedResult <Dataset> { RecordCount = results.Count.GetValueOrDefault(), PageCount = PageHelper.CalculateNumberOfPages(results.Count), Value = (from item in results.Results let doc = item.Document select doc.ToDataset()).ToList() }); }
private static StringBuilder AppendLicenseFilterString(DatasetSearch criteria, StringBuilder sb) { bool needsOr = false; foreach (var value in criteria.Facets[FacetKey.LicenseId].Where(t => !string.IsNullOrEmpty(t))) { if (!needsOr) { needsOr = true; } else { sb.Append($" and "); } sb.Append($"{FacetKey.LicenseId} eq '{value}'"); } return(sb); }