/// <summary> /// Method is used for populating a request model from Query String parameters. If you need to add populating any extra parameters - just override this method. /// IMPORTANT! This method is executed during building a query for search and shouldn't be called in another places. /// </summary> protected virtual void PopulateFromQueryString(ISearchRequestModel model) { if (!SearchConfiguration.LoadQueryString || !string.IsNullOrWhiteSpace(model.SearchBoxQuery) || (model.Filters != null && model.Filters.Any())) { Logging.Log.Debug("Loading search parameters from query string is disabled"); return; } if (String.IsNullOrWhiteSpace(model.CurrentUrl)) { Logging.Log.Debug("Loading search parameters from query string is impossible due the HttpContext is null."); return; } var url = new Sitecore.Text.UrlString(model.CurrentUrl); if (url.Parameters.Count < 1) { Logging.Log.Debug("There is no any query string parameters in the current request."); return; } var query = url.Parameters.Get("q"); if (!string.IsNullOrWhiteSpace(query)) { var decoded = HttpUtility.UrlDecode(query); model.SearchBoxQuery = decoded; } var parameterBlacklist = new [] { "sc_itemid", "sc_mode", "sc_lang", "sc_site" }; var querystrings = url.Parameters.ToKeyValues().Where(q => q.Key != "q" && !parameterBlacklist.Contains(q.Key) && !string.IsNullOrWhiteSpace(q.Value)).ToList(); if (!querystrings.Any()) { return; } model.Filters = querystrings.Select(q => new FilterModel { FieldName = q.Key, FieldValue = q.Value }).ToList(); var filter = model.Filters.LastOrDefault(); if (filter != null) { model.LastChangedFilterName = filter.FieldName; } }
/// <summary> /// Method is used for populating a request model from Query String parameters. If you need to add populating any extra parameters - just override this method. /// IMPORTANT! This method is executed during building a query for search and shouldn't be called in another places. /// </summary> protected virtual void PopulateFromQueryString(ISearchRequestModel model) { if (!SearchConfiguration.LoadQueryString) { Logging.Log.Debug("Loading search parameters from query string is disabled"); return; } if (HttpContext.Current == null) { Logging.Log.Debug("Loading search parameters from query string is impossible due the HttpContext is null."); return; } if (HttpContext.Current.Request.QueryString.Count < 1) { Logging.Log.Debug("There is no any query string parameters in the current request."); return; } var query = HttpContext.Current.Request.QueryString["q"]; if (!string.IsNullOrWhiteSpace(query)) { model.SearchBoxQuery = query; } var querystrings = HttpContext.Current.Request.QueryString.ToKeyValues().Where(q => q.Key != "q").ToList(); if (!querystrings.Any()) { return; } model.Filters = querystrings.Select(q => new FilterModel { FieldName = q.Key, FieldValue = q.Value }).ToList(); var filter = model.Filters.LastOrDefault(); if (filter != null) { model.LastChangedFilterName = filter.FieldName; } }