I am trying to fetch List of articles using Solr Search context. This is the code block trying to fetch the results.
var searchIndex = ContentSearchManager.GetIndex(indexName); // Get the search index
var searchPredicate = GetSearchPredicate(false, speciality, category,
filterModel.Specific_Speciality, true); // Build the search predicate
using (var searchContext = searchIndex.CreateSearchContext()) // Get a context of the
search index
{
var searchResults = (IQueryable<SearchModel>)null;
{
searchResults = searchContext.GetQueryable<SearchModel>().Where(searchPredicate).OrderByDescending(i => i.CreatedOn);//.Where(searchPredicate)
searchResults = searchResults.Where(i => i.Category.Equals(category) && i.Category != "Cardio news").Take(count);
}
var fullResults = searchResults.GetResults();
fullResults
contains zero results after execution.
I checked the Search.Config
to get the Solr query.
?q=((category_t:("News") AND _templatename:("News Article")) AND _latestversion:("True")) AND _val_:__boost&start=4&rows=4&fl=*,score&fq=_indexname:(sitecore_master_index)&wt=xml&sort=createddate_tdt desc
I executed this query in Solr and it returned zero results.
When I searched for category_t
in the Solr index, I noticed that the category field is getting indexed as category_s
not category_t
. Hence returning zero results.
Update - #1
I checked the search predicate and the search model as well.
[IndexField("category_t")] public virtual string Category { get; set; }
Search model is referencing category_t
. I made the changes in search model making category_s
instead of category_t
.
Also, my predicate code is referring to category_s
field.
After updating the model, I did restarted the IIS and did the index rebuilding.
I am still seeing same query in the Search.Config
file.