public ActionResult FacetSearch(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 = _solr.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 View("Results", searchModel);
        }
        public ActionResult Search(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 = _solr.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 View("Results", 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();
 }