gjshah7254
7/24/2017 - 11:41 PM

Get values from the Search database

Get values from the Search database

List<SearchResultItem> searchItems;

					using (var context = ContentSearchManager.GetIndex("news_{0}_index".ToFormattedString(Sitecore.Context.Database.Name.ToLower())).CreateSearchContext())
					{
						searchItems = context.GetQueryable<SearchResultItem>()
							.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
						}
					}