Disclaimer: This website requires Please enable JavaScript in your browser settings for the best experience.

HomeDev GuideAPI Reference
Dev GuideAPI ReferenceLegal TermsDev CommunityOptimizely AcademySubmit a ticketLog In
Dev Guide

Retrieve documents

Describes how to retrieve documents from the index using the Client interface in Optimizely Search & Navigation.

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 it does not find a document with that ID and type.

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 accept 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 it finds the document and (if found) the indexed object.

📘

Note

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 retrieving the object and its version number, which you can use in optimistic concurrency checks (and update objects only if they have not changed because they are being fetched).

Classes without parameter-less constructors

You might be unable to 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 theClient class conventions, you can customize how people create instances of a specific class.