|Number of votes:||1|
EPiServer Find is not just for EPiServer CMS pages– in fact the client API supports indexing of any .NET object.
When working with indexing of data in EPiServer Find there are some hidden gems that are nice to know about.
According to the documentation, If a document of the same type with the same ID already exists it will be overwritten (or updated if you like). In other words, controlling the ID is the key.
Let me illustrate this with a code sample. For demonstration purposes I have created a class Product:
Using the Product model I can now add some simple test data to the EPiServer Find index.
If I navigate to the Find Explorer (from the main menu in EPiServer CMS) I can now see the following:
Notice the “Index ID” – this is the id that Find is using for identifying each document in the index. Lets see what happens if I now try to update product number two:
As you can see from the screenshot above, the update resulted in duplicate documents in the index. Off course, I could solve this by deleting the document before re-indexing, but that far from an ideal solution. The trick is to use the Id attribute on the property that uniquely identifies your model:
Re-indexing, we can see that the Find is now using my Id property as Index ID:
This way updating existing documents no longer result in duplicates.
By default, Find will use Namespace_Class as title in the index explorer. To easier distinguish between the different documents, we can tell the explorer to use a property on our model instead. In order to do this, we create a new class where we implement interface IDocumentInterpreter and override the ExtendDocumentInformation method.
Notice that you pass in your model type and specify the property you want to use as title – here I’m using DisplayName.
Navigating to the explorer view, it is a lot easier to distinguish between the documents in the index.
The IDocumentInterpreter interface is part of the EPiServer.Find.Framework.UI namespace.