Examine Search using class instances
# help-with-umbraco
j
I have an Article doctype and an TeamMember doctype. Each Article has one TeamMember (alias of 'authorTeamMember'). Can I use Examine to search for all articles where the authorTeamMember field is equal to a specific TeamMember? I was hoping for something like this:
Copy code
public IEnumerable<IPublishedContent> SearchContentByTeamMember(TeamMember teamMember)
{
    IEnumerable<string> ids = Array.Empty<string>();
    if (_examineManager.TryGetIndex(Constants.UmbracoIndexes.ExternalIndexName, out IIndex? index))
    {
        ids = index
            .Searcher
            .CreateQuery("content")
            .Field("authorTeamMember", teamMember)
            .Execute()
            .Select(x => x.Id);
    }
    
    throw new NotImplementedException();
}
...but "Field" isn't happy (see image). Any advice on this? TIA!
m
Presumably "authorTeamMember" being a doctype is in the examine index as a udi/guid/id? (depends on the properditor you use to select the teammember) so would be "teamMember.Id" or such like for you fieldValue?
d
If you want to know how your value is indexed, I'd recommend checking out the examine manager and see what the value looks like in the index. What you see there is what you need to pass into this method. Likely an id or guid. If the indexed value is in an inconvenient format, you can enrich your index with values that are better suited for your needs
j
OK so what I think my problem boils down to is searching for a field within a Content Picker's section. 1. "Articles" have a Content Picker property with alias "authorTeamMember" 2. The content picked by "authorTeamMember" has a field called "displayName" What's the .Field() query for picking that up? I've tried
.Field("authorTeamMember.displayName", "Richard Jackson")
but that isn't picking up anything. Full query:
Copy code
ids = index
    .Searcher
    .CreateQuery("content")
    .NodeTypeAlias("article")
    .And()
    .Field("authorTeamMember.displayName", "Richard Jackson") 
    .Execute()
    .Select(x => x.Id);
Sidenote: is there a way to write and run Field searches to test what they'd come back as in the backoffice? Feels like that would be useful for testing.