public static IQueryable <T> OrderBy <T>(this IQueryable <T> queryable, ISearchModel sortModel) { if (string.IsNullOrWhiteSpace(sortModel.SortColumn)) { return(queryable); } var typeOfT = typeof(T); var property = typeOfT.GetProperty(sortModel.SortColumn, BindingFlags.IgnoreCase | BindingFlags.Public | BindingFlags.Instance); if (property == null) { return(queryable); } var parameter = Expression.Parameter(typeOfT, "parameter"); var propertyAccess = Expression.PropertyOrField(parameter, sortModel.SortColumn); var orderExpression = Expression.Lambda(propertyAccess, parameter); var orderByMethod = sortModel.SortDir == "desc" ? "OrderByDescending" : "OrderBy"; var expression = Expression.Call(typeof(Queryable), orderByMethod, new[] { typeOfT, property.PropertyType }, queryable.Expression, Expression.Quote(orderExpression)); return(queryable.Provider.CreateQuery <T>(expression)); }
private async Task <ISecurityQuestionSearchViewModel> SearchDataAsync(ISearchModel searchModel, ISecurityQuestionSearchViewModel model, CancellationToken cancellationToken) { IPredicate pred = null; IPredicate finalPred = null; List <IPredicate> list = new List <IPredicate>(); if (!string.IsNullOrEmpty(searchModel.SearchText)) { searchModel.SearchText = searchModel.SearchText.Trim(); pred = Predicate <string> .GetPredicate("Question", searchModel.SearchText, Operator.Like); list.Add(pred); } if (list.Count == 0) { list.Add(Predicate <string> .GetPredicate("1", "1", Operator.Equal)); } finalPred = CompoundPredicate.GetCompoundPredicate(LogicalOperator.AND, list.ToArray()); if (model == null) { model = await PoulateDropDownListAsync(model, cancellationToken); } model.SecurityQuestionList = await _dal.SelectAllByFilterAsync(finalPred, cancellationToken, model.GetPageInfo(searchModel.CPage, searchModel.TPage, searchModel.TRows, searchModel.PSize, searchModel.UserId)); return(model); }
private void NavigationService_LoadCompleted(object sender, NavigationEventArgs e) { ISearchModel searchmodel = (ISearchModel)e.ExtraData; SearchResults = (ObservableCollection <VideoFolder>)searchmodel.Results; ResultText = searchmodel.SearchQuery; ResultTextInDetail = SearchResults.Count.ToString(); navigationService.LoadCompleted -= NavigationService_LoadCompleted; OpenFolderCommand = new DelegateCommand <object>(OpenFolderCommandAction); UpdateViewCollection(); }
private async Task <IAdvertisementSearchViewModel> SearchDataAsync(ISearchModel searchModel, IAdvertisementSearchViewModel model, CancellationToken cancellationToken) { IPredicate pred = null; IPredicate finalPred = null; List <IPredicate> list = new List <IPredicate>(); if (!string.IsNullOrEmpty(searchModel.SearchText)) { searchModel.SearchText = searchModel.SearchText.Trim(); if (searchModel.SearchField == -1) { pred = CompoundPredicate.GetCompoundPredicate( LogicalOperator.OR, Predicate <string> .GetPredicate("A.Name", searchModel.SearchText, Operator.Like), Predicate <string> .GetPredicate("A.Description", searchModel.SearchText, Operator.Like)); list.Add(pred); } else if (searchModel.SearchField == -2) { pred = Predicate <long> .GetPredicate("T.ThemeId", System.Convert.ToInt64(searchModel.SearchText), Operator.Equal); list.Add(pred); } else if (searchModel.SearchField == -3) { pred = Predicate <long> .GetPredicate("C.CategoryId", System.Convert.ToInt64(searchModel.SearchText), Operator.Equal); list.Add(pred); } } if (list.Count == 0) { list.Add(Predicate <string> .GetPredicate("1", "1", Operator.Equal)); } finalPred = CompoundPredicate.GetCompoundPredicate(LogicalOperator.AND, list.ToArray()); if (model == null) { model = await PoulateDropDownListAsync(model, cancellationToken); } model.AdvertisementList = await _dal.SelectAllByFilterAsync(finalPred, cancellationToken, model.GetPageInfo(searchModel.CPage, searchModel.TPage, searchModel.TRows, searchModel.PSize, searchModel.UserId)); return(model); }
public async Task <ICollection <Product> > SearchForProduct(ISearchModel searchModel) { var productSearch = searchModel as ProductSearch; if (productSearch == null) { return(null); } // join products and cities into one db var joinedDb = (from pr in _context.Product join cityUsr in _context.Users on pr.OwnerId equals cityUsr.Id select new { product = pr, city = cityUsr.City, address = cityUsr.Address, owner = cityUsr.FullName }); // Check if the name was filled, if not, add the result to the list try { var result = joinedDb.Where(productJoin => productSearch.Name == "" || productSearch.Name == null || productJoin.product.Name.Contains(searchModel.Name) || searchModel.Name.Contains(productJoin.product.Name)) //// Check if the category was chosen, if not, add the result to the list .Where(productJoin => productSearch.CategoryId == 0 || productSearch.CategoryId == productJoin.product.CategoryId) // Check if the city was filled, if not, add the result to the list .Where(productJoin => productSearch.Location.City == "" || productSearch.Location.City == null || productJoin.city == productSearch.Location.City) // Check if the street was filled, if not, add the result to the list .Where(productJoin => productSearch.Location.StreetAddress == "" || productSearch.Location.StreetAddress == null || productSearch.Location.StreetAddress.Contains(productJoin.address) || productJoin.address.Contains(productSearch.Location.StreetAddress)) // Check if the price range is filled, if not add to result .Where(productJoin => productSearch.MinPrice == 0 || productJoin.product.Price >= productSearch.MinPrice) .Where(productJoin => productSearch.MaxPrice == 0 || productJoin.product.Price <= productSearch.MaxPrice) .Select(productJoin => productJoin.product) .Include(pr => pr.Category) .Include(pr => pr.Owner); return(await(result.Distinct()).ToListAsync()); } catch (Exception ex) { Console.WriteLine(ex); } return(new List <Product>()); }
public async Task <ICategorySearchViewModel> SearchDataAsync(ISearchModel searchModel, ICategorySearchViewModel model, CancellationToken cancellationToken) { IPredicate pred = null; IPredicate finalPred = null; List <IPredicate> list = new List <IPredicate>(); if (!string.IsNullOrEmpty(searchModel.SearchText)) { if (searchModel.SearchField == -1) { pred = CompoundPredicate.GetCompoundPredicate( LogicalOperator.OR, Predicate <string> .GetPredicate("C.CategoryName", searchModel.SearchText, Operator.Like), Predicate <string> .GetPredicate("T.Name", searchModel.SearchText, Operator.Like) ); list.Add(pred); } else if (searchModel.SearchField == 1) { pred = Predicate <string> .GetPredicate("C.CategoryName", searchModel.SearchText, Operator.Like); list.Add(pred); } else if (searchModel.SearchField == 2) { pred = Predicate <string> .GetPredicate("T.Name", searchModel.SearchText, Operator.Like); list.Add(pred); } } if (list.Count == 0) { list.Add(Predicate <string> .GetPredicate("1", "1", Operator.Equal)); } finalPred = CompoundPredicate.GetCompoundPredicate(LogicalOperator.AND, list.ToArray()); if (model == null) { model = await PoulateDropDownListAsync(model, cancellationToken); } model.CategoryList = await _dal.SelectAllByFilterAsync(finalPred, cancellationToken, model.GetPageInfo(searchModel.CPage, searchModel.TPage, searchModel.TRows, searchModel.PSize, searchModel.UserId)); return(model); }
public static SearchModel Clone(this ISearchModel model) { if (model is null) { throw new ArgumentNullException(nameof(model)); } return(new SearchModel { Page = model.Page, PageSize = model.PageSize, Search = model.Search }); }
public static IQueryable <T> SkipAndTake <T>(this IQueryable <T> queryable, ISearchModel sortModel) { if (sortModel.Skip > 0) { queryable = queryable.Skip(sortModel.Skip); } if (sortModel.Take > 0) { queryable = queryable.Take(sortModel.Take); } return(queryable); }
public async Task RefreshIndexDic(Algorithm alg) { await Task.Run(() => { while (!FileManager.Ready) { ; } }); if (alg == Algorithm.BooleanSearch) { await Task.Run(() => { flagBool = false; SearchMdl_Bool = new BooleanSearchModel(); flagBool = SearchMdl_Bool.buildIndexDic(); }); } else if (alg == Algorithm.InvertedIndexSearch) { await Task.Run(() => { flagInvrtd = false; SearchMdl_InvrtdIdx = new InvertedIndexSearchModel(); flagInvrtd = SearchMdl_InvrtdIdx.buildIndexDic(); }); } else if (alg == Algorithm.PositionalIndexSearch) { await Task.Run(() => { flagPos = false; SearchMdl_PosIdx = new PositionalIndexSearchModel(); flagPos = SearchMdl_PosIdx.buildIndexDic(); }); } else if (alg == Algorithm.TFIDFSearchModel) { await Task.Run(() => { flagTFIDF = false; SearchMdl_TFIDF = new TFIDFSearchModel(); flagTFIDF = SearchMdl_TFIDF.buildIndexDic(); }); } }
public Task <ISearchResult <TestObject> > Get(ISearchModel model) { var search = (TestSearchModel)model; var query = new StringBuilder("id != null"); if (search.CollectionValues.Any()) { foreach (var searchCollectionValue in search.CollectionValues) { query.Append($" and Collection.Contains(\"{searchCollectionValue}\")"); } } if (!string.IsNullOrEmpty(search.StrVal)) { query.Append($" and Prop1=\"{search.StrVal}\""); } if (!string.IsNullOrEmpty(search.ContainsStrTest)) { query.Append($" and ChildObject.Prop1.Contains(\"{search.ContainsStrTest}\")"); } if (search.Num > 0) { query.Append($" and Number={search.Num}"); } if (search.UUID.HasValue) { query.Append($" and UUID=\"{search.UUID}\""); } var queryResult = query.ToString(); return(Get(queryResult, model)); }
public abstract Task <ISearchResult <T> > Get(Expression <Func <T, bool> > predicate, ISearchModel model);
private async Task <IUserSearchViewModel> SearchDataAsync(ISearchModel searchModel, IUserSearchViewModel model, CancellationToken cancellationToken) { IPredicate pred = null; IPredicate finalPred = null; List <IPredicate> list = new List <IPredicate>(); if (searchModel.CountryId > 0) { pred = Predicate <long> .GetPredicate("C.CountryId", searchModel.CountryId, Operator.Equal); list.Add(pred); } if (searchModel.LocationId > 0) { pred = Predicate <long> .GetPredicate("L.LocationId", searchModel.LocationId, Operator.Equal); list.Add(pred); } if (!string.IsNullOrEmpty(searchModel.SearchText)) { searchModel.SearchText = searchModel.SearchText.Trim(); if (searchModel.SearchField == -1) { pred = CompoundPredicate.GetCompoundPredicate( LogicalOperator.OR, Predicate <string> .GetPredicate("U.FirstName", searchModel.SearchText, Operator.Like), Predicate <string> .GetPredicate("U.EmailId", searchModel.SearchText, Operator.Like), Predicate <string> .GetPredicate("L.LocationName", searchModel.SearchText, Operator.Like), Predicate <string> .GetPredicate("U.PhoneNo", searchModel.SearchText, Operator.Like), Predicate <string> .GetPredicate("U.Address2", searchModel.SearchText, Operator.Like)); list.Add(pred); } else if (searchModel.SearchField == 1) { pred = Predicate <string> .GetPredicate("U.FirstName", searchModel.SearchText, Operator.Like); list.Add(pred); } else if (searchModel.SearchField == 2) { pred = Predicate <string> .GetPredicate("U.EmailId", searchModel.SearchText, Operator.Like); list.Add(pred); } else if (searchModel.SearchField == 3) { pred = Predicate <string> .GetPredicate("L.LocationName", searchModel.SearchText, Operator.Like); list.Add(pred); } else if (searchModel.SearchField == 4) { pred = Predicate <string> .GetPredicate("U.PhoneNo", searchModel.SearchText, Operator.Like); list.Add(pred); } else if (searchModel.SearchField == 5) { pred = Predicate <string> .GetPredicate("U.Address2", searchModel.SearchText, Operator.Like); list.Add(pred); } } if (list.Count == 0) { list.Add(Predicate <string> .GetPredicate("1", "1", Operator.Equal)); } finalPred = CompoundPredicate.GetCompoundPredicate(LogicalOperator.AND, list.ToArray()); if (model == null) { model = await PoulateDropDownListAsync(model, cancellationToken); } model.UserList = await _dal.SelectAllByFilterAsync(finalPred, cancellationToken, model.GetPageInfo(searchModel.CPage, searchModel.TPage, searchModel.TRows, searchModel.PSize, searchModel.UserId)); return(model); }
public async Task <ICountrySearchViewModel> SearchAsync(HttpContext context, CancellationToken cancellationToken, ISearchModel searchModel) { ICountrySearchViewModel tdModel = await SearchDataAsync(searchModel, null, cancellationToken); return(tdModel); }
private async Task <IEmailServerSearchViewModel> SearchDataAsync(ISearchModel searchModel, IEmailServerSearchViewModel model, CancellationToken cancellationToken) { IPredicate pred = null; IPredicate finalPred = null; List <IPredicate> list = new List <IPredicate>(); if (!string.IsNullOrEmpty(searchModel.SearchText)) { searchModel.SearchText = searchModel.SearchText.Trim(); if (searchModel.SearchField == -1) { pred = CompoundPredicate.GetCompoundPredicate( LogicalOperator.OR, Predicate <string> .GetPredicate("ServerName", searchModel.SearchText, Operator.Like), Predicate <string> .GetPredicate("ServerIP", searchModel.SearchText, Operator.Like)); System.Int32 port; if (System.Int32.TryParse(searchModel.SearchText, out port)) { pred = CompoundPredicate.GetCompoundPredicate( LogicalOperator.OR, pred, Predicate <System.Int32> .GetPredicate("CONVERT(int,EmailPort)", port, Operator.Equal) ); } list.Add(pred); } else if (searchModel.SearchField == 1) { pred = Predicate <string> .GetPredicate("ServerName", searchModel.SearchText, Operator.Like); list.Add(pred); } else if (searchModel.SearchField == 2) { pred = Predicate <string> .GetPredicate("ServerIP", searchModel.SearchText, Operator.Like); list.Add(pred); } else if (searchModel.SearchField == 3) { System.Int32 port; if (System.Int32.TryParse(searchModel.SearchText, out port)) { pred = Predicate <System.Int32> .GetPredicate("CONVERT(int,EmailPort)", port, Operator.Equal); list.Add(pred); } else { list.Add(Predicate <string> .GetPredicate("1", "2", Operator.Equal)); } } } if (list.Count == 0) { list.Add(Predicate <string> .GetPredicate("1", "1", Operator.Equal)); } finalPred = CompoundPredicate.GetCompoundPredicate(LogicalOperator.AND, list.ToArray()); if (model == null) { model = await PoulateDropDownListAsync(model, cancellationToken); } model.EmailServerList = await _dal.SelectAllByFilterAsync(finalPred, cancellationToken, model.GetPageInfo(searchModel.CPage, searchModel.TPage, searchModel.TRows, searchModel.PSize, searchModel.UserId)); return(model); }
public async Task <IEmailServerSearchViewModel> SearchAsync(System.Web.HttpContext httpContext, ISearchModel model, CancellationToken cancellationToken) { IEmailServerSearchViewModel tdModel = await SearchDataAsync(model, null, cancellationToken); return(tdModel); }
public SearchViewModel(ISearchModel model) { this.model = model; this.model.CleanLocal(); this.Search = new RelayCommand <object>(this.SearchHandler); }
public SearchControlTestViewModel() { data = new TestSearchControlModel(); }
public TestSearchControlViewModel() { searchModel = new TestSearchControlModel(); }
private async Task <ILocationSearchViewModel> SearchDataAsync(ISearchModel searchModel, ILocationSearchViewModel model, CancellationToken cancellationToken) { IPredicate pred = null; IPredicate finalPred = null; List <IPredicate> list = new List <IPredicate>(); var sdsd = searchModel.CPage; if (searchModel.CountryId > 0) { pred = Predicate <long> .GetPredicate("T.CountryId", searchModel.CountryId, Operator.Equal); list.Add(pred); } if (searchModel.LocationId > 0) { pred = Predicate <long> .GetPredicate("O.LocationId", searchModel.LocationId, Operator.Equal); list.Add(pred); } if (!string.IsNullOrEmpty(searchModel.SearchText)) { if (searchModel.SearchField == -1) { //pred = CompoundPredicate.GetCompoundPredicate( // Predicate<string>.GetPredicate("O.LocationName", searchModel.SearchText, Operator.Like), // Predicate<string>.GetPredicate("O.LocationRefNo", searchModel.SearchText, Operator.Like), LogicalOperator.OR); //list.Add(pred); pred = Predicate <string> .GetPredicate("L.LocationName", searchModel.SearchText, Operator.Like); list.Add(pred); } else if (searchModel.SearchField == 1) { pred = Predicate <string> .GetPredicate("L.LocationName", searchModel.SearchText, Operator.Like); list.Add(pred); } } if (list.Count == 0) { list.Add(Predicate <string> .GetPredicate("1", "1", Operator.Equal)); } finalPred = CompoundPredicate.GetCompoundPredicate(LogicalOperator.AND, list.ToArray()); if (model == null) { model = await PoulateDropDownListAsync(model, cancellationToken); } model.LocationList = await _dal.SelectAllByFilterAsync(finalPred, cancellationToken, model.GetPageInfo(searchModel.CPage, searchModel.TPage, searchModel.TRows, searchModel.PSize, searchModel.UserId)); return(model); }
public override async Task <ISearchResult <TModel> > GetAll(Expression <Func <TModel, bool> > predicate, ISearchModel model) { var results = new List <TModel>(); do { var partial = await Get(predicate, model); model.ContinuationToken = partial.ContinuationToken; results.AddRange(partial.Results); } while (!string.IsNullOrEmpty(model.ContinuationToken)); var searchResult = new SearchResult <TModel>() { Results = results, TotalResults = results.Count }; return(searchResult); }
public abstract Task <ISearchResult <T> > Get(string predicate, ISearchModel model);
/// <summary> /// Query with a predicate you built using PredicateBuilder /// </summary> /// <param name="predicate"></param> /// <param name="model"></param> /// <returns></returns> public override async Task <ISearchResult <TModel> > Get(Expression <Func <TModel, bool> > predicate, ISearchModel model) { var queryOptions = new QueryRequestOptions() { MaxItemCount = model.PageSize }; if (!string.IsNullOrEmpty(model.PartitionKey)) { queryOptions.PartitionKey = new PartitionKey(model.PartitionKey); } else { Log.LogWarning($"Enabling Cross-Partition Query in repo {this.GetType().Name}"); } if (!string.IsNullOrEmpty(model.ContinuationToken)) { var decoded = Convert.FromBase64String(model.ContinuationToken); var token = System.Text.Encoding.UTF8.GetString(decoded); model.ContinuationToken = token; } var response = new SearchResult <TModel>() { PageSize = model.PageSize }; if (string.IsNullOrEmpty(model.ContinuationToken)) { var totalResultsCount = Client .GetItemLinqQueryable <TModel>(requestOptions: queryOptions, allowSynchronousQueryExecution: true) .Where(x => x.ItemType.Contains(typeof(TModel).Name)) //force filtering by Item Type .Where(predicate) .Select(x => x.Id) .Count(); response.TotalResults = totalResultsCount; if (totalResultsCount > 500) { Log.LogWarning($"Large Resultset found. Query returned {totalResultsCount} results."); } } var result = Client .GetItemLinqQueryable <TModel>(requestOptions: queryOptions, continuationToken: model.ContinuationToken) .Where(x => x.ItemType.Contains(typeof(TModel).Name)) //force filtering by Item Type .Where(predicate) .ToFeedIterator(); var res = await result.ReadNextAsync(); if (res.RequestCharge < 100) { Log.LogInformation($"Request used {res.RequestCharge} RUs.| Query: {result}"); } else if (res.RequestCharge < 200) { Log.LogInformation($"Moderate request to CosmosDb used {res.RequestCharge} RUs"); } else { Log.LogWarning($"Expensive request to CosmosDb. RUs: {res.RequestCharge} | Query: {result}"); } response.Results = res.ToList(); response.ContinuationToken = !string.IsNullOrEmpty(res.ContinuationToken) ? Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(res.ContinuationToken)) : ""; return(response); }
public SearchViewModel(ISearchModel model) { SearchCommand = new DelegateCommand(() => model.Search(SearchText)); }
public async Task <ISecurityQuestionSearchViewModel> SearchAsync(System.Web.HttpContext httpContext, ISearchModel model, CancellationToken cancellationToken) { ISecurityQuestionSearchViewModel tdmodel = await SearchDataAsync(model, null, cancellationToken); return(tdmodel); }