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

Try our conversational search powered by Generative AI!

Loading...
Area: Optimizely Search & Navigation
ARCHIVED This content is retired and no longer maintained. See the latest version here.

Recommended reading 

Introduction

Indexed objects can be retrieved using the IClient interface Get method. The Get method requires a type as a type parameter and an id and returns the indexed object of the specified type, or null if no document can be found with that ID and type.

C#
IClient client = //A client retrieved from config or injected into the method
BlogPost result = client.Get<BlogPost>(42);

One of the overloads of the Get method also accepts a list of ids and an extension method with the same name accepts a list of IDs as params. These methods return an IEnumerable of GetResult which in turn contains information about whether the document was found or not as well as the object itself if found.

Note that while indexed objects can be returned as the same type as they were before they were indexed only the values of public properties with both a getter and a setter will be populated by default.

GetWithMeta

The IClient interface also has another method for getting indexed objects; GetWithMeta. This returns the indexed object wrapped in a GetResult object. A typical use case for this method is to retrieve the object along with its version number so that the version number can be used in optimistic concurrency checks (only updating objects if they haven't changed since they were fetched).

Classes without parameter less constructors

Types that do not have parameter less constructors or outer dependencies, might not be possible to de-serialize. In many cases that is a sign that they are not suitable to use as search results. In these cases it is probably better to only fetch their IDs and then get them from the database or other backing store or project their values using the Select method. However, it is possible to customize how instances of a specific class are created by adding to the Client class conventions.

Do you find this information helpful? Please log in to provide feedback.

Last updated: Apr 03, 2014

Recommended reading