示例#1
0
 //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,
         });
     }
 }
示例#2
0
 public SortOrder[] GetSelectedSort(SearchParameters parameters)
 {
     return new[] { SortOrder.Parse(parameters.Sort) }.Where(o => o != null).ToArray();
 }
示例#3
0
 public ISolrQuery BuildQuery(SearchParameters parameters)
 {
     if (!string.IsNullOrEmpty(parameters.FreeSearch))
         return new SolrQuery(parameters.FreeSearch);
     return SolrQuery.All;
 }
示例#4
0
 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();
 }
示例#5
0
 public IEnumerable<string> SelectedFacetFields(SearchParameters parameters)
 {
     return parameters.Facets.Select(f => f.Key);
 }
示例#6
0
 public SolrViewModel()
 {
     Search = new SearchParameters();
     Facets = new Dictionary<string, ICollection<KeyValuePair<string, int>>>();
     Products = new List<Product>();
 }