public async Task <IEnumerable <FileStorageDto.StorageDto> > Search(AdvancedSearchDto advancedSearchDto, int userId, int clientId) { var fileStorageRepository = DataContextManager.CreateRepository <IFileStorageRepository>(); var fileStorages = await fileStorageRepository.GetQuery(userId, clientId, advancedSearchDto.FolderIds); var resFileStorages = await fileStorages.GetForFileStorage(advancedSearchDto).ToListAsync(); var result = new List <FileStorage>(); if (advancedSearchDto.FolderIds.Count() > 0) { foreach (var fileStorage in resFileStorages) { var res = GetByParentIds(fileStorage, advancedSearchDto.FolderIds); if (res != null) { result.Add(res); } } } else { result = resFileStorages; } return(MapperFactory.CreateMapper <IFileStorageMapper>().MapCollectionToModel(result)); }
private static bool IsNotEmptySearch(AdvancedSearchDto advancedSearch) { return(advancedSearch.ClientIds.Count() > 0 || advancedSearch.DepartmentIds.Count() > 0 || advancedSearch.UserIds.Count() > 0 || advancedSearch.UserGroupIds.Count() > 0 || advancedSearch.StartDate.HasValue || advancedSearch.EndDate.HasValue || !String.IsNullOrEmpty(advancedSearch.SearchString) || advancedSearch.FolderIds.Count() > 0); }
public async Task <ActionResult> SearchByFileStorage([FromBody] AdvancedSearchDto advancedSearchDto) { if (!IsAvailableOperation()) { return(BadRequest()); } var fileStorages = await _fileStorageService.Search(advancedSearchDto, UserId, ClientId); return(Ok(fileStorages)); }
/// <summary> /// Advanced Search /// </summary> /// <param name="advancedSearch"> Object advandced search</param> /// <returns></returns> public List<SearchDocumentResult> AdvancedSearch(AdvancedSearchDto advancedSearch, SortBy sortBy) { var result = new List<SearchDocumentResult>(); if (advancedSearch != null) { try { string strResponse = string.Empty; // String search query string strQuery = BuildSearchQuery(advancedSearch); // String search option string strOption = BuildSearchOption(SearchOptionConst.And, false); // Call Amazon Cloud Search API Service AmazonCloudSearcher ObjCloudSearch = new AmazonCloudSearcher(); strResponse = ObjCloudSearch.SearchRequest(ApiEndpoint, ApiVersion, strQuery, strOption, "_all_fields,_score", SearchOptionConst.SortByScoreDesc, DataFormat.Json); result = GetSearchDocumentList(strResponse); return result; } catch (Exception e) { Log.Error("Advanced search error. Message: " + e.Message + " Stack trace: " + e.StackTrace); } } return null; }
/// <summary> /// Build search query for advanced search /// </summary> /// <param name="advancedSearch"></param> /// <returns></returns> private string BuildSearchQuery(AdvancedSearchDto advancedSearch) { var parameterList = new List<string>(); string parameter = "(and+(phrase+field%3D'{0}'+'{1}'))"; if (advancedSearch != null) { if (advancedSearch.FirstName != null) { parameterList.Add(String.Format(parameter, "firstname", Regex.Replace(advancedSearch.FirstName, @"\s+", " "))); } if (advancedSearch.LastName != null) { parameterList.Add(String.Format(parameter, "lastname", Regex.Replace(advancedSearch.LastName, @"\s+", " "))); } if (advancedSearch.BusinessName != null) { parameterList.Add(String.Format(parameter, "business_name", Regex.Replace(advancedSearch.BusinessName, @"\s+", " "))); } if (advancedSearch.Specialization != null) { parameterList.Add(String.Format(parameter, "specialization", Regex.Replace(advancedSearch.Specialization, @"\s+", " "))); } if (advancedSearch.Country != null) { parameterList.Add(String.Format(parameter, "country", Regex.Replace(advancedSearch.Country, @"\s+", " "))); } if (advancedSearch.State != null) { parameterList.Add(String.Format(parameter, "state", Regex.Replace(advancedSearch.State, @"\s+", " "))); } if (advancedSearch.PostCode != null) { //string template = "(and+(or+ (phrase+field%3D'{0}'+'{1}') (phrase+field%3D'{2}'+'{3}') ))"; //string value = String.Format(template, "postcode", Regex.Replace(advancedSearch.PostCode, @"\s+", " "), "suburb", Regex.Replace(advancedSearch.PostCode, @"\s+", " ")); //parameterList.Add(value); parameterList.Add(String.Format(parameter, "postcode", Regex.Replace(advancedSearch.PostCode, @"\s+", " "))); } if (advancedSearch.Suburb != null) { parameterList.Add(String.Format(parameter, "suburb", Regex.Replace(advancedSearch.Suburb, @"\s+", " "))); } if (advancedSearch.Language != null) { parameterList.Add(String.Format(parameter, "language", Regex.Replace(advancedSearch.Language, @"\s+", " "))); } if (advancedSearch.Profession != null) { parameterList.Add(String.Format(parameter, "profession", Regex.Replace(advancedSearch.Profession, @"\s+", " "))); } } //(and+(phrase+field%3D'firstname'+'david')+(and+(phrase+field%3D'lastname'+'perks')) +(and+(phrase+field%3D'specialisation'+'doctor')))&q.parser=structured //(and+(phrase+field%3D'firstname'+'david')+(and+(phrase+field%3D'lastname'+'perks')) +(and+(phrase+field%3D'specialisation'+'doctor')) +(and+(or+(phrase+field%3D'postcode'+'perks'))))&q.parser=structured if (parameterList.Count > 0) { if (parameterList[0].Length > 0) { parameterList[0] = parameterList[0].Substring(1, parameterList[0].Length - 2); } } var result = string.Join("+", parameterList); result = String.Format("q=({0})", result); return result; }
public static IQueryable <FileStorage> GetForFileStorage(this IQueryable <FileStorage> query, AdvancedSearchDto advancedSearch) { var predicate = PredicateBuilder.New <FileStorage>(true); if (IsNotEmptySearch(advancedSearch)) { predicate.GetByClients(advancedSearch.ClientIds); predicate.GetByDepartments(advancedSearch.DepartmentIds); predicate.GetByUsers(advancedSearch.UserIds); predicate.GetByUserGroups(advancedSearch.UserGroupIds); predicate.GetByDate(advancedSearch.StartDate, advancedSearch.EndDate); predicate.GetBySearchString(advancedSearch.SearchString); } else { predicate.And(x => !x.IsActive); } return(query.Where(predicate)); }
private IQueryable <Property> CreateSearchPredicate( AdvancedSearchDto queryDto, IQueryable <Property> properties) { if (queryDto.HasImage > 0) { properties = properties.Where(i => i.PropertyImage.Any()); } if (queryDto.PropertyTypeIds.Any()) { properties = properties.Where(i => queryDto.PropertyTypeIds.Contains(i.PropertyTypeId)); } if (queryDto.PropertyStatusIds.Any()) { properties = properties.Where(i => queryDto.PropertyStatusIds.Contains(i.PropertyStatusId)); } if (queryDto.PropertyLabelIds.Any()) { properties = properties.Where(i => queryDto.PropertyLabelIds.Contains(i.PropertyLabelId)); } if (queryDto.PropertyFeatureIds.Any()) { properties = properties.Where(i => i.PropertyInvolveFeature .Any(f => queryDto.PropertyFeatureIds.Contains(f.PropertyFeatureId))); } if (queryDto.RoomsFrom != null) { properties = properties.Where(i => i.PropertyDetail.Rooms >= queryDto.RoomsFrom); } if (queryDto.RoomsTo != null) { properties = properties.Where(i => i.PropertyDetail.Rooms <= queryDto.RoomsTo); } if (queryDto.SizeFrom != null) { properties = properties.Where(i => i.PropertyDetail.Size >= queryDto.SizeFrom); } if (queryDto.SizeTo != null) { properties = properties.Where(i => i.PropertyDetail.Size <= queryDto.SizeTo); } if (queryDto.AreaFrom != null) { properties = properties.Where(i => i.PropertyDetail.LandArea >= queryDto.AreaFrom); } if (queryDto.AreaTo != null) { properties = properties.Where(i => i.PropertyDetail.LandArea <= queryDto.AreaTo); } if (queryDto.BathRoomsFrom != null) { properties = properties.Where(i => i.PropertyDetail.Bathrooms >= queryDto.BathRoomsFrom); } if (queryDto.BathRoomsTo != null) { properties = properties.Where(i => i.PropertyDetail.Bathrooms <= queryDto.BathRoomsTo); } if (queryDto.PriceFrom != null) { properties = properties.Where(i => i.PropertyPrice.CalculatedPriceUnit >= queryDto.PriceFrom); } if (queryDto.PriceTo != null) { properties = properties.Where(i => i.PropertyPrice.CalculatedPriceUnit <= queryDto.PriceTo); } if (queryDto.BathRoomsFrom != null) { properties = properties.Where(i => i.PropertyDetail.Bathrooms >= queryDto.BathRoomsFrom); } if (queryDto.BathRoomsTo != null) { properties = properties.Where(i => i.PropertyDetail.Bathrooms <= queryDto.BathRoomsTo); } if (queryDto.BedRoomsFrom != null) { properties = properties.Where(i => i.PropertyDetail.Bedrooms >= queryDto.BedRoomsFrom); } if (queryDto.BedRoomsTo != null) { properties = properties.Where(i => i.PropertyDetail.Bedrooms <= queryDto.BedRoomsTo); } if (queryDto.GaragesFrom != null) { properties = properties.Where(i => i.PropertyDetail.Garages >= queryDto.GaragesFrom); } if (queryDto.GaragesTo != null) { properties = properties.Where(i => i.PropertyDetail.Garages <= queryDto.GaragesTo); } if (queryDto.GaragesSizeFrom != null) { properties = properties.Where(i => i.PropertyDetail.GaragesSize >= queryDto.GaragesSizeFrom); } if (queryDto.GaragesSizeTo != null) { properties = properties.Where(i => i.PropertyDetail.GaragesSize <= queryDto.GaragesSizeTo); } if (queryDto.YearBuildFrom != null) { properties = properties.Where(i => i.PropertyDetail.YearBuild >= queryDto.YearBuildFrom); } if (queryDto.YearBuildTo != null) { properties = properties.Where(i => i.PropertyDetail.YearBuild <= queryDto.YearBuildTo); } if (queryDto.FloorsFrom != null) { properties = properties.Where(i => i.PropertyFloorPlan.Count >= queryDto.FloorsFrom); } if (queryDto.FloorsTo != null) { properties = properties.Where(i => i.PropertyFloorPlan.Count <= queryDto.FloorsTo); } if (queryDto.CountryId != null) { properties = properties.Where(i => i.PropertyLocation.CityNavigation.Region.CountryId == queryDto.CountryId); } if (queryDto.RegionId != null) { properties = properties.Where(i => i.PropertyLocation.CityNavigation.RegionId == queryDto.RegionId); } if (queryDto.CityId != null) { properties = properties.Where(i => i.PropertyLocation.CityId == queryDto.CityId); } if (!string.IsNullOrWhiteSpace(queryDto.Search)) { properties = properties.Where(p => p.Title.Contains(queryDto.Search) || p.PropertyLocation.CityNavigation.Region.Country.Name.Contains(queryDto.Search) || p.PropertyLocation.CityNavigation.Region.Name.Contains(queryDto.Search) || p.PropertyLocation.CityNavigation.Name.Contains(queryDto.Search) || p.PropertyLocation.AddressLine1.Contains(queryDto.Search) || p.PropertyLocation.AddressLine2.Contains(queryDto.Search) || p.PropertyLocation.ZipCode.Contains(queryDto.Search)); } return(properties); }
/// <summary> /// Advanced search by Amazon /// </summary> /// <param name="model"></param> /// <param name="start"></param> /// <param name="size"></param> /// <param name="sortBy"></param> /// <param name="searcherId"></param> /// <param name="searcherLocation"></param> /// <returns></returns> public List<SearchResultDto> AdvancedSearchByAmazon(AdvancedSearchDto model, int start, int size, SortBy sortBy, Guid searcherId, Coordinates searcherLocation = null) { var result = new List<SearchResultDto>(); try { if (model != null) { // Search var AmazonCloud = new AmazonCloudSearch(); var resultList = AmazonCloud.AdvancedSearch(model, sortBy); if (resultList != null && resultList.Count > 0) { //get latitude, longitude of Searcher if (searcherLocation == null) { searcherLocation = GetPositionSearcher(searcherId); } // Get list user by list user Id from database var userList = userService.GetListUserFromAWFSearchResults(resultList); // Join 2 list for sort by score var searchResultList = (from user in userList join item in resultList on user.Id equals item.Id where user.Profiles != null && user.Profiles.Any() && user.Profiles.FirstOrDefault().Specializations != null && user.Profiles.FirstOrDefault().Specializations.Any() && user.Locations != null && user.Locations.Any() && user.Status == Status.Active orderby item.Score descending select new SearchResultDto { User = user, Score = item.Score, Proximity = GetDistance(searcherLocation, user), TalkNowRate = (double)user.Profile.Specializations.SingleOrDefault().TalkNowRate, Feedback = bookingService.RatingCalculator(user.Id) }).ToList(); // Search result after sort result = ResultSequencing(searchResultList, sortBy, model.ShowVerifiedExperts, model.ShowIndependentMember, model.ShowBusinessMember); // Paging search result if (size != -1) { result = result.Skip(start).Take(size).ToList(); } } } } catch (Exception ex) { Log.Error(ex.ToString()); } return result; }