Skip to content

Instantly share code, notes, and snippets.

@gopigujjula
Created October 20, 2018 17:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gopigujjula/9c4df5b16bdb900c75ddced354c9cc7b to your computer and use it in GitHub Desktop.
Save gopigujjula/9c4df5b16bdb900c75ddced354c9cc7b to your computer and use it in GitHub Desktop.
using Sitecore.ContentSearch;
using Sitecore.ContentSearch.SearchTypes;
using Sitecore.ContentSearch.SolrProvider.SolrNetIntegration;
using SolrNet;
using SolrNet.Commands.Parameters;
using System.Web.Mvc;
namespace SC9SolrDemo.Controllers
{
public class GroupController : Controller
{
public ActionResult Index()
{
string searchText = Request.QueryString["text"] ?? string.Empty;
if (string.IsNullOrEmpty(searchText))
return View();
var queryOptions = new QueryOptions
{
Grouping = new GroupingParameters
{
Fields = new[] { "type_t" },
Limit = 10
}
};
var indexName = $"sitecore_{Sitecore.Context.Database.Name}_index";
var index = ContentSearchManager.GetIndex(indexName);
SolrQueryResults<SearchResultItem> results;
using (var context = index.CreateSearchContext())
{
results = context.Query<SearchResultItem>($"(language_t:{searchText})", queryOptions);
}
return View(results);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment