Search code examples
sitecoresitecore8

Specifying which index to use in sitecore lucene


I have a website that was produced in sitecore that i have inherited. The search does not seem to be working correctly. Basically documents do not seem to be returned correctly. I have noted that there is the default sitecore_web_index index and also a custom index that seems to index the same content more or less. Currently the search queries the custom index however I would like to change the query to the default index to see if the document is then returned. I was told you can specify which index to use but the person never told me how to do it. Does anyone know how i can change this?


Solution

  • Sitecore 8 content search uses Sitecore.ContentSearch.ContentSearchManager.GetIndex(...) method to retrieve chosen index.

    You can pass either:

    1. Index name as a string:
    Sitecore.ContentSearch.ContentSearchManager.GetIndex("sitecore_web_index")
    
    1. IIndexable item - in this case Sitecore will try to find first registered index for you:
    Sitecore.ContentSearch.ContentSearchManager.GetIndex(iIndexable)
    

    Just find where GetIndex is used in your code and replace it with a default index name.

    One thing you should be aware of - there is a chance that your custom index has some customization added (like computed fields, list of fields indexed etc). Be careful with any changes. Maybe there are other reasons why your search doesn't work. Try using IndexingManager app to rebuild the indexes and see if it helps.