I'm trying to create an autocomplete control that returns items stored in a bucket however I seem to be having issues with my search query.
I've created a custom index and can see the items within the index however when I try to search the index using the ContentSearchManager
I'm not getting the results I expect.
My current code is:
using (var context = index.CreateSearchContext())
{
const string Id = "{2E1D94CD-DF46-4B45-B3F9-66A002C20CCA}";
Expression<Func<Symptom, bool>> predicate = s => s.TemplateId == new Sitecore.Data.ID(Id) &&
s.LaymanDescription.Contains(search);
var results = context.GetQueryable<Symptom>().Where(
predicate).ToList();
}
As an example I have 2 symptom items
- Hair Loss
- Hair Loss loss on scalp
It seems that if I search "hair loss on" I still get the hair loss item back. I wasn't expecting this. Looking at the search query in the logs it seems that "hair loss on" is split and then searched on individually.
- How can I stop the query being split? Am I using correct method for querying?
- How can I return results based on a partial search? e.g if I search on "Hair Lo" I want both the "Hair Loss" and "Hair Loss on scalp", if I search on "Hair Loss o" then I want the "Hair Loss on scalp" returned only.