2

I am working on a search functionality to return items with certain template, location of the folder to look for in, and has the item name:

var predicate = PredicateBuilder.True<SearchResultItem>();

using (var context = ContentSearchManager.GetIndex(GetSiteIndexName()).CreateSearchContext())
{
    ID recruitersBioBlocksFolderId = new ID(EmbraceGuids.RecruitersBioBlocksFolderId);
    ID recruiterTemplateId = new ID(EmbraceGuids.RecruiterContentBlockTemplateID);

    if (!string.IsNullOrEmpty(recruiter))
    {
        predicate = predicate.And(x => x.TemplateId == recruiterTemplateId);
        predicate = predicate.And(x => x.Paths.Contains(recruitersBioBlocksFolderId));
        predicate = predicate.And(x => x.Name.Contains(recruiter));
    }

    var queryable = context.GetQueryable<SearchResultItem>().Where(predicate);

It was working fine before adding the last predicate:

predicate = predicate.And(x => x.Name.Contains(recruiter));

However, when I add the previous predicate to search for the item name with string i pass to this function, it doesn't work.

Any idea why isn't it working?

Thanks,

  • 1
    What do you mean with "is not working"? Do you get no results? Can you check the search query in the logs and test it with Luke on your index to see whether there should be any result for that query? – Gatogordo Nov 17 '16 at 13:24
  • Yes if I add this predicate to search for the item name, it doesn't return any results, but if I remove this predicate and keep the rest, it returns results. – joanelaydi Nov 17 '16 at 13:29
  • 4
    Check the search log for the query that is performed and test that on your index with Luke. – Gatogordo Nov 17 '16 at 13:30
  • Could you show us how the Name field is defined in the C# model class? Also, please include your field configuration (the .config file). – Dmytro Shevchenko Nov 17 '16 at 13:46
  • It is the one used in the Default SearchResultItem, which is the following property: [IndexField("_name")] public virtual string Name { get; set; } – joanelaydi Nov 17 '16 at 13:49