.InField with string argument

Member since: 2017

Hi!

I'm trying to use method InField with a string argument, but it doesn't seem to work.

            return client.Search<ProductPage>()
                .For(searchQuery)
                .InField(i => i.FullName)
                .GetPagesResult(); // returns results

            return client.Search<ProductPage>()
                .For(searchQuery)
                .InField("FullName")
                .GetPagesResult(); // doesn't return any result

What can be the problem?

#182225 Sep 12, 2017 17:26
  • Member since: 2017

    I've found the solution. The quick answer is:

                return client.Search<ProductPage>()
                    .For(searchQuery)
                    .InField("FullName$$string.en")
                    .GetPagesResult();

    I've studied sources of InField method. There is a call of FieldNameConvention method inside. So, I've found the correct format calling this method:

    Expression<Func<ProductPage, string>> expression = page => page.FullName;
    var fieldName = client.Conventions.FieldNameConvention.GetFieldNameForSearch((Expression)expression, Language.English);

    #182250 Sep 13, 2017 13:37
  • Member since: 2010

    I think this approach will work for normal string (short string) properties and not for xhtml properties. For xhtml properties, JSON nested fields are generated. You can use the explore option in find interface to exactly know the field name if hard-coding the name works for you.

    #182263 Sep 13, 2017 17:22