Try our conversational search powered by Generative AI!

.InField with string argument



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

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

            return client.Search()
                .GetPagesResult(); // doesn't return any result

What can be the problem?

Sep 12, 2017 17:26

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

            return client.Search<ProductPage>()

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);
Sep 13, 2017 13:37
<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>
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.