Getting started with Lucinq on Sitecore

Installation on Sitecore

Here are the steps necessary to get Lucinq working on Sitecore

1) Install Nuget Packages

In order to get Lucinq, you simply need to get down the latest nuget package for your version of sitecore. At present this will be either Lucinq.Sitecore66 or Lucinq.Sitecore7

2a) Add Indexing Configuration (Sitecore 6.x Only)

Create and add a configuration file similar to below.

<configuration xmlns:patch="">

      <configuration type="Sitecore.Search.SearchConfiguration, Sitecore.Kernel" singleInstance="true">
        <indexes hint="list:AddIndex">
          <index id="lucinq_index" type="Sitecore.Search.Index, Sitecore.Kernel">
            <param desc="name">$(id)</param>
            <param desc="folder">$(id)</param>
            <Analyzer ref="search/analyzer"/>
            <locations hint="list:AddCrawler">
              <master type="Lucinq.SitecoreIntegration.Sitecore66.Indexing.StandardCrawler, Lucinq.SitecoreIntegration.Sitecore66">
              <web type="Lucinq.SitecoreIntegration.Sitecore66.Indexing.StandardCrawler, Lucinq.SitecoreIntegration.Sitecore66">

2b) Indexing Configuration for Sitecore 7.x

Lucinq on Sitecore 7 utilises the default indexes, I generally recommend duplicating the default Web and Master index configurations that come with Sitecore and replacing the name.

Lucinq also comes with a fix to the template structure to allow querying based upon base templates.

3) Build the index

You can either rebuild the index using the Index Viewer Module (which is my preferred method on versions of Sitecore previous to 7, or use the control panel or developer ribbon. Your index should be called ‘lucinq_index’ if you have used the configuration above for Sitecore 6.x. If you are using Sitecore 7.x then you can use the default configured indexes.

3) Creating Your First Search

Ok, so now you have installed Lucinq, you can now go ahead and create a search.

var search = new SitecoreSearch(Settings.IndexFolder + "\\lucinq_index", new DatabaseHelper()));
// get out all items with the given template
var queryBuilder = new SitecoreQueryBuilder(x => x.TemplateId(templateId));
var sitecoreSearchResult = search.Execute(queryBuilder, 20);

var sitecoreItemResult = sitecoreSearchResult.GetRange(0, 10);

// the original lucinq search result is available here
// sitecoreSearchResult.LuceneSearchResult
// therefore - for the total number of hits you can use
int totalHits = sitecoreSearchResult.TotalHits;

// for results as a list for convenience you can use
List<Item> results = sitecoreItemResult.Items;

// as with the regular lucene search result - the sitecoreItemResult is IEnumerable<Item>
foreach (Item item in sitecoreItemResult)
    // do something with the items        

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s