Using infiel in combination with nested queries

Should it be possible to use infield together with nested queries? For example:
public class Team
 public Team(string name)
  TeamName = name;
  Players = new List();
 public string TeamName { get; set; }
 public List Players { get; set; }
public class Player
  public string FirstName { get; set; }
  public string LastName { get; set; }
  public int Salary { get; set; }

result = client.Search()
 .Filter(x => x.Players, p => p.FirstName.Match("Cristiano") &
And in that case what is the syntax for the InField?
Feb 18, 2016 11:58

InField works for the "parent" object, in your example - Team:

clien.Search<Team>().For("my team name").InFiled(x => x.TeamName).Filter(x => x.PLayers, p => p.FirstName.Match("Christiano") & p.LastName.Match("Ronaldo")).GetResults();

Could you elaborate what are you trying to achieve?  

Feb 18, 2016 14:32

I was hoping that one could use the inField on the object (not the parent object), for example something like this:

clien.Search<Team>().For("my team name").InFiled(x => x.Players[].FirstName).Filter(x => x.PLayers, p => p.FirstName.Match("Christiano") & p.LastName.Match("Ronaldo")).GetResults();

That is, i would like to search in a field of a nested object (or several fields, but not all). One reason for specifying infields is to exclude certain fields with data and to be able to use stemmings. Any work arounds that you can see?

Edited, Feb 18, 2016 14:43

Not 100% sure if I understand what you need to do, but have you tried using MatchContained? 

var searchQuery = client.Search<BlogPost>()
    .Filter(x => x.Authors.MatchContained(
        a => a.Name, "Winston Churchill"));

Check out the documentation:

Feb 19, 2016 11:03

I would like to use infield since it allows FIND to use stemmings. As I understand it, you must use infield to specify which field to search in order for stemming to work. And in my case the property that i would like to use with stemming is on the nested object. Ex

var searchQuery = client.Search<BlogPost>(Language.Swedish)
    .Filter(x => x.Authors.MatchContained(
        a => a.Name, "Winston Churchill"));
Feb 19, 2016 13:09

Oh, I see.
I think the easiest way to do that would be to add an extension, like this:

        public static string Name(this List<Author> authors)
            throw new NotImplementedException();

and then do:

 .InField(x => x.Authors.Name())

That should do the trick.

Don't worry that the extension throws an exception. The Find engine will never actually invoke the extension method, but only look at it's name and type.

Feb 22, 2016 9:00

Thank you, i will try that!

Feb 23, 2016 15:41
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.