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

.InField with string argument

Vote:
 

Hi!

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

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

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

What can be the problem?

#182225
Sep 12, 2017 17:26
Vote:
 

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
Vote:
 
<p>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.</p>
#182263
Sep 13, 2017 17:22
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* 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.