Пример #1
0
 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 ProductView {
             Products = matchingProducts,
             Search = parameters,
             TotalCount = matchingProducts.NumFound,
             Facets = matchingProducts.FacetFields,
             DidYouMean = GetSpellCheckingResult(matchingProducts),
         };
         return View(view);
     } catch (InvalidFieldException) {
         return View(new ProductView {
             QueryError = true,
         });
     }
 }
Пример #2
0
 public ProductView()
 {
     Search = new SearchParameters();
     Facets = new Dictionary<string, ICollection<KeyValuePair<string, int>>>();
     Products = new List<SolrTitle>();
 }
 public SortOrder[] GetSelectedSort(SearchParameters parameters)
 {
     return new[] { SortOrder.Parse(parameters.Sort) }.Where(o => o != null).ToArray();
 }
 /// <summary>
 /// Gets the selected facet fields
 /// </summary>
 /// <param name="parameters"></param>
 /// <returns></returns>
 public IEnumerable<string> SelectedFacetFields(SearchParameters parameters)
 {
     return parameters.Facets.Select(f => f.Key);
 }
 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();
 }
 /// <summary>
 /// Builds the Solr query from the search parameters
 /// </summary>
 /// <param name="parameters"></param>
 /// <returns></returns>
 public ISolrQuery BuildQuery(SearchParameters parameters)
 {
     if (!string.IsNullOrEmpty(parameters.FreeSearch))
         return new SolrQuery(parameters.FreeSearch);
     return SolrQuery.All;
 }
Пример #7
0
 /// <summary>
 /// Builds the Solr query from the search parameters
 /// </summary>
 /// <param name="parameters"></param>
 /// <returns></returns>
 public ISolrQuery BuildQuery(SearchParameters parameters)
 {
     if (!string.IsNullOrEmpty(parameters.FreeSearch))
         return new SolrQuery("Name:" + parameters.FreeSearch + "*");  //TODO: Just until I change the default in Lucene to Name and figure out contains..
     return new SolrQueryByField("Type", "Title");
 }