07 October 2013

Search with Sitecore - Article - 2 - Configure Advance Database Crawler and More

Dear all friends, I hope you have read my first article in this series and here are list of articles which are as follows:

1) Search with Sitecore - Article-1 - Introduction 
2) Search with Sitecore - Article - 2 - Configure Advance Database Crawler and More
3) Search with Sitecore - Article - 3 - Crawler to Crawl Media File like PDF, Document  
4) Search with Sitecore - Article - 4 - Create Search API
5) Search with Sitecore - Article - 5 - Auto Complete For Search

In same series this is next instalment, before telling/showing you what we do in this article I need to set records straight first.
  1. I use Shyba's Advance Database Crawler's, there are already very good articles which are written in length and breadth about it. Just for reference following is the best I found and refer during my work.
    1. Three article series showing how to use the ADV.
    2. Another good article which tell us all glossary of the ADV configuration files.
In our project we have content section as usual under home node. We also have Global reference and product catalogue which is outside of the home node. In our project for day to day retrieval of items also we used Lucene based search, this strategy can be debated but for now that is what we have done. So following is the overall content tree we have. All this I share to set the context of this series.
Content Tree - Figure 2.1
Because of this we have almost three different custom index configured using Advance database crawler.
  • Home
  • GlobalReference
  • Product
All above index can be build using the Sitecore Index Building Wizard from the control Panel. All above index have it's configuration file added in the following path ~\App_Config\Include\Shared\ and every index configuration file is just having default configuration as suggested for advance database crawler in above blogs. 
Once you build the index using Sitecore Wizard you will able to see the folder named as index named in the data folder as follows:
Index Folders - Figure 2.2
Next we optimize the each index configuration file so that we have clear knowing what to index. As I need to provide the front end search for my website I will put my focus on two index namely Home and Product. To optmize my index I followed above article listed from other authors, but mainly set following property false 
<IndexAllFields> false </IndexAllFields>
I also updated the list of fields to include which is relevant to my project using following syntax. Then I provided the list of fields to exclude. This is very important as I don't want to index the fields such as 'UpdatedBy', 'Revision' etc., which is as follows as this list can be used by others as it is same for most of the cases.
             <include hint="list:ExcludeField">
                  <!-- Workflow Fields -->
                  <!-- Statistics Fields -->
                  <!-- Security Fields -->
                  <!-- Publish Fields -->
                  <!-- Lifetime Fields -->
                  <!-- Layout Fields -->
                  <!-- Insert Options Fields -->
                  <!-- Help Fields -->
                  <!-- Appearance Menu Fields -->
                  <!-- Advanced Fields -->
                  <!-- Tasks Fields -->
                  <!-- Validation Rules Fields -->
Following is the syntax of Include field. Off-course your list of fields in case of include will be different as it is based on your own template.
<include hint="list:IncludeField">
Above configurations make my index more slimmer and accurate from content prospective. After updating the configuration file I re-build the index to be certain that my configurations are correct. Next, to be more certain what lies in my index I used another community tool which can show the content of Lucene Index. To run this tool you need correct version of it as it depends upon the lucene version and you also need JVM. Here is the link which do the job...
Now next thing is to start writing the custom code / API which uses the Advance database search libraries and customized for my project. Before getting into the code let me tell you requirement I have:
  • Search Result should be able to search based on any search keyword or in other words it is free text search.
  • Search Result should show the description also or part of text where it finds the word which is being search and highlight that word in the description.
  • Search Result should also show URL.
  • Search result should be prioritize first on product then browsable content and last should include the file result.
  • File search should also be able to show content from PDF file, Word File, text and HTML files. All files are stored within Media Library.
  • In case of file result it should also show the file type as icon next to link.
  • In header search box which is available in every page should be able to show the auto-complete feature and should come from the keywords which is relevant as per the content.
I will not say above requirement is equivalent to Mini Google within site but yes its get inspired by the same.
Taking clue from the requirements First thing which I notice is ability to search inside the file. Till this moment we don't have any Sitecore inbuilt mechanism which can go and crawl the files. So it means I need to write my own crawler can parse and crawl the PDF and other files. My next article is devoted fully for how to crawl and index the files within media library.