public ActionResult IndexPost(string searchTerm) { var query = new SolrQuery() { SearchTerm = searchTerm }; var response = searchService .Execute(query); Basket basket = basketService.GetBasket(); XElement navigation = XElement.Load(Server.MapPath(@"~\MetaData\Navigation.xml")); var model = new PageModel() { Basket = basket, Response = response, TopNavigation = navigation }; return View(model); }
public SolrResponse Execute(SolrQuery query) { String queryExtensions = null; SolrResponse solrResponse = null; query = UpdateQuery(query); if (configuration != null) { // Get facets var facets = configuration.Element("facets").Elements(); foreach (var facet in facets) { // Get queries if any var type = facet.Attribute("type").Value; var name = facet.Attribute("name").Value; switch (type) { case "Query": var queries = facet.Elements("facetQueries").Elements("facetQuery").Attributes("query"); foreach (var facetQuery in queries) { queryExtensions = queryExtensions + "&facet.query=" + facet.Attribute("name").Value + ":" + facetQuery.Value; } break; case "Field": queryExtensions = queryExtensions + "&facet.field=" + name; break; } } } using (var client = new WebClient()) { var response = client.DownloadString("http://localhost:8983/solr/browse?" + query.ToSolrQuery() + queryExtensions); var responseElement = XElement.Parse(response); solrResponse = new SolrResponse(responseElement, configuration); } var header = solrResponse.Header; return solrResponse; }
private SolrQuery UpdateQuery(SolrQuery query) { foreach (var facetQuery in query.FacetQueries) { // Try and find the facet in the configuration var facetConfiguration = configuration.XPathSelectElement(String.Format("//facet[@name='{0}']", facetQuery.Field)); if (facetConfiguration != null) { // Try and find the value represented in the query var targetFacetQuery = facetConfiguration.XPathSelectElement(String.Format(".//facetQuery[@en-GB='{0}']", facetQuery.Value)); if (targetFacetQuery != null) { // Get the actual query to be used against solr var targetQuery = targetFacetQuery.Attribute("query").Value; facetQuery.Value = targetQuery; } } } return query; }
public ActionResult Search() { var query = new SolrQuery(); var response = searchService .Execute(query); return View(response); }