This is my code for searching a data in the specified index:
using (var context = ContentSearchManager.GetIndex(Common.Constants.IndexNames.PlotTreeIndexName).CreateSearchContext())
{
var plotTreeQuerable = context.GetQueryable<UserPlottedTreeSearchResultItem>()
.Where(m => m.LatestVersion)
.Where(m => m.TemplateId == new Sitecore.Data.ID(Common.Constants.TemplateIDs.UserPlottedTreePageTemplateId));
List<UserPlottedTreeSearchResultItem> results = new List<UserPlottedTreeSearchResultItem>();
if (!string.IsNullOrEmpty(searchTerm))
{
var predicate = PredicateBuilder.True<UserPlottedTreeSearchResultItem>();
if (typeOfSearch.ToUpper() == Constants.SearchTerm.EmailAddress.ToUpper())
{
predicate = predicate.Or(m => m.PersonEmail.Equals(searchTerm));
}
else if (typeOfSearch.Equals(Constants.SearchTerm.NameOfThePerson, StringComparison.OrdinalIgnoreCase))
{
predicate = predicate.Or(m => m.PersonName.Equals(searchTerm, StringComparison.InvariantCultureIgnoreCase));
}
else
{
foreach (var t in searchTerm.Trim().Split(' '))
{
predicate = predicate.Or(m => m.PersonName.Contains(t) || m.PersonEmail.Contains(t));
}
}
plotTreeQuerable = plotTreeQuerable.Where(predicate);
}
if (plotTreeQuerable.Count() > 0)
{
results = plotTreeQuerable.ToList();
return results;
}
}
The string in m.PersonEmail
should be case-insensitive. I tried the following code with their respective results:
test search value: test.Val
sample dataset/list:
test.val
test.Val
Test.val
TEST.VAL
predicate = predicate.Or(m => m.PersonEmail.Equals(searchTerm, StringComparison.OrdinalIgnoreCase))
Result: only returns test.Val
predicate = predicate.Or(m => m.PersonEmail.Contains(searchTerm))
same result: (returns test.Val
)
Any reason as to why my code doesn't work? it should return all data from the dataset/list. First code doesn't seem to respect the StringComparison.OrdinalIgnoreCase