Sitecore’s SearchHits.Slice(int) method seems to change in Sitecore 6.6

I am working on a Sitecore 6.6 upgrade (yes, I know that that is still pretty much obsolete) and I came across a weird bug that took an age to track down. This is more a reminder for myself than anything else.

The code for Lucene searches frequently used lines of the form:

Slice Capture

List<SearchHit> distinctHits = hits.Slice(0).Distinct(new SearchHitEqualityComparer()).ToList();

This always returned zero SearchHits. It seems that this is due to the call to ‘Slice(0)‘ bit. This does raise some questions…

Why would you want to .Slice(0)? This is saying ‘give me all contents of my enumerable, from the first to the last’. It’s not exactly a slice. I can only imagine someone didn’t know about .Hits property, which will give you that same enumerable.

How is this going wrong? Sure, the .Slice() call is weird, but it’s not wrong. I decompiled the Sitecore Kernel to try to figure out what was going on – and it’s a bit knotted. It’s not clear what class is doing what. I did find this interesting implementation:

Slice that never returns items

This should never return any items. However, that was the same in the Kernel before upgrade, so I’m not sure what it is in my 6.5 to 6.6 upgrade that has exposed this issue – but if I replace the .Slice() with .Hits my search seems to work again.

Advertisement
Sitecore’s SearchHits.Slice(int) method seems to change in Sitecore 6.6

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.