London Dev Meetup Rescheduled! Due to unavoidable reasons, the event has been moved to 21st May. Speakers remain the same—any changes will be communicated. Seats are limited—register here to secure your spot!

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

You can retrieve indexed objects using the IClient interface Get method. This method requires a type (as a type parameter) and an id, and returns the indexed object of that type, or null if no document is 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 Get method overloads also accepts a list of ids. Moreover, an extension method with the same name accepts a list of IDs as params. These methods return an IEnumerable of GetResult, which contains information about whether the document was found and, if found, the indexed object.

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 are populated by default.

GetWithMeta

The IClient interface has another method for getting indexed objects: GetWithMeta. This method 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, which can be used in optimistic concurrency checks (that is, updating objects only if they haven't changed since being fetched).

Classes without parameter-less constructors

It might not be possible de-serialize types without parameter-less constructors or outer dependencies. In many cases, that is a sign that the types 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, by adding to Client class conventions, you can customize how instances of a specific class are created.

Last updated: Sep 21, 2015