As I describe in this blog post http://world.episerver.com/blogs/Henrik-Fransas/Dates/2015/2/how-to-do-custom-query-and-click-tracking-with-episerver-find/ it is possible to enable click tracking for more than unified search.
Now I have run into problem with that when trying to get HitId and HitType when using projections.
I am trying to minimize what are returned by the server together with doing a multisearch and for that I am using projections.
The problem is that when I use these functions:
HitId = _searchClient.Conventions.IdConvention.GetId(h),
HitType = _searchClient.Conventions.TypeNameConvention.GetTypeName(h.GetType())
I get an error like this:
An exception of type JsonSerializationException was thrown while deserializing object.
With the inner exception:
"Error setting value to 'IsPendingPublish' on '[pagetype]'."
If I comment out these two lines it works great with the projection.
Anyone know how to get this to work or to work around it to get projections to work?
Henrik Lindström helped me out with the answer.
This is because it triggers Find to referens and trying to serielize the whole PageData object and this wount work.
The way to solve it is to use IncludeField.
Start by creating extension methods to PageData like this:
public static string HitId(this PageData page)
public static string HitType(this PageData page)
Then in your class that defines what to or not to index (if you have one of those) add this:
SearchClient.Instance.Conventions.ForInstancesOf<PageData>().IncludeField(p => p.HitId());
SearchClient.Instance.Conventions.ForInstancesOf<PageData>().IncludeField(p => p.HitType());
Reindex all and then use the new property like this:
HitId = h.HitId(),
HitType = h.HitType()
It works great!Thanks again Henrik!