Sitecore Lucene Search Index

Sitecore has been using Lucene search since version 5, which used the Sitecore.Data.Indexing namespace and Sitecore -> Indexes section in the Web.Config.

Starting in Sitecore 6.4, they introduced a new Search namespace – Sitecore.Search, this uses the Sitecore -> Search -> Configuration -> Indexes section in Web.Config.

From what I know, Sitecore recommends using the new namespace and the old namespace is going to be deprecated starting Sitecore 6.5. The following is a blurb from Sitecore 6.5 Release notes from SDN:
“The Sitecore.Data.Indexing namespace has been deprecated and will be removed in a future version of the CMS in favor of the more powerful and flexible Sitecore.Search classes and corresponding index definitions. ”

Since there is only one document on this new namespace, it’s difficult to get more information when you find yourself in a bind. I had to google search to find bits and pieces and so I am writing this post.

Here is the link to the PDF on this site. Click Here (NO SDN access needed)

The basic configuration is given below:

      <configuration type="Sitecore.Search.SearchConfiguration, Sitecore.Kernel" singleInstance="true">
        <indexes hint="list:AddIndex">
          ... ... ...
          <index id="IndexNAME" type="Sitecore.Search.Index, Sitecore.Kernel">
            <param desc="name">$(id)</param>
            <param desc="folder">im_index</param>
            <Analyzer ref="search/analyzer"/>
            <locations hint="list:AddCrawler">
              <master type="Sitecore.Search.Crawlers.DatabaseCrawler, Sitecore.Kernel">
                <Database>master</Database>
                <Tags>master content</Tags>
                <Root>/sitecore/content</Root>
                <IndexAllFields>true</IndexAllFields>
                <include hint="list:IncludeTemplate">
                  <template comment="Template1">{8917CADF-2148-4328-B595-217C5A9CCA7D}</template>
                  <template comment="Template2">{2A18027D-CA51-4E5D-A7C1-51096E09C16C}</template>
                </include>
                <include hint="list:ExcludeTemplate">
                  <template>{8C18027D-CA51-4E5D-A7C1-510965555C}</template>
                </include>
                <!--<include hint="list:IncludeField">
                  <fieldId>{GUID}</fieldId>
                </include>-->
              </master>
            </locations>
          </index>
        </indexes>
      </configuration>

Here is a piece of sample code to query the index:

    Sitecore.Search.Index searchIndex = Sitecore.Search.SearchManager.GetIndex("Search Index Name"); //replace string with the name of the search index
    using (IndexSearchContext context = searchIndex.CreateSearchContext())
    {
        SearchHits hits = context.Search("search string");  //replace string with the actual search string
        SomeRepeater.DataSource = hits.FetchResults(0, 25); //first param is the start item, second is the count
        SomeRepeater.DataBind();
        ResultsCount = hits.FetchResults(0, hits.Length).Count();
    }

Here are some useful links:

Search Index Troubleshooting by Alex Shyba

Index Viewer in Sitecore Shared Source

I hope this is useful. If you have any questions please don’t hesitate to get in touch!

Tagged as: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,