Tuesday, July 5, 2016

Sitecore search inconsistencies in the result URLs

I noticed on a Lucene search implementation in Sitecore that there were some inconsistencies around the URLs being generated. In some cases spaces where replaced by dashes and in other cases they were not. This was a tricky issue because some of the content names (and therefore paths) included dashes.

of course in the Sitecore.config file there was an encode name replacement to replace all dashes in URLs with spaces.
<replace mode="on" find=" " replaceWith="-"/>
However the results weren't showing until the EncodeNames element was set in the UrlOptions when generating the link with the link manager.
itemUrl = Sitecore.Links.LinkManager.GetItemUrl(item, new UrlOptions { AlwaysIncludeServerUrl = true, LanguageEmbedding = LanguageEmbedding.Never, EncodeNames = true});

No comments:

Post a Comment