Duplicated entries in Lucene index after item publish/save

I just faced with the issue yesterday that I created my own search configuration to store only one field value in the index. I thought that it’s enough if I only index that one field what I want, but NOT.

So if you have something like this, then you will have duplicated entries in the index, because when you change the item and save/publish Lucene doesn’t know that you have already this in Index and it should be updated. So it creates a totally new entry with a different “_uniqueId”.

<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/"&gt;
<sitecore>
<contentSearch>
<indexConfigurations>
<myOwnCustomLuceneIndexConfiguration type="Sitecore.ContentSearch.LuceneProvider.LuceneIndexConfiguration, Sitecore.ContentSearch.LuceneProvider">
<fieldMap type="Sitecore.ContentSearch.FieldMap, Sitecore.ContentSearch">
<fieldNames hint="raw:AddFieldByFieldName">
<field fieldName="MyOwnField" storageType="YES" indexType="TOKENIZED" vectorType="NO" boost="1f" type="System.String" settingType="Sitecore.ContentSearch.LuceneProvider.LuceneSearchFieldConfiguration, Sitecore.ContentSearch.LuceneProvider">
<analyzer type="Sitecore.ContentSearch.LuceneProvider.Analyzers.LowerCaseKeywordAnalyzer, Sitecore.ContentSearch.LuceneProvider" />
</field>
</fieldNames>
</fieldMap>
</myOwnCustomLuceneIndexConfiguration>
</indexConfigurations>
</contentSearch>
</sitecore>
</configuration>

If you add the “_uniqueid” also to your config then Lucene can update the entry, and you can get rid of the duplicated entries.

<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/"&gt;
<sitecore>
<contentSearch>
<indexConfigurations>
<myOwnCustomLuceneIndexConfiguration type="Sitecore.ContentSearch.LuceneProvider.LuceneIndexConfiguration, Sitecore.ContentSearch.LuceneProvider">
<fieldMap type="Sitecore.ContentSearch.FieldMap, Sitecore.ContentSearch">
<fieldNames hint="raw:AddFieldByFieldName">
<field fieldName="MyOwnField" storageType="YES" indexType="TOKENIZED" vectorType="NO" boost="1f" type="System.String" settingType="Sitecore.ContentSearch.LuceneProvider.LuceneSearchFieldConfiguration, Sitecore.ContentSearch.LuceneProvider">
<analyzer type="Sitecore.ContentSearch.LuceneProvider.Analyzers.LowerCaseKeywordAnalyzer, Sitecore.ContentSearch.LuceneProvider" />
</field>
<field fieldName="_uniqueid" storageType="YES" indexType="TOKENIZED" vectorType="NO" boost="1f" type="System.String" settingType="Sitecore.ContentSearch.LuceneProvider.LuceneSearchFieldConfiguration, Sitecore.ContentSearch.LuceneProvider">
<analyzer type="Sitecore.ContentSearch.LuceneProvider.Analyzers.LowerCaseKeywordAnalyzer, Sitecore.ContentSearch.LuceneProvider" />
</field>
</fieldNames>
</fieldMap>
</myOwnCustomLuceneIndexConfiguration>
</indexConfigurations>
</contentSearch>
</sitecore>
</configuration>

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s