Try our conversational search powered by Generative AI!

Change title in the UnifiedSearch result

Vote:
 

Hi,

We have page:

[ContentType(GUID = "5049a00b-8ed1-49c5-92ab-a6d273b8fcd5")]
    public class ArticlePage : BasePage
    {
        [CultureSpecific]
        [Display(Order = 1)]
        public virtual string Title { get; set; }
    }

Result from UnifiedSearch contains page Name property value in the Title property. (EPiServer.Find.UnifiedSearch.UnifiedSearchHit.Title)

Is it possible to change this behaviour to the specific type? It is important because Title has different weight in the search configuration.

Best regards,

Pavel

#141367
Nov 13, 2015 10:59
Vote:
 

Add a property named SearchTitle to your content type and it will be used as title in the search result.

public virtual string SearchTitle { get { return Heading; } }

Cheers

#141433
Nov 15, 2015 17:24
Vote:
 

Hi Marcus Lindblom,

Why I can't configure this in the configuration?

For example:

client.Conventions.ForInstancesOf<ArticlePage>()
                .IncludeField(p => p.SearchTitle());

Is it possible to change indexing behaviour without adding new field to the object?

#141438
Nov 16, 2015 7:59
Vote:
 

You can configure this. Check out the unified search documentation:

http://world.episerver.com/documentation/Items/Developers-Guide/EPiServer-Find/10/DotNET-Client-API/Searching/Unified-search/

Here is an example:

client.Conventions.UnifiedSearchRegistry
                .ForInstanceOf<MySearchableClass>()
                .ProjectTitleFrom(x => x.MyTitleProperty);
#141439
Nov 16, 2015 8:45
Vote:
 

Hi,

I tried to do this but it doesn't work as expected.

Code:

[InitializableModule]
    [ModuleDependency(typeof(EPiServer.Web.InitializationModule))]
    public class SearchInitialization : IInitializableModule
    {
        public void Initialize(InitializationEngine context)
        {
            SearchClient.Instance.Conventions.UnifiedSearchRegistry
                .ForInstanceOf<ArticlePage>()
                .ProjectTitleFrom(p => p.Title);

        }

        public void Uninitialize(InitializationEngine context)
        {
        }
    }

or

            var client = ServiceLocator.Current.GetInstance<IClient>();

            client.Conventions.UnifiedSearchRegistry
                .ForInstanceOf<ArticlePage>()
                .ProjectTitleFrom(p => p.Title);

or 

         client.Conventions.UnifiedSearchRegistry
                .ForInstanceOf<ArticlePage>()
                .ProjectTitleFrom(p => p.SearchTitle());

doesn't work.

If I add 'SearchTitle' to ArticlePage it will change indexing behaviour.

Could you please help me to find error in my implementation?

#141642
Nov 17, 2015 11:41
Vote:
 

Your first bulk of code looks correct. But remember that you will have to reindex your content after adding the conventions.

Always use SearchClient.Instance.

#141645
Nov 17, 2015 11:50
Vote:
 

I did:

1) IClient was replaced by SearchClient.Instance;
2) Index was reindexed (I also created new develop index);
3) Different configuration was checked:

          SearchClient.Instance.Conventions
                .ForInstancesOf<ArticlePage>()
                .IncludeField(p => p.SearchTitle());

It seems to me that this has no effect on indexing data. I uses EPiServer Find 9.6.0.3185

P.S. Why should I always use SearchClient.Instance?

#141649
Nov 17, 2015 12:56
Vote:
 

SearchClient.Instance is preconfigured with default conventions for how different types (such as IContent) should be serialized.

#141651
Nov 17, 2015 13:34
Vote:
 

I'm not sure why it is not working for you. However, I would do as Marcus suggested earlier in the thread, and just add a new property to your page that is named SearchTitle. Quick and easy.

#141652
Nov 17, 2015 13:46
* 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.