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

Problems with highlighting projections

Vote:
 

Hi all,

After upgrading to Find 9.2 we have some problems with our highlighting projections. Instead of the correct pre- and post tags "|pre|" and "|post|" are returned.

This is the projection:

SearchClient.Instance.Conventions.UnifiedSearchRegistry.Add()
                .ProjectHighlightedExcerptUsing(hitSpec => d => d.SearchText()
                    .AsHighlighted(new HighlightSpec
                    {
                        FragmentSize = hitSpec.ExcerptLength,
                        PreTag = hitSpec.PreTagForAllHighlights,
                        PostTag = hitSpec.PostTagForAllHighlights
                    }))
                .ProjectUrlFrom(d => d.Url);

The result of this projection is for example "lorem ipsum |pre|myhighlightedword|post| lorem ipsum". It was working before the upgrade. 

Bug?

#120548
Apr 20, 2015 13:09
Vote:
 

Hi Gustav,

We are looking into that right now. We have made some changes in that area but that was quite a long time ago. May I inquire from what version you are upgrading?

/Marcus

#120550
Apr 20, 2015 13:24
Vote:
 

Ok, great.

It's been a while since our last upgrade, we are upgrading from version 8.10.0.1509.

/Gustav

#120551
Apr 20, 2015 13:35
Vote:
 

Can you post your query with your HitSpecification defined?

/Henrik

#120629
Apr 21, 2015 13:56
Vote:
 

Sure:

var hitSpecification = new HitSpecification
            {
                HighlightExcerpt = true,
                HighlightTitle = false,
                PreTagForAllHighlights = "<b>",
                PostTagForAllHighlights = "</b>",
                ExcerptLength = 200
            };

            if (!string.IsNullOrWhiteSpace(query))
            {
                var searchQuery = SearchClient.Instance.UnifiedSearchFor(query, Language.Swedish)
                    .UsingSynonyms()
                    .WithAndAsDefaultOperator()
                    .BoostMatching(h => h.MatchType(typeof(QuickAnswerPage)) |
                                        h.MatchType(typeof(GuidePage)) |
                                        h.MatchType(typeof(ServicePage)), 2)
                    //.ApplyBestBets()
                    .Skip((page - 1)*PageSize)
                    .Take(PageSize);

                if (type != FilterOptions.All)
                {
                    searchQuery = searchQuery.FilterHits(
                            h => h.SearchTypeName.Match(GetTypeForFilter(typeFilter).Name)
                        );
                }
                    
                searchQuery = searchQuery.TermsFacetFor(x => x.SearchTypeName)
                                         .Track();

                searchResult = searchQuery.GetResult(hitSpecification);                    
            }

/Gustav

#120631
Apr 21, 2015 14:37
Vote:
 

We have indeed identified it as a bug. We resolved the bug and the fix will be included it in the next release. You can use the following workaround in order for you to get your solution working:

1) Add an extension to your indexed object like below:

   public static class NativeSearchContentExtensions
    {
        public static string Text(this NativeSearchContent content)
        {
            return content.SearchText;
        }
    }

2) Add Index convention and index your object

client.Conventions.ForInstancesOf<NativeSearchContent>()
                .IncludeField(x => x.Text());

client.Index(mySearchContent);

2) add your convention 

       client.Conventions.UnifiedSearchRegistry.Add<NativeSearchContent>()
                .ProjectHighlightedExcerptUsing<NativeSearchContent>(hitSpec => d => d.Text().AsHighlighted(new HighlightSpec
                {

                    PreTag = hitSpec.PreTagForAllHighlights,
                    PostTag = hitSpec.PostTagForAllHighlights
                }))
                .ProjectTitleFrom<NativeSearchContent>(d => d.SearchText);

3) Search

var hitSpecification = new HitSpecification
            {
                HighlightExcerpt = true,
                HighlightTitle = false,
                PreTagForAllHighlights = "|start|",
                PostTagForAllHighlights = "|end|",
                ExcerptLength = 200
            };

            client.UnifiedSearchFor("Bacon").GetResult(hitSpecification)

/David

#120682
Apr 22, 2015 13:26
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.