//private string GetSpellCheckingResult(ISolrQueryResults<Product> products) //{ // return string.Join(" ", products.SpellChecking // .Select(c => c.Suggestions.FirstOrDefault()) // .Where(c => !string.IsNullOrEmpty(c)) // .ToArray()); //} public ActionResult Index(SearchParameters parameters) { try { var start = (parameters.PageIndex - 1) * parameters.PageSize; var matchingProducts = solr.Query(BuildQuery(parameters), new QueryOptions { FilterQueries = BuildFilterQueries(parameters), Rows = parameters.PageSize, Start = start, OrderBy = GetSelectedSort(parameters), SpellCheck = new SpellCheckingParameters(), Facet = new FacetParameters { Queries = AllFacetFields.Except(SelectedFacetFields(parameters)) .Select(f => new SolrFacetFieldQuery(f) { MinCount = 1 }) .Cast<ISolrFacetQuery>() .ToList(), }, }); var view = new SolrViewModel { Products = matchingProducts, Search = parameters, TotalCount = matchingProducts.NumFound, Facets = matchingProducts.FacetFields//, // DidYouMean = GetSpellCheckingResult(matchingProducts), }; return View(view); } catch (InvalidFieldException) { return View(new SolrViewModel { QueryError = true, }); } }
public SortOrder[] GetSelectedSort(SearchParameters parameters) { return new[] { SortOrder.Parse(parameters.Sort) }.Where(o => o != null).ToArray(); }
public ISolrQuery BuildQuery(SearchParameters parameters) { if (!string.IsNullOrEmpty(parameters.FreeSearch)) return new SolrQuery(parameters.FreeSearch); return SolrQuery.All; }
public ICollection<ISolrQuery> BuildFilterQueries(SearchParameters parameters) { var queriesFromFacets = from p in parameters.Facets select (ISolrQuery)Query.Field(p.Key).Is(p.Value); return queriesFromFacets.ToList(); }
public IEnumerable<string> SelectedFacetFields(SearchParameters parameters) { return parameters.Facets.Select(f => f.Key); }
public SolrViewModel() { Search = new SearchParameters(); Facets = new Dictionary<string, ICollection<KeyValuePair<string, int>>>(); Products = new List<Product>(); }