November Happy Hour will be moved to Thursday December 5th.

Using infiel in combination with nested queries

Vote:
 
Hi!
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()
 .InField(FirstName)
 .Filter(x => x.Players, p => p.FirstName.Match("Cristiano") &
    p.LastName.Match("Ronaldo"))
 .GetResult();
And in that case what is the syntax for the InField?
regards
Magnus
#144747
Feb 18, 2016 11:58
Vote:
 

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?  

#144762
Feb 18, 2016 14:32
Vote:
 

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?

#144763
Edited, Feb 18, 2016 14:43
Vote:
 

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: http://world.episerver.com/documentation/Items/Developers-Guide/EPiServer-Find/11/DotNET-Client-API/Searching/Filtering/Complex-objects/

#144810
Feb 19, 2016 11:03
Vote:
 

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)
    .For(query)
    .InField(x.Authors.Name)
    .Filter(x => x.Authors.MatchContained(
        a => a.Name, "Winston Churchill"));
#144822
Feb 19, 2016 13:08
Vote:
 

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.

#144886
Feb 22, 2016 9:00
Vote:
 

Thank you, i will try that!

#144990
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.