public async Task <IPagedResults <EvacueeListItem> > GetEvacueesAsync(SearchQueryParameters searchQuery) { var query = db.Evacuees .Include(e => e.EvacueeRegistration) .ThenInclude(r => r.IncidentTask) .ThenInclude(i => i.Community) .Include(e => e.EvacueeRegistration) .ThenInclude(r => r.IncidentTask) .ThenInclude(i => i.Region) .Include(e => e.EvacueeRegistration) .ThenInclude(r => r.HostCommunity) .Include(e => e.Referrals) .Where(e => e.EvacueeRegistration.Active == searchQuery.Active); if (searchQuery.HasQuery()) { query = query.Where(e => EF.Functions.Like(e.LastName, $"{searchQuery.Query}%") || e.EvacueeRegistration.IncidentTask.TaskNumber == searchQuery.Query || e.EvacueeRegistration.EssFileNumber.ToString() == searchQuery.Query || EF.Functions.Like(e.EvacueeRegistration.HostCommunity.Name, $"%{searchQuery.Query}%") || EF.Functions.Like(e.EvacueeRegistration.IncidentTask.Community.Name, $"%{searchQuery.Query}%") ); } if (!searchQuery.HasSortBy()) { searchQuery.SortBy = "-essFileNumber"; } var results = await query.Sort(MapSortToFields(searchQuery.SortBy)).ToArrayAsync(); return(new PaginatedList <EvacueeListItem>(results.Select(mapper.Map <EvacueeListItem>), searchQuery.Offset, searchQuery.Limit)); }
public async Task <IActionResult> GetOpenIncidentTasks([FromQuery] SearchQueryParameters searchQuery) { int limit = searchQuery.Limit; int offset = searchQuery.Offset; var items = await dataInterface.GetOpenIncidentTasksAsync(limit, offset); return(Json(items)); }
public async Task <IActionResult> Get(string registrationId, SearchQueryParameters searchQuery) { var results = await dataInterface.GetReferralsAsync(registrationId, searchQuery); return(await Task.FromResult(Json(new { RegistrationId = registrationId, Referrals = results }))); }
public async Task <IPagedResults <IncidentTask> > GetIncidentTasksAsync(SearchQueryParameters searchQuery) { var items = await IncidentTasks .GroupJoin(db.EvacueeRegistrations.Select(e => new { e.IncidentTaskId, evacueeCount = e.Evacuees.Count() }), incident => incident.Id, summary => summary.IncidentTaskId, (incident, summary) => new { incident = incident, evacueeCount = summary.Sum(s => s.evacueeCount) } ) .Where(t => !searchQuery.HasQuery() || t.incident.Community.Id == Guid.Parse(searchQuery.Query)) .Where(t => searchQuery.Active == t.incident.Active) .Sort(searchQuery.SortBy ?? "incident.id") .ToArrayAsync(); return(new PaginatedList <IncidentTask>(items.Select(t => t.incident.ToViewModel(t.evacueeCount)), searchQuery.Offset, searchQuery.Limit)); }
private string BuildQuery(SearchQueryParameters parameters) { var queryList = new List <string>(); foreach (var searchFilterInfo in parameters.Filters.Where(s => s != null)) { var query = _queryBuilders.First(s => s.IsMatch(searchFilterInfo)) .BuildQuery(searchFilterInfo); if (string.IsNullOrWhiteSpace(query)) { continue; } queryList.Add(query); } if (!string.IsNullOrWhiteSpace(parameters.CustomQuery)) { queryList.Add(parameters.CustomQuery); } return(BuildCustomQuery(parameters.QueryOperator, queryList.ToArray())); }
public async Task <IPagedResults <Organization> > GetOrganizationsAsync(SearchQueryParameters searchQuery) { Guid? communityId = null; string regionName = null; if (searchQuery.HasQuery() && Guid.TryParse(searchQuery.Query, out Guid searchEntityId)) { communityId = searchEntityId; } else if (searchQuery.HasQuery()) { regionName = searchQuery.Query; } var items = await Organizations .Where(o => (!communityId.HasValue || o.Community.Id == communityId) && (string.IsNullOrEmpty(regionName) || o.RegionName == regionName) ) .Where(t => searchQuery.Active == t.Active) .Sort(searchQuery.SortBy ?? "id") .Join(Volunteers.Where(v => v.IsPrimaryContact ?? false), o => o.Id, pc => pc.Organization.Id, (org, pc) => new { org, pc }) //Assume a single primary contact .ToArrayAsync(); return(new PaginatedList <Organization>(items.Select(i => MapToViewModel(i.org, i.pc)), searchQuery.Offset, searchQuery.Limit)); }
public async Task <IActionResult> GetAll([FromQuery] SearchQueryParameters searchQuery) { var items = await dataInterface.GetOrganizationsAsync(searchQuery); return(Json(items)); }
public async Task <IPagedResults <ViewModels.ReferralListItem> > GetReferralsAsync(string registrationId, SearchQueryParameters searchQuery) { var results = await Referrals .Where(r => r.RegistrationId == long.Parse(registrationId) && r.Active == searchQuery.Active) .Select(r => mapper.Map <ViewModels.Referral>(r)) .ToArrayAsync(); return(new PaginatedList <ViewModels.ReferralListItem>( results.Select(r => r.ToListItem()) .OrderBy(r => referralOrder.IndexOf(r.Type)) .ThenByDescending(r => r.ValidFrom) .ToArray(), searchQuery.Offset, searchQuery.Limit)); }
public async Task <IActionResult> Get([FromQuery] SearchQueryParameters searchQuery) { var items = await dataInterface.GetIncidentTasksAsync(searchQuery); return(Json(items)); }
public void QueryBuilder_BuildQuery_complex_quey() { var expectedFilter = "((Rooms/any(x: x/Type ne 'Standard Room' and x/BaseRate ge 100 and search.in(x/Tags, 'jacuzzi tub|bathroom shower','|')) and search.in(Tags, 'view|laundry service', '|')) or Address/Country eq 'USA')"; var searchOptions = new List <SearchQueryParameter> { new SearchQueryParameter() { Parent = TestAzureSearchProperties.Rooms, Name = TestAzureSearchProperties.Rooms, Value = "", Type = DataType.String, ODataOperator = ODataOperators.Any, SubQueryParameterQueryCondition = QueryConditions.And, SubQueryParameters = new List <SearchSubQueryParameter> { new SearchSubQueryParameter { AdditionalFilterParent = TestAzureSearchProperties.Rooms, AdditionalFilterName = TestAzureSearchProperties.RoomType, Value = "Standard Room", Type = DataType.String, ODataOperator = ODataOperators.Ne }, new SearchSubQueryParameter { AdditionalFilterParent = TestAzureSearchProperties.Rooms, AdditionalFilterName = TestAzureSearchProperties.RoomBaseRate, Value = 100, Type = DataType.Number, ODataOperator = ODataOperators.Ge }, new SearchSubQueryParameter { AdditionalFilterParent = TestAzureSearchProperties.Rooms, AdditionalFilterName = TestAzureSearchProperties.Tags, Value = "jacuzzi tub|bathroom shower", Type = DataType.String, ODataOperator = ODataOperators.SearchIn } } }, new SearchQueryParameter() { Parent = TestAzureSearchProperties.Tags, Name = TestAzureSearchProperties.Tags, Value = "view|laundry service", Type = DataType.String, ODataOperator = ODataOperators.SearchIn } }; var countryQuery = new SearchQueryParameters(new List <SearchQueryParameter> { new SearchQueryParameter { Parent = TestAzureSearchProperties.Country, Name = TestAzureSearchProperties.Country, Value = "USA", ODataOperator = ODataOperators.Eq } }); var actualQuery = _queryBuilder.BuildQuery(QueryConditions.Or, new SearchQueryParameters(searchOptions, QueryConditions.And), countryQuery); actualQuery.Should().Be(expectedFilter); }
static void Main(string[] args) { //Step 1: Create your search properties var propertyMaps = new AzureSearchProperties(); //Step 2: Provide configurations required - Date format and Delimiter var searchConfig = new SearchConfiguration("yyyy-MM-dd", "|"); //Step 3: Create property mapper object var filterMapper = new PropertyMapper(propertyMaps); //Step 4: Create DataFormat var dataFormats = new List <IDataFormat>() { new DateTimeFormat(searchConfig), new NullDataFormat(), new NumberFormat(), new StringDataFormat() }; //Step 5: Create QueryBuilder list var queryBuilders = new List <IQueryBuilder> { new StandardQueryBuilder(filterMapper, searchConfig, dataFormats), new CollectionQueryBuilder(filterMapper, searchConfig, dataFormats) }; //Step 6: Create SearchQueryBuilder object var searchQueryBuilder = new SearchQueryBuilder(queryBuilders); //Example Query we required to build // "((Rooms/any(x: x/Type ne 'Standard Room' and x/BaseRate ge 100 and search.in(x/Tags, 'jacuzzi tub|bathroom shower','|')) and search.in(Tags, 'view|laundry service', '|')) or Address/Country eq 'USA')" //To create above query you have to build your searchQueryParameters in c# //Build Rooms and tags query block var roomsAndTagFilters = new List <SearchQueryParameter> { new SearchQueryParameter() { Parent = AzureSearchProperties.Rooms, Name = AzureSearchProperties.Rooms, Value = "", ODataOperator = ODataOperators.Any, SubQueryParameterQueryCondition = QueryConditions.And, SubQueryParameters = new List <SearchSubQueryParameter> { new SearchSubQueryParameter { AdditionalFilterParent = AzureSearchProperties.Rooms, AdditionalFilterName = AzureSearchProperties.RoomType, Value = "Standard Room", ODataOperator = ODataOperators.Ne }, new SearchSubQueryParameter { AdditionalFilterParent = AzureSearchProperties.Rooms, AdditionalFilterName = AzureSearchProperties.RoomBaseRate, Value = 100, ODataOperator = ODataOperators.Ge }, new SearchSubQueryParameter { AdditionalFilterParent = AzureSearchProperties.Rooms, AdditionalFilterName = AzureSearchProperties.Tags, Value = "jacuzzi tub|bathroom shower", ODataOperator = ODataOperators.SearchIn } } }, new SearchQueryParameter() { Parent = AzureSearchProperties.Tags, Name = AzureSearchProperties.Tags, Value = "view|laundry service", ODataOperator = ODataOperators.SearchIn } }; //This parameter will build the "((Rooms/any(x: x/Type ne 'Standard Room' and x/BaseRate ge 100 and search.in(x/Tags, 'jacuzzi tub|bathroom shower','|')) and search.in(Tags, 'view|laundry service', '|'))" var roomsAndTagQueryParameter = new SearchQueryParameters(roomsAndTagFilters, QueryConditions.And); //This parameter will build the "Address/Country eq 'USA'" var countryQueryParameter = new SearchQueryParameters(new List <SearchQueryParameter> { new SearchQueryParameter { Parent = AzureSearchProperties.Country, Name = AzureSearchProperties.Country, Value = "USA", ODataOperator = ODataOperators.Eq } }); //Finally combined the two parameters with or gate var azureSearchQuery = searchQueryBuilder.BuildQuery(QueryConditions.Or, roomsAndTagQueryParameter, countryQueryParameter); Console.WriteLine("Final Query:"); Console.WriteLine(azureSearchQuery); Console.Read(); }
public async Task <IActionResult> Get(SearchQueryParameters query) { var evacuees = await dataInterface.GetEvacueesAsync(query); return(Json(evacuees)); }