Click tracking still not working

Vote:
 

I tried today to enable click tracking again after applying the latest update of Find and I can still not get it to work.

I have added @Html.RequiredClientResources(RenderingTags.Header) in the header and @Html.RequiredClientResources(RenderingTags.Footer) in the body.

The url in the result looks like this:

http://localhost:37005/jobb/Jobbsokartips/Vad-ar-en-kompetensexpert/?_t_id=NNBa49GSHvbWIIh6mQee8Q%3d%3d&_t_q=&_t_tags=language%3asv&_t_ip=%3a%3a1&_t_hit.id=CUSTOMER_Web_Models_Pages_StandardPage/_daf06644-a8a0-441a-859d-af7f0d91242f_sv&_t_hit.pos=1

So it seems like the url is correct.

The problem I get is that when clicking that url I get two 400-request, first this one:

http://localhost:37005/find_v2/_track?id=NNBa49GSHvbWIIh6mQee8Q&q=&tags=language:sv&ip=::1&hit.id=CUSTOMER_Web_Models_Pages_StandardPage/_c4d89f05-1660-4e61-a8d6-dc34b621d4d2_sv&hit.pos=4

That one gives this response
Bad Request

And directly after that I get a 400 on this url
http://es-api01.episerver.com/b4oGn4czRFzH19qEVsAigfi7H1yKMi6e/customersite_localhost/_track?id=NNBa49GSHvbWIIh6mQee8Q&q=&tags=language:sv&ip=::1&hit.id=CUSTOMER_Web_Models_Pages_StandardPage/_c4d89f05-1660-4e61-a8d6-dc34b621d4d2_sv&hit.pos=4

That url gives the response
message=validation failed: 'q' must not be empty

Anyone got this working?

#112521
Oct 29, 2014 13:37
Vote:
 

Can you post the actual query that you are executing (the .net part). It seems like query lookup fails as you get an empty 'q' parameter in the urls.

/Henrik 

#112529
Oct 29, 2014 15:58
Vote:
 

This is how the query is built up (Pretty complicated)

public SearchResult<OtherSearchResultItem> SearchOther(string query, int take = 20, int skip = 0, string orderBy = "", string sortOrder = "asc")
        {
            var key = string.Format("SearchOther_q:{0}_t:{1}_s:{2}_o:{3}_so:{4}", query, take, skip, orderBy, sortOrder);

            var result = CacheManager.Get(key);
            if (result != null)
            {
                return (SearchResult<OtherSearchResultItem>)result;
            }


            var totalStopWatch = new Stopwatch();
            totalStopWatch.Start();

            var returnSearchResult = new SearchResult<OtherSearchResultItem>();

            try
            {
                var searchQuery = SearchClient.Instance.UnifiedSearchGraspingRightHandTruncationFor(query,
                                                                                                    Language.Swedish)
                                                .Filter(f => !f.MatchType(typeof (EducationInfoToIndex)))
                                                .Filter(f => !f.MatchType(typeof (Jobbannons)))
                                                .Filter(f => !f.MatchType(typeof (OfficeInfoToIndex)))
                                                .Filter(f => !f.MatchType(typeof (ContactPersonToIndex)))
                                                .TermsFacetFor(x => x.SearchTypeName, x => { x.Size = 200; });
               var searchResult = searchQuery.Skip(skip).Take(take).Track().StaticallyCacheFor(TimeSpan.FromSeconds(60)).GetResult();

                returnSearchResult = new SearchResult<OtherSearchResultItem>
                    {
                        TotalCount = searchResult.TotalMatching,
                        ResultItems = searchResult.Hits.Select(h => new OtherSearchResultItem()
                            {
                                Title = h.Document.Title,
                                OtherType = TranslateTypeName(h.Document.TypeName),
                                Description = h.Document.Excerpt,
                                LinkUrl = h.Document.Url,
                                CssClass = h.Document.FileExtension
                            }).ToList(),
                        Facets = new List<FilterFacet>
                            {
                                new FilterFacet()
                                    {
                                        Name = "Typ",
                                        Terms =
                                            searchResult.TermsFacetFor(t => t.SearchTypeName)
                                                        .Terms.Select(
                                                            t =>
                                                            new FilterTerm()
                                                                {
                                                                    Name = TranslateTypeName(t.Term),
                                                                    TotalCount = t.Count
                                                                }).OrderBy(x => x.Name)
                                                        .ToList()
                                    },
                            }
                    };

                if (take == 1000 && searchResult.TotalMatching > 1000)
                {
                    var nextBatchFrom = 1000;
                    while (nextBatchFrom < searchResult.TotalMatching)
                    {
                        searchResult = searchQuery.Skip(nextBatchFrom).StaticallyCacheFor(TimeSpan.FromSeconds(60)).GetResult();
                        returnSearchResult.ResultItems.AddRange(
                            searchResult.Hits.Select(h => new OtherSearchResultItem()
                                {
                                    Title = h.Document.Title,
                                    OtherType = h.Document.TypeName,
                                    Description = h.Document.Excerpt,
                                    LinkUrl = h.Document.Url.ToLowerInvariant(),
                                    CssClass = h.Document.FileExtension
                                }));
                        nextBatchFrom += 1000;
                    }
                }


            }
            catch (Exception exception)
            {
                _logger.Error("EPiServer Find ligger nere", exception);
            }

            totalStopWatch.Stop();

            CacheManager.RuntimeCacheInsert(key, returnSearchResult, null, DateTime.Now.AddMinutes(Helpers.Constants.OtherSearchCacheTimeToLive), Cache.NoSlidingExpiration);

            return returnSearchResult;
           

        }

The function UnifiedSearchGraspingRightHandTruncationFor looks like this:

public static class SearchExtensions
    {

        public static IQueriedSearch<ISearchContent> UnifiedSearchGraspingRightHandTruncationFor(this IClient client, string query, Language language)
        {
            language = language ?? Language.None;
            return client.Search<ISearchContent>(language).GraspingRightHandTruncationFor<ISearchContent>(query).WithAndAsDefaultOperator().InAllField();
        }

        public static IQueriedSearch<TSource, QueryStringQuery> GraspingRightHandTruncationFor<TSource>(this ITypeSearch<TSource> search, string queryString)
        {
            if (search == null)
            {
                throw new ArgumentNullException("search");
            }
            
            var str = (string.IsNullOrWhiteSpace(queryString) ? "" : queryString);

            str += !str.Contains("\"") ? "*" : "";

            return new Search<TSource, QueryStringQuery>(search, (ISearchContext context) =>
            {
                var queryStringQuery = new QueryStringQuery(str);
                queryStringQuery.RawQuery = queryString;
                var queryStringQuery1 = queryStringQuery;
                context.RequestBody.Query = queryStringQuery1;
            });
        }
    }

I hope the grasping would be built in the product soon (we come from SiteSeeker and it exists there, so the customer needed to keep it)

#112533
Oct 29, 2014 16:27
Vote:
 

I have now removed my extension with the grasping so now I do not get the error and it works for the unified search.

#114368
Dec 11, 2014 8:02
Vote:
 

I have just published a blog post on how to do this for more than just unified search:

http://world.episerver.com/blogs/Henrik-Fransas/Dates/2015/2/how-to-do-custom-query-and-click-tracking-with-episerver-find/

#117973
Feb 25, 2015 11:17
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.