Cogworks

Post Author
Ismail Mayat 0 Comments Tags: Examine, UK festival, indexing, lucene

Examiness hints and tips from the trenches part 1 - Umbraco Examine

This is part 1 in my Umbraco Examine blog post series. Today I shall be covering useful tools.  Basically if you are doing anything with Umbraco Examine then you need the following:

  1. A copy of Lucene in action 2nd edition
  2. Luke for Lucene (java version)  (.net version)

Lucene in action 2nd edition

As you may or may not be aware Umbraco Examine is just an abstraction around Lucene. The Lucene in action book covers in detail the inner workings of Lucene e.g analysers, documents, fields.

For detailed summary see Manning about page. The last few chapters cover detailed case studies with the LinkedIn case study being a real eye opener. In fact the LinkedIn case study pointed me to the Bobo browser faceting engine, I will cover Bobo in a future post.

Luke for Lucene

Luke for Lucene is the Lucene equivalent of SQL server enterprise manager. This tool is an absolute must when working with Lucene/Umbraco Examine. If you want to know what is in your index or test your queries then 'View the source Luke!'  

An example on how to use Luke. Lets say you have the following code snippet that generates and runs an Umbraco Examine query.

private BaseSearchProvider searcher = ExamineManager.Instance.SearchProviderCollection["MYIndex"];

protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
      ExecuteSearch();
    }
}

private void ExecuteSearch()
{
    var criteria = searcher.CreateSearchCriteria(IndexTypes.Content);

    IBooleanOperation query = criteria.NodeTypeAlias("NewsItem");

    query = query.Not().Field("umbracoNaviHide", 1.ToString());

    query = query.And().OrderByDescending("createDate");
        
    var results = searcher.Search(query.Compile());
   
    totalResults = results.Count();

    SearchResultListing.DataSource = results.Skip(page * PageSize).Take(PageSize);

    SearchResultListing.DataBind();
    //hidden field to store generated query
    generatedQuery.Value = criteria.ToString() + " count is " + totalResults;
}

This creates a query written to the hidden field that looks like 

SearchIndexType: content, LuceneQuery: +(+__NodeTypeAlias:newsitem -umbracoNaviHide:1) +__IndexType:content

You can cut and paste everything after the : into Luke and run that query to get some results.  Luke will also allow you to test your queries using different analysers.

Here ends post no 1 part 2 covers every Examine users best friend GatheringNodeData event.