public HitterSearchViewModel GetFacetedHitterSearch(Int32?yearStart, Int32?yearEnd, Int32?maxSalary, Int32?minHomeRuns, string field, string criteria) { var query = new SolrQueryByRange <Int32>("year", yearStart.Value, yearEnd.Value, true) && new SolrQueryByRange <Int32>("salary", 0, maxSalary.Value) && new SolrQueryByRange <Int32>("homeruns", minHomeRuns.Value, 500) && new SolrQuery(String.Format("{0}:{1}", field, criteria)); var options = GetFactedQueryOptions(minHomeRuns.Value); var results = _ctx.Query(query, options); var searchModel = new HitterSearchViewModel(); SetSearchModelMainResults(results, searchModel); searchModel.OriginalCriteria = new HitterSearch() { MaxSalary = maxSalary.Value, MinHomeRuns = minHomeRuns.Value, YearEnd = yearEnd.Value, YearStart = yearStart.Value }; GenerateFacetedSearchCategories(results, searchModel); searchModel.NumberFound = results.NumFound; searchModel.RecordsShown = results.Count; return(searchModel); }
public HitterSearchViewModel GetHitterSearch(HitterSearch criteria) { var query = new SolrQueryByRange <Int32>("year", criteria.YearStart, criteria.YearEnd, true) && new SolrQueryByRange <Int32>("salary", 0, criteria.MaxSalary) && new SolrQueryByRange <Int32>("homeruns", criteria.MinHomeRuns, 500); var options = GetFactedQueryOptions(criteria.MinHomeRuns); var results = _ctx.Query(query, options); var searchModel = new HitterSearchViewModel(); SetSearchModelMainResults(results, searchModel); searchModel.OriginalCriteria = criteria; GenerateFacetedSearchCategories(results, searchModel); searchModel.NumberFound = results.NumFound; searchModel.RecordsShown = results.Count; return(searchModel); }
private static void GenerateFacetedSearchCategories(SolrQueryResults <Hitter> results, HitterSearchViewModel searchModel) { searchModel.Categories = new Dictionary <String, HitterCategory>(); foreach (var category in results.FacetQueries) { var categoryinfo = category.Key.Split(new char[] { ':' }, StringSplitOptions.RemoveEmptyEntries); if (searchModel.Categories.ContainsKey(categoryinfo[0])) { //key exists, just add the item info searchModel.Categories[categoryinfo[0]].Items.Add(new CategoryItem() { Count = category.Value, Item = categoryinfo[1].TrimStart('[').TrimEnd(']'), ItemCriteria = categoryinfo[1] }); } else { //key doesn't exist...create it searchModel.Categories.Add(categoryinfo[0], new HitterCategory() { CategoryField = categoryinfo[0], Items = new List <CategoryItem>() { new CategoryItem() { Count = category.Value, Item = categoryinfo[1].TrimStart('[').TrimEnd(']'), ItemCriteria = categoryinfo[1] } } }); } } }
private static void SetSearchModelMainResults(SolrQueryResults <Hitter> results, HitterSearchViewModel searchModel) { searchModel.SearchResults = results.Select(r => new HitterSearchResult { Average = r.Average, Doubles = r.Doubles, FirstName = r.FirstName, Hits = r.Hits, HomeRuns = r.HomeRuns, Id = r.Id, LahmanId = r.LahmanId, LastName = r.LastName, PlayerId = r.PlayerId, RunsBattedIn = r.RunsBattedIn, Salary = r.Salary, StrikeOuts = r.StrikeOuts, TeamName = r.TeamName, Triples = r.Triples, Year = r.Year }).ToList(); }