Don't miss out Virtual Happy Hour this Friday (April 26).

Try our conversational search powered by Generative AI!

SearchHitUrl has wrong Url value (multi-sites)

Vote:
 

We have two sites and and two catalogs with catalog content being indexed with the SiteId for filtering to get the correct results. 

The issue I'm having is with the 'SearchHitUrl$$string' value being indexed -- having a mismatch of my Host and SiteId. It also appears inconsistent with some times placing a relative url (which is fine and causes no issues for my search results).

Is there a way to set 'SearchHitUrl$$string' explicitily for the type, or configure this somewhere?   I was thinking an initialization module might work but not sure if that's the best approach. 

Thanks in advanced,

Ben

#226233
Edited, Aug 08, 2020 0:14
Vote:
 

Hi Ben

First of all, I would investigate why the URLs are sometimes relative, sometimes absolute, sometimes mismatched. The indexer gets the URL from UrlResolver.GetUrl, so you should be able to replicate and test the URLs outside of the index situation.

Second, you can override the indexing of the URLs. Something like this should get you started (put it in an initialization module):

public void Initialize(InitializationEngine context)
{
    IClient findClient = context.Locate.Advanced.GetInstance<IClient>();
    findClient.Conventions.UnifiedSearchRegistry
        .Add<GenericProduct>()
        .CustomizeIndexProjection(p => p.ProjectUrlFrom((GenericProduct x) => GenerateCustomUrl(x.ContentLink)));
}
#226234
Edited, Aug 08, 2020 12:35
Vote:
 

Hi Stefan, 

I've added an initialization module for Find indexing with a slightly different implementation and it's hitting the breakpoint when creating a product but the value for the SearchHirUrl is not updating in the index:

	[ModuleDependency(typeof(IndexingModule))]
	public class FindConventionsInitialization : IInitializableModule
	{
		public void Initialize(InitializationEngine context)
		{
			var client = SearchClient.Instance;

			client.Conventions.UnifiedSearchRegistry
				.Add<IProfessionalProduct>()
				.CustomizeIndexProjection(p => p.ProjectUrlFrom((IProfessionalProduct x) => RepairUrl(x.ContentLink)));
		}

		public void Uninitialize(InitializationEngine context) { }

		private string RepairUrl(ContentReference contentLink)
		{
			IUrlResolver urlResolver = ServiceLocator.Current.GetInstance<IUrlResolver>();

			string path = urlResolver.GetUrl(contentLink);

			return path ?? path.Replace("mysite1.com", "mysite2.com");
		}
	}
#226311
Edited, Aug 10, 2020 22:01
Vote:
 

Hey Ben,

Did you ever get to the bottom of why the searchhiturl was inconsistently either a relative or absolute uri?

We've just stumbled across the same thing in our sites when investigating why there was a language slug in the url on one environment and not on the other when the content being indexes is essentially identical.

Alex 

#277388
Edited, Mar 29, 2022 15:31
* 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.