Hide menu Last updated: Oct 31 2016
Area: Episerver Find Applies to versions: 12 and higher
Other versions:

Indexing

This topic explains what indexing is and what happens when objects are indexed, and how to modify the indexing, for instance with regards to availability and identity of indexed documents. 

How it works

Indexing is the process of sending an object to the Find service for storage and analysis, so it can be retrieved as search results. If a document of the same type and ID already exists, it is overwritten. The client API supports the indexing of any .NET object.

As objects are serialized upon indexing, the only restriction is that indexed objects can be serialized. If for some reason, typically circular references, an object cannot be serialized, the API supports customizing how an object is serialized and indexed. This flexibility can also be used to implement functionality, such as indexing the return value of extension methods.

In this topic

Indexing objects

Indexing is done via the Index method, exposed by the IClient interface. If you have an instance of a Client and an object to index, you can index using this code.

You can index several objects in a batch.

Once an object is indexed, an instance of the IndexResult class is returned. You can use that class to verify that the indexing was successful and retrieve the document ID.

Time delay

After an object is indexed, it is instantly available for retrieval via the Client’s Get method. However, before the object is returned in search results, the index must be refreshed. This happens automatically every second. However, if it is crucial that an object be available immediately, modify the client command that tells the service to refresh the index. Only do this if really necessary (and preferably only while testing or debugging), since it can negatively affect performance.

C#
client.Index(blogPost, 
        x => x.Refresh = true);

Identity

Unless specified, the service automatically assigns an ID to an indexed document. To explicitly specify an ID, you can either modify the command or annotate a property on the indexed class with the ID attribute. In both cases, the ID's value must be compatible with the DocumentID type.

You can also modify the Client class conventions to use a specific property or method as the ID for all instances of a type without modifying the actual class.

client.Conventions.ForInstancesOf<Product>()
    .IdIs(x => x.Key);

Ignoring properties

To exclude individual properties in a class from being indexed, annotate them with the JsonIgnore attribute. You can also exclude properties without modifying their classes via Client class conventions.

Time to live

You can delete individual documents after a designated time period via the "time to live" functionality. To set this, either modify the command or annotate a property on the indexed class with the TimeToLive attribute.

The granularity of time to live is 60 seconds. This means that documents are deleted within 60 seconds of the actual time to live.

Customizing type indexing

There are several ways to customize how type is serialized and indexed. You can exclude properties, remove HTML tags in string properties, and include return values of methods so they can be used later when searching or filtering.

Updating a single field

With Episerver Find, you can update a single field if you have the indexed item's ID.

client.Update<BlogPost>(Id).Field(x => x.PublishDate, newTime).Execute();

Limiting depth of ContentAreas to be indexed

You can modify a json contract to limit the maximum depth of ContentAreas to index. If your site architecture features a complex structure of nested ContentAreas, using the limit should improve the performance of indexing and searching.

Comments