Skip to main content
2 of 3
added 5855 characters in body

Programmatically refresh lucene index

I'm using Sitecore 8.0 update 5. I'm a having a strange issue with Lucene.

I'm trying to update a product in the index with the following code:

var tempItem = (SitecoreIndexableItem)item;

         ContentSearchManager.GetIndex("sitecore_products_index").Refresh(tempItem);

Instead of an update, the code creates a new product entry in the index with no data (blank). If I debug, I can see the uniqueid is matching, so I'm not sure what is causing this behavior. If I simply do a '.Rebuild()', it refreshes the index with the new product, but I don't want to do that for one product change.

In addition to this, OnPublishEndAsync wasn't working either. Products change and the index won't refresh.

I found this bug fix, but it didn't seem to work for me: https://kb.sitecore.net/articles/992608

Thanks for any help!

<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
$(id) $(id)
        <indexAllFields>true</indexAllFields>
        
        <fields hint="raw:AddComputedIndexField">
                <field fieldName="Back Image" storageType="YES" indexType="TOKENIZED">Service.Lucene.ImageIndexField, Service</field>
                <field fieldName="Front Image" storageType="YES" indexType="TOKENIZED">Service.Lucene.ImageIndexField, Service</field>
                <field fieldName="ExternalID" storageType="YES" indexType="TOKENIZED">Service.Lucene.TextIndexFieldAddOn, Service</field>
                <field fieldName="Brand" storageType="YES" indexType="TOKENIZED">Service.Lucene.TextIndexFieldAddOn, Service</field>
                <field fieldName="Region" storageType="YES" indexType="TOKENIZED">Service.Lucene.TextIndexFieldAddOn, Service</field>
                <field fieldName="Substrates" storageType="YES" indexType="TOKENIZED">Service.Lucene.TextIndexFieldAddOn, Service</field>
                <field fieldName="Categories" storageType="YES" indexType="TOKENIZED">Service.Lucene.TreeListexIndexFieldAddOn, Service</field>
                <field fieldName="Certification Icons" storageType="YES" indexType="TOKENIZED" patch:after="field[last()]">Service.Lucene.TreeListexIndexField, Service</field>
                <field fieldName="Applications" storageType="YES" indexType="TOKENIZED" patch:after="field[last()]">Service.Lucene.TreeListexIndexField, Service</field>
        </fields>
            
        <fieldMap type="Sitecore.ContentSearch.FieldMap, Sitecore.ContentSearch">
            <fieldNames hint="raw:AddFieldByFieldName">
              <field fieldName="Page Title" storageType="YES" indexType="TOKENIZED" vectorType="YES" boost="1f" type="System.String"
                   settingType="Sitecore.ContentSearch.LuceneProvider.LuceneSearchFieldConfiguration, Sitecore.ContentSearch.LuceneProvider" />
            <field fieldName="Product Number" storageType="YES" indexType="TOKENIZED" vectorType="YES" boost="1f" type="System.String"
                   settingType="Sitecore.ContentSearch.LuceneProvider.LuceneSearchFieldConfiguration, Sitecore.ContentSearch.LuceneProvider" />
                   <field fieldName="Short Description" storageType="YES" indexType="TOKENIZED" vectorType="YES" boost="1f" type="System.String"
                   settingType="Sitecore.ContentSearch.LuceneProvider.LuceneSearchFieldConfiguration, Sitecore.ContentSearch.LuceneProvider" />
                   <field fieldName="Full Description" storageType="YES" indexType="TOKENIZED" vectorType="YES" boost="1f" type="System.String"
                   settingType="Sitecore.ContentSearch.LuceneProvider.LuceneSearchFieldConfiguration, Sitecore.ContentSearch.LuceneProvider" />
                   <field fieldName="Features Description" storageType="YES" indexType="TOKENIZED" vectorType="YES" boost="1f" type="System.String"
                   settingType="Sitecore.ContentSearch.LuceneProvider.LuceneSearchFieldConfiguration, Sitecore.ContentSearch.LuceneProvider" />
                   <field fieldName="Patent Numbers" storageType="YES" indexType="TOKENIZED" vectorType="YES" boost="1f" type="System.String"
                   settingType="Sitecore.ContentSearch.LuceneProvider.LuceneSearchFieldConfiguration, Sitecore.ContentSearch.LuceneProvider" />
                   <field fieldName="Discontinued" storageType="YES" indexType="TOKENIZED" vectorType="YES" boost="1f" type="System.String"
                   settingType="Sitecore.ContentSearch.LuceneProvider.LuceneSearchFieldConfiguration, Sitecore.ContentSearch.LuceneProvider" />
                   <field fieldName="_uniqueid" storageType="YES" indexType="TOKENIZED" vectorType="YES" boost="1f" type="System.String"
                   settingType="Sitecore.ContentSearch.LuceneProvider.LuceneSearchFieldConfiguration, Sitecore.ContentSearch.LuceneProvider" />
            </fieldNames>
            
          </fieldMap>
          </configuration>
        
        <strategies hint="list:AddStrategy">
          <!-- NOTE: order of these is controls the execution order -->
          <strategy ref="contentSearch/indexConfigurations/indexUpdateStrategies/onPublishEndAsync" />
        </strategies>
        <commitPolicyExecutor type="Sitecore.ContentSearch.CommitPolicyExecutor, Sitecore.ContentSearch">
          <policies hint="list:AddCommitPolicy">
            <policy type="Sitecore.ContentSearch.TimeIntervalCommitPolicy, Sitecore.ContentSearch" />
          </policies>
        </commitPolicyExecutor>
        
        <locations hint="list:AddCrawler">
          <crawler type="Sitecore.ContentSearch.SitecoreItemCrawler, Sitecore.ContentSearch">
            <Database>master</Database>
            <Root>/sitecore/content/Products</Root>
          </crawler>
        </locations>

      </index>
    </indexes>
  </configuration>
</contentSearch>