Home Gitesh Portfolio Blog About Me Gallery Contact

Sitecore: Get values from the Search database

Get values from the SOLR/Lucene Search database.


 

List searchItems;
 
using (var context = ContentSearchManager.GetIndex("news_{0}_index".ToFormattedString(Sitecore.Context.Database.Name.ToLower())).CreateSearchContext())
{
	searchItems = context.GetQueryable()
		.Where(p => p.TemplateId == NewsTemplateIDs.News)
		.Where(p => p["ShowInNewsFilter"] == "1")
		.Where(p => p["RelatedRegions"] != "")
		.Where(p => p["RelatedRegions"].Contains(region))
		.OrderByDescending(p => p["ShowOnRegionalLandingPage"])
		.ThenByDescending(p => p["ReleaseDate"])
		.Take(10)
		.ToList();
}

foreach (SearchResultItem sritem in searchItems)
{
	Item item = sritem.GetItem();
	if (item != null)
	{
		#region get individual news items
		var news = MappingItemToNewsModel(item);

		items.Add(news);
		model.Items = items;
		#endregion get individual news items
	}
}

Posted: 27/05/2022 2:56:29 p.m. by Gitesh Shah | with 0 comments