/// <summary> /// Search for content using an instance of <see cref="EdismaxSolrQuery"/>. /// </summary> public SolrQueryResults <PageContentResultItem> Search( string q, Item solrQueryItem, int startRow = 0, string language = "", string facetValue = "") { // TODO: custom business logic here. EdismaxSolrQuery query = BuildEdismaxSolrQueryFromItem(solrQueryItem); return(Search(q, query, startRow, language, facetValue)); }
/// <summary> /// Returns the search results rendering. /// </summary> public ActionResult SearchResults(string q, int pageNumber = 1, string facet = "") { // Get the rendering datasource item. Item datasourceItem = GetDatasourceItem(); // Convert Sitecore item into a EdismaxSolrQuery. EdismaxSolrQuery query = _searchService.BuildEdismaxSolrQueryFromItem(datasourceItem); // Build the model. var model = new SearchResultsViewModel { Query = q, SearchResults = new SolrQueryResults <PageContentResultItem>(), PageNumber = pageNumber, Facet = facet }; // Execute the Search. if (datasourceItem != null && !string.IsNullOrWhiteSpace(q)) { // Convert 1-based pageNumber to 0-based pageIndex. int pageIndex = pageNumber > 0 ? pageNumber - 1 : 0; int startRow = pageIndex * query.Rows; // Execute the search. model.SearchResults = _searchService.Search(q, query, startRow, facetValue: facet); } // Page the results. model.PagedResults = new StaticPagedList <PageContentResultItem>( model.SearchResults, pageNumber, query.Rows, model.SearchResults.NumFound ); // Facet Counts. model.FacetCounts = BuildFacetCounts(model).ToArray(); // Determine the selected Facet Name. Guid selectedFacetId = Guid.Empty; if (Guid.TryParse(facet, out selectedFacetId)) { model.FacetName = DetermineFacetName(model, selectedFacetId); } // Send the model to the view. return(View(Views.SearchResults, model)); }
/// <summary> /// Search for content using a Sitecore <see cref="Item"/>. /// </summary> public SolrQueryResults <PageContentResultItem> Search( string q, EdismaxSolrQuery query, int startRow = 0, string language = "", string facetValue = "") { // TODO: custom business logic here // Filter by facet. var filters = new List <ISolrQuery>(); if (!string.IsNullOrWhiteSpace(query.FacetField) && !string.IsNullOrWhiteSpace(facetValue)) { filters.Add(new SolrQueryByField(query.FacetField, facetValue)); } return(EdismaxSearch <PageContentResultItem>(q, query, startRow, language, filters)); }