Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

urllink in Sitecore indexs returns media url with "/sitecore/shell/~/media/..."

"urllink" is a ComputedIndexField in Sitecore indexs.

Foe media items, if I rebuild the indexs, the urls that gets stored into index start with "/~/media/...", which is correct.

But if the index strategy is onPublishEndSync, and I do republish on my media items, the urls start with "/sitecore/shell/~/media/...".

I've checked Sitecore source code, the difference is Context.Site. it's null when rebuilding the index, so it uses "/" as prefix. but it's "Sitecore shell" when doing publishing. Therefore it's using Context.Site.VirtualFolder of Sitecore Shell, which is "/sitecore/shell".

I think this is a Sitecore bug. ATM I'm thinking to create my own urlLink ComputedIndexField class and use MediaUrlOptions with AbsolutePath=false as a fix.

Just want to know if I'm missing anything and it's actually not a Sitecore issue?

Thanks!

like image 277
zhanke Avatar asked Dec 03 '14 13:12

zhanke


1 Answers

Just to give an update for this. Confirmed by Sitecore it's a bug. They are finding a workaround, I'll update here when they do.

Thanks.

-------------updated on 15/12/2014----------------------

Ticket's closed now. Sitecore's solution is to remove this "urlLink" field from the index in the future(They said they will request this).

Reason being that url should be generated by LinkManager based on current site context. However site context doesn't exist while indexing(For content item you can check the path, but for media item you cannot).

Of course there's another solution is to create your own computeredField to override the logic for media item. However I agree with Sitecore, it feels more right to remove this field from the index.

On top of all that, the initial reason for using the urlLink field was to drop the need for querying Sitecore completely while doing a Search. All the content are coming from Index's stored fields value. But on the other hand, pagination is normally being used for search results, so even there're requests to Sitecore, it shouldn't be a lot.

That'd be all for now, happy to see more opinions and to discuss, thanks!

like image 144
zhanke Avatar answered Oct 29 '22 21:10

zhanke