Quantcast
Channel: Brian Pedersen's Sitecore and .NET Blog
Viewing all articles
Browse latest Browse all 285

Sitecore ContentSearch Get Latest Version

$
0
0

The Sitecore ContentSearch API allows you to index content in either .NET Lucene or SOLR, dramatically speeding up retrieval of content, especially when querying items that are scattered across your content tree.

Content retrieved from the ContentSearch API is not Sitecore Content Items (of type Sitecore.Data.Items.Item), they are objects that you have defined yourself. This is why you will experience that when querying from the MASTER database index (SITECORE_MASTER_INDEX), you will receive one result per version (and one result per language) rather than one Item object containing all versions and languages.

To overcome this issue, Sitecore have added a few nifty fields to the index, for example the _latestversion field:

Latest Version Field from SOLR

Latest Version Field found in my SOLR index

So when querying the index, you can add the _latestversion field:

query = query.Where(item => item["_latestversion"].Equals("1")); 

BTW, _latestversion is defined in a constant value in Sitecore:

Sitecore.ContentSearch.BuiltinFields.LatestVersion;

MORE TO READ: 



Viewing all articles
Browse latest Browse all 285

Trending Articles