SiteCore Best Practices
SiteCore Best Practices
SiteCore Best Practices
Best Practices
for Sitecore
Nonlinear Digital is the full-service digital agency division of non-linear creations, with extensive
knowledge and technical expertise in various CMS and marketing/analytics solutions, particularly the
Sitecore platform. Our teams, working with you, use an agile methodology to create unique website and
digital experiences that drive business results in a measurable way.
www.nonlinearcreations.com
www.nonlinearcreations.com
Contents
Tables 4
Figures 4
Introduction 5
For the speed reader
Sitecore terminology 7
Conclusion 27
About Nonlinear 28
Tables
This whitepaper organizes important information about Sitecore settings and infrastructure into a number of tables:
Figures
We’ve also included a number of figures and screenshots:
Introduction
All content management systems (CMS) offer promises of reduced IT expenditures, a streamlined content lifecycle, and a return
of content control to the subject matter experts. Sitecore, an incredibly flexible CMS that fits well in the mid-market, can deliver on
those promises, whether you’re using version 5.3 or the newest incarnation of Sitecore—version 6.0.
Our previous whitepaper shared “lessons learned” during Nonlinear’s real-world implementations of Sitecore, but it did not cover
two very important considerations in a Sitecore build: performance and scalability. As a CMS that dynamically serves content from
a database, users and potential purchasers of Sitecore are often concerned with how to create a best-of-breed implementation that
accounts for both performance and scalability. In this whitepaper, we offer you the steps that your implementation and operations
teams will need to take to ensure a high-performing and reliable web presence within the Sitecore CMS.
If you only have a few minutes to take in the key points of this document, I suggest reviewing the following diagram, which speaks to
the overarching process required to ensure a responsive and scalable solution:
Develop &
Test Configure
First, define the performance criteria for your Sitecore deployment. Second, purchase and configure a server & network
environment that can deliver on these requirements. Third, the development team designs, implements and (most importantly!)
tests the Sitecore solution to ensure it performs well in your technical environment. Fourth, the operational team monitors and
proactively responds to any changing conditions, perhaps revisiting the original requirements and making some tweaks. Now, if you
still have some time and are interested in learning more, read on!
6 | BEST PRACTICES FOR SITECORE
We sincerely hope you take advantage of Nonlinear’s whitepaper series to give you a more complete view of the online environment.
Sitecore terminology
This document assumes a familiarity with the Sitecore content management system. If you are comfortable with Sitecore concepts
and web programming terminology, feel free to skip this section. If, on the other hand, you have little or no experience with the
Sitecore CMS, then this brief overview of Sitecore concepts should render the rest of the document much more readable.
Branch Template (Version 6) to create and assign the required presentation objects, which
Used by content authors to create new content items allow the devices to render content appropriately.
Branch templates have the ability to also create “children”
(descendants) of the new item at the same time the parent item Layout
is created. This is the base presentation object in Sitecore, which defines
the general look-and-feel of a web page.
Command Template (Version 6)
Used by content authors to create a new content item through Masters (Version 5.3)
the use of a custom wizard or dialog box. What content authors use to create content items. Masters
include additional security information, which creates default
Content Authors settings for the content items.
Users of the Sitecore CMS, who are responsible for the input
and approval of content. All content authors have a username Page Editor (Version 6)
and password to access the Sitecore CMS. This authoring interface is similar to the Web Edit mode of
version 5.3 but includes improved functionality, such as inline
Content Item editing and content author control over presentation items.
A piece of content that has been created using a template and
assigned to a location in the content tree. A content item can Rendering / Sub-layout
exist in one or more languages and may also be controlled by a A presentation object assigned to areas of a layout, which
workflow process. renders specific content. Renderings are created using XSLT;
sub-layouts using .NET code.
Content Tree (Hierarchy)
The content tree is the method of organizing content items in Templates
Sitecore, using a folder-like structure. Templates define the structure and fields of content items. In
Version 5.3, they are used by administrators to create content,
Device but, normally, content authors make use of masters. In Version
Like many CMS products, Sitecore allows you to separate 6, templates are also used by content authors to create
content from its presentation layer. In addition, Sitecore allows content.
you to define multiple presentation schemes for your content.
These schemes are defined using a Device. Web Edit (Version 5.3)
In Sitecore version 5.3.1, there are two default devices. The The most common authoring interface used by content authors
first is the standard HTML device, and the second is the print- to browse the site and edit content. Making use of green dots
friendly device. It is the responsibility of the Sitecore developer and a floating menu, content authors are able to create and
edit content.
8 | BEST PRACTICES FOR SITECORE
To define your performance requirements for each system, simply complete the following tables. We have added some sample
information for you, as well as a description of what each metric means:
Filling in the above table will provide you with a baseline when developing test procedures for your CMS and website. Note that
the above criteria are offered as a guide only; you may want to develop additional criteria for your project to account for your most
important pages, major entry or landing pages or functionally-complex areas of the site.
BEST PRACTICES FOR SITECORE | 9
• Appropriate hardware
Final choices on hardware and networks will depend on the size of your site, the level of functionality it requires and the number of
visitors you need to support.
In the above diagram, you can see that the Sitecore CMS authoring environment is separate from the actual website delivery nodes.
This allows for the separation of performance requirements for content authors and site visitors. This configuration also increases
security by removing the authoring environment from the public site. This deployment architecture includes multiple, load-balanced
web nodes for added performance and fault tolerance.
The diagram also shows that all instances of Microsoft SQL Server (MS SQL) have been separated from the both the authoring
servers and the web nodes. We strongly recommend the separation of the database from Sitecore, for a few different reasons:
1. MS SQL server does not perform well in most virtualized environments, whereas Sitecore can perform quite well. Virtualizing
the Sitecore web nodes allows for the rapid deployment of additional capacity, if required.
2. The hardware requirements of MS SQL, when compared to Sitecore, are typically greater. By separating these specialized
applications, you can make appropriate hardware choices for each.
3. When the database is isolated from Sitecore, it is much easier to diagnose performance issues.
BEST PRACTICES FOR SITECORE | 11
Configuration tasks
Once Sitecore is installed, there are a number of configuration settings that can be adjusted, which tend to impact performance.
The first category of settings defines storage location. The second category controls the caching behavior of the CMS.
Storage locations
There are a number of directory locations in the web.config file. The following excerpt from a Sitecore 6 web.config file shows the
most relevant entries:
The web.config file references the above entries to control the majority of file location settings.
• The datafolder is responsible for logs, viewstates, diagnostic counters, debug traces and packages—making this location a
high-write situation for both the CMS and the web nodes. Ensuring the datafolder is located on a disk that can handle the
write requirements aids in performance. You will want to consider this set-up for the tempFolder, as well, which is used as a
temporary processing location.
• The Media.CacheFolder, which is used to store media that has been extracted from the database, is most relevant for the
published site. Writes to disk are generally infrequent for this folder, making high-speed reading a greater priority.
Caching
As you probably already know, caching is one of the most complex topics related to performance. The impact of caching is subject
to available hardware resources, the caching algorithm of Sitecore, the configuration approach you have taken and the behavior
of your users. The only way you can know with 100% certainty what will happen is to try it. This makes planning and realistic pre-
launch testing critical.
In this section, we outline the major types of caching in Sitecore and where the settings are configured. In the development section,
we cover tech specifics for developers. Our intention here is not to dive into the nitty-gritty detail, but instead give you a solid
overview of your options so that you are able to test the performance of your chosen strategy.
There are three levels of caching in Sitecore: the browser-level cache, the site-level cache and the database-level cache.
12 | BEST PRACTICES FOR SITECORE
Site-level caching
Site-level caching is enabled by settings on sublayouts and renderings inside the Sitecore CMS. We recommend that you maintain
the cache settings for renderings and sublayouts using the standard values for your template layout settings. This ensures that you
do not mistakenly cache sublayouts and renderings that require dynamic generation on each load. These settings can be adjusted
to suit the needs of the particular control, in terms of desired rendering, functionality and usage. The importance of this in relation
to end usage is that the more of these variations you use, potentially the more cache space each rendering or sublayout will use, as
a separate copy of the rendered version will be stored for each specific variation.
The site nodes have a number of settings that control caching, which are listed in the following table:
Note that Sitecore differentiates a cache size for HTML vs. XSLT controls, allowing you increased granularity for tuning the
performance needs of your particular site, but this is dependent on usage of pages heavy in sublayouts (HTML) or renderings (XSLT).
Sitecore also allows for a Media cache, which holds media files extracted from the database in a flat file format on the web server.
This allows for faster response times than accessing the associated database blob. We don’t recommend that you store media in
the database.
For each of these groups it is important to spell out their mandate and responsibilities. The key group in this model is the ECM
Governance Board; we provide some insight into how it is frequently structured.
BEST PRACTICES FOR SITECORE | 13
Database-level caching
Each database has its own caching parameters. These parameters define the allowable cache size for data, items, paths and
standard values. The following extract from the web.config entries of Sitecore 6 show an example of possible settings:
<cacheSizes hint=”setting”>
<data>20MB</data>
<items>10MB</items>
<paths>500KB</paths>
<standardValues>500KB</standardValues>
</cacheSizes>
This review of cache settings will be further expanded in the Development section of this whitepaper.
Prefetch
In version 5, Sitecore introduced a new feature called Prefetch. Prefetch allows you to configure Sitecore to pre-load the item cache
upon start-up. The benefit is a smoother experience for users, as they do not have to endure the waiting time of the initial non-
cached request. The trade-off here is a longer start-up time.
In Sitecore, prefetch options are configured for each database. There is also a single, shared configuration. The common
configuration file and the .config files for each database are located in the App_Config/Prefetch directory.
For optimal site performance, adjust the prefetch entries of the web database (App_Config/Prefetch/web.config). The following is a
slightly modified listing of the web database default entries found in Sitecore 6. The additional inline comments explain what each
entry does.
<!—
Loads all items based on system template:
/sitecore/content/templates/system/alias
-->
<template desc=”alias”>{<alias-guid>}</template>
<!—
Loads all items based on system template:
/sitecore/content/templates/system/Layout/Layout
-->
<template desc=”layout”>{<layout-guid>}</template>
<!—
Loads all items based on system template:
/sitecore/content/templates/system/Layout/Renderings/Xsl Rendering
-->
<template desc=”xsl rendering”>{<xsl-guid>}</template>
<!—
Loads the “home” node
-->
<item desc=”home”>{<home-guid>}</item>
<!—
Loads all children of the “home” node
-->
<children desc=”main items”>{<home-guid>}</children>
</configuration>
14 | BEST PRACTICES FOR SITECORE
2. Relationships between content can cause unexpected looping (and the related challenges). Using a Lucene index can prove a
more efficient means of determining content relationships
3. Caching is an art form. Watch your site’s performance and tweak settings as required
4. Make full use of the Sitecore Debugger, and be sure to stress-test your implementation before going live
5. Profile your code. This can show you how it is interacting with Sitecore
6. Rely on Sitecore sorting rather than customized .NET sorting code to sort on the published site
Content structures
Content in Sitecore is organized using the Content Hierarchy. There are a few basic considerations to take into account when
designing your content tree.
When the tree is too broad, the authoring interfaces are often required to load a large number of items at once. This can also create
performance problems in the rendering of the website. If possible, structure the content so that no node in the tree has more than
100 siblings.
To go deeper into this concept, let’s consider a simple example: news releases.
How do we best structure this content? One option is to organize all news releases into single folder. The second option is to
organize the releases into subfolders by year.
BEST PRACTICES FOR SITECORE | 15
Consider the news release page for 2008. When the news releases are organized into a single folder, the page must load all news
articles and then filtre out the news releases that are not for 2008. This forces Sitecore to make a lot of unnecessary calls to either
the database or the cache, and then perform extra processing to eliminate the unneeded data.
When news releases are stored by year, Sitecore can simply load all the releases from a single folder and display them. We can see
how this choice can significantly impact site performance.
If we consider how product pages relate to news items, we can also see how the choice of content structure can also impact the
performance of the authoring environment. Using the single folder option, the amount of information that Sitecore needs to load
is much greater. While it’s not an issue with only six news items, 6000 news items would be quite problematic. Organizing news
releases by year would alleviate the problem.
In short, be careful of the way content is organized in the Sitecore tree, and remember that content organizing strategies have
implications for both the published site and the content authoring environment.
Sorting
Organizations often require their published sites to sort content items based on a field value. Common examples would be
alphabetical sorts based on title, or chronological sorts based on a date or time value. Understanding how Sitecore performs this
sorting of content items is an important part of developing the most efficient code.
Basically, Sitecore sorts children of any given item using the SortOrder field. If this field is not filled or the values are all equal, then
Sitecore sorts according to the Subitems Sorting field of the parent item. This can be seen clearly in the following sorting dialog
screenshot.
16 | BEST PRACTICES FOR SITECORE
Note that it is also possible to create your own sorting behaviors and register them with Sitecore by implementing a customized
class based on the Comparer abstract class. If you look to the Core database, then/Sitecore/content/Settings/Subitems Sorting
you will find the registration of the existing sorting methods. Once you have created your own sorter class, simply register it in this
location by creating a new item.
At Nonlinear, we prefer this method of sorting, as it provides explicit sorting control for the content authors and performance
benefits for the published site (which no longer needs to run the sorting code). The sorting code option inside Sitecore only runs in
two circumstances:
(a) When interacting with the content-editing interfaces, and, (b) During the publication of content items. Once content items have
been published to the live site, the order is explicitly set. This means that there is no sorting code or logic executed in the published
website.
BEST PRACTICES FOR SITECORE | 17
Related content
Many of our clients at Nonlinear request that content authors be able to tag content during the publishing process. Using these
tags, the content is automatically pulled into related positions on the website. If we continue with our news release example from
before, that would mean that news releases could be tagged according to related products. By tagging content in this way, the
related news items would automatically appear on each product page without the intervention of the content author. There is no
problem with this, so long as the right approach is employed. To maximize performance, at Nonlinear we make use of customized
Lucene indexes on the tag fields. This allows us to create efficient Lucene queries to quickly retrieve content with particular tags as
opposed to scanning large numbers of content items.
The first step in this process is to set up the appropriate Lucene index:
<index id=”relatedLinks” singleInstance=”true” type=”Sitecore.Data.Indexing.Index,
Sitecore.Kernel”>
<param desc=”name”>$(id)</param>
<!--<templates hint=”list:AddTemplate”>
<template>Section Search</template>
</templates>-->
<fields hint=”raw:AddField”>
<field target=”id” storage=”unstored”>@id</field>
<field target=”tags”>tags</field>
<field target=”includeinsearchresults”>include in search results</field>
</fields>
</index>
In this example, a Single-Line Text field called “Tags” is being used to populate a Lucene index call relatedLinks. The sample .NET
code that would be used to query this index has been included in Appendix A.
1. NET string manipulation capabilities (like string concatenation, String.Format and StringBuilder) need to be used correctly.
Though, what is correct for your situation depends on the performance characteristics you are trying to achieve. Lower memory
use? Faster execution? Both?
2. Sitecore does cache, but don’t forget you can still access the Cache features of the .NET framework. This can be especially
helpful if you want to explicitly control the caching of complex queries to Sitecore or other systems. Complex navigational
systems (such as sites using faceted navigation) will often utilize such an approach.
3. Creating new hooks or pipeline additions in Sitecore is a common means to extend functionality; however, before deciding on
this approach, be sure you understand when this new code fires. If you are unsure, create a simple stub and have it log out, or
trace it through your debugger.
18 | BEST PRACTICES FOR SITECORE
1. Data providers are an excellent way to integrate external data into Sitecore; however, when they’re chained into the Master
database (the way it’s described in articles on the Sitecore Developers’ Network, or SDN), you will add significant overhead
to each item request, burdening the master database. Instead, consider using the Sharepoint Connector, which has been
architected with its own database and cross-proxy. We have found this to be much more efficient.
2. Make use of automated tools to test your .NET code. At Nonlinear, we really like the Red Gate suite of products for profiling our
.NET code and locating potential problem points. The free FxCop scanner from Microsoft can also help you to find problematic
code.
XSL
The XSL vs. .NET debate is always a lively one on the SDN forums. All being equal, at Nonlinear we take the approach that XSL is
more than acceptable for content that has no complex rendering logic, such as conditionals or advanced queries. In our experience,
the performance improvement gained by going to .NET in such cases is minimal and, sometimes undetectable. We prefer XSL in
these instances, as renderings are much easier to update and do not require a recompile of the solution.
One quick tip: the Rendering Wizard in Sitecore automatically inserts a $home variable. Remove it unless you need it. If you are
concerned about the performance of a rendering, use the Sitecore Debugger to determine the bottleneck. If required, you can
always convert it to .NET.
There are three steps required of any Sitecore developer when validating code for performance:
1. Use the Sitecore Debugger as a means of identifying any underperforming code early on
2. Make use of .NET profilers to find .NET issues
3. Stress-test your code with realistic volumes of data and users—make the test scenario as close as you can to the reality of your
eventual implementation environment
Now, let’s look at the Sitecore Debugger. The first thing that needs your attention, on any given page, is the “Hot Spots” sections of
the trace:
BEST PRACTICES FOR SITECORE | 19
There are two main pieces of information to take notice of here. First, the time taken to display various renderings and sublayouts.
Second, the “most items read” info. If a rendering is taking a long time but there are few item reads for that rendering, this often
points to an algorithmic problem in the code. If, however, the item reads are high, this can point to excess Sitecore queries,
unnecessary loading of items or a poorly-designed content tree. As part of Sitecore’s profile section, the Debugger provides
counts of cache hits, cache misses and physical reads. If we look at the detailed profile information, we can see the performance
information for sample rendering.xslt:
This information tells us that 12 items were read and 21 cache hits were made in order to output this rendering. Examination of the
logic in this rendering may give you leads for potential performance improvements.
I am not going to dive into .NET profiling and stress-testing here, but I would suggest you take a serious look at the RedGate
products for .NET profiling. They have been invaluable for us at Nonlinear in diagnosing underperforming .NET code during audits of
existing implementations, as well as during our own development projects.
If you don’t have the budget for commercial stress-testing tools, there are also a number of free and open source tools. OpenSTA
(http://opensta.org/) is probably our favorite. Microsoft also offers a number of tools for website stress-testing, including the free
Web Application Stress Tool.
Caching specifics
I have already discussed some of the basics of Sitecore caching. Now, I would like to delve into some of the greater detail
Namely, what level of caching is appropriate for your circumstances? At its most basic, caching in Sitecore relies on caching the
presentation objects themselves. From there, you simply need to decide how many additional layers of caching to add. See below for
a figure that outlines a typical caching structure for Sitecore.
20 | BEST PRACTICES FOR SITECORE
Client Caching
HTML Output
Content Items
Presentation
Items
Sitecore is configured, by default, to cache items; however, what you will need to consider is how large the cache should be for
each database/site. As your site grows, more content items will be used within the same timeframe. In order to properly maintain
all items in the cache, you will need to increase the allocated cache size. There are a number of tools that you can use to monitor
cache-hit performance. The first is the Sitecore Debugger. Part of Sitecore’s profile section, the Debugger provides counts of cache
hits, cache misses and physical reads.
Ideally, item are always read from cache. As the Debugger is simply a snapshot in time, it does not give you a complete picture of
your development environment.
If you are looking for a more complete summary of rendering statistics, the stats.aspx page, which is part of Sitecore’s admin tools
(/Sitecore/admin/stats.aspx), provides an excellent summary of presentation objects for each site. Using this tool, you can easily
see average and maximum rendering times as well as the number of times the rendering was drawn from cache as opposed to
being regenerated. See next page.
BEST PRACTICES FOR SITECORE | 21
The most important thing a developer can learn is how to structure rendering and sub-layouts to maximize the benefits of caching.
There are no hard-and-fast rules for this because the choices you make will depend on the size of your available cache and the
design of your site. That said, here are some good rules of thumb:
1. Building a site with a higher number of small renderings and sublayouts gives you greater flexibility to control the caching of
HTML
2. Navigational controls tend to use the VaryByData option unless content is personalized.
3. Portions of the header and footer often require no variation. Structuring renderings to allow for a single cached instance of such
segments will greatly reduce requirements for cache size and make for better site performance.
4. Over-riding cache settings at an item level often makes sense for high-traffic pages, such as main section pages or campaign
landing pages. But watch your analytics and use your own judgment.
5. If you have a high number of content items based on a single template, carefully consider how you will set up the caching. If
caching is applied to all items, you may consume a large portion of the cache—especially if the traffic is distributed amongst the
items (such as with news releases). Instead, you may consider removing the caching from the news renderings altogether. Or, if
there are some high-hit releases, consider an item-by-item approach.
22 | BEST PRACTICES FOR SITECORE
Now we come to the caching of the rendered HTML. As discussed earlier, Sitecore developers can control this in the standard values
of the presentation objects, in the presentation configuration of templates or in an item-by-item configuration. In Sitecore, HTML
caching must first be enabled for each site. This is done by setting the cacheHTML attribute to true. In the following screenshot, we
can see the available Sitecore 6 caching options:
That should provide you with enough information to get started on caching. Next, we discuss what to do when caching isn’t enough.
BEST PRACTICES FOR SITECORE | 23
Static publication
Sitecore is designed to serve and render database content. However, there are circumstances in which you may want to consider
static publication of HTML files from Sitecore. While uncommon, we do see this in cases where a new promotion or event landing
page is being set up and heavily promoted. Instead of loading the CMS with this (hopefully) overwhelming traffic, a static snapshot
of the content is taken and stored on the web nodes.
At Nonlinear, we prefer to automate static publication as much as possible. By hooking into the publication process, it is possible
to capture the results of the page and then store the resulting HTML and media to a specialized location for static serving of the
content.
This process involves two major complications. Both are related to managing the mixture of content—which is to say, content that‘s
dynamically served by Sitecore and content that is statically served by IIS from a disk.
In order to allow IIS to serve the static files, it is easiest to place those files in a specialized location. This allows for an optimal
configuration of IIS, removing all Sitecore handlers from the execution.
There is also the issue of managing URLs in content. If a dynamically-served page links to a page that is static, the dynamic page
must be aware of the alternate URL (to modify it) or URL redirects need to be put in place. Personally, I prefer the redirect imposed
by the IIS service; however, this does require that Sitecore publish redirect rules to IIS. While not a complex task, this requires a
hook into the Sitecore publication, or whatever program is being used, to grab the static HTML.
24 | BEST PRACTICES FOR SITECORE
But the question is, do you simply delete the old versions of content, or do you move them to an archival location? You’ll have to
weigh the benefits of having the instant availability of old versions—probably most critical if you have a requirement for e-discovery—
against the options of delayed retrieval or outright deletion. With the exception of our clients in the financial sector, most will opt
to archive old content in a separate location, accepting a slightly increased retrieval time in the unlikely event that the content is
required.
These threshold settings dictate under what conditions Sitecore will create a log entry for page execution. The complete list of
options can be found in the table on the following page.
Ideally, your log-monitoring programs will be watching the Sitecore logs and can notify you when required.
First, make sure that you have configured Sitecore and IIS to return friendly error messages. If your site is going down for
performance reasons, IIS is likely to return a HTTP error in the 500 range. If you look into the web.config file, you will find a number
of settings that are relevant to error-handling. You will want to ensure the designated handlers are displaying appropriate messaging
and performing any required notifications.
The complete list of error settings can be found in the table below:
Even better than well-configured error messages, though, is having a hot standby site, which allows you to maintain your online
presence no matter what. This standby site does not have to be a copy of the whole site, but it should provide enough information
so your visitors know what options are available to them — such as contacting a call center or returning to the site once it is restored
in a few hours. You get the idea.
There are two ways of going about standby sites. The first option is to have a separate Sitecore installation (preferably, in a separate
datacenter in a different part of the country or world). This kind of installation typically involves only the web nodes but may also
include the authoring environment. This environment is a (perhaps delayed) mirror of the actual site. In the event of catastrophic
failure in your primary installation and datacenter, you switch over to this secondary system.
Obviously, the cost of the first approach is relatively high. A more moderate approach that also works well is to make use of the
static publication described earlier to create snapshots of the site. This way, you can deploy limited, flat versions of the site. As very
few sites are static, we would recommend that you also publish a simple message to indicate that site functionality is temporarily
reduced.
BEST PRACTICES FOR SITECORE | 27
Conclusion
Performance and scalability issues relating to any large-scale website are almost always complex. Luckily, Sitecore provides
straightforward tools that deliver a high-performance and robust web presence. If you follow the general guidelines in this
whitepaper, you should be well on your way to a successful implementation.
As always, additional information on Sitecore is available on the Sitecore Developer Network (http://sdn5.sitecore.net) and the
Nonlinear Blog (http://blog.nonlinearcreations.com/).
If you find that you need further assistance in your Sitecore upgrade or implementation, you can reach us by email at info@
nonlinear.ca
28 | BEST PRACTICES FOR SITECORE
About Nonlinear
Who is Nonlinear Digital?
Nonlinear Digital is the full-service digital agency division of non-linear creations. With offices across Canada, the USA and Brazil,
Nonlinear has a track record of successfully planning, executing and measuring the effectiveness of digital marketing and outreach
solutions for a range of clients.
We are a full-service digital agency with extensive knowledge and technical expertise in various CMS and marketing/analytics
solutions. Our teams, working with you, use an agile methodology to create unique website and digital experiences that drive
business results in a measurable way.
~~serves your customers’ needs by being memorable, relevant and increasingly personalized and accessible on any device
~~serves your business’ needs by generating meaningful data from which you can extract real insights and metrics tied to your
business goals
Contact us today
http://www.nolinearcreations.com
[email protected]
BEST PRACTICES FOR SITECORE | 29
APPENDIX A
Lucene Example
private void SearchInternal(string search)
{
//Get index for the database by index name
Database db = currentDatabase;
//If index doesn’t exist for the database then index == null
Sitecore.Diagnostics.Error.AssertNotNull(index,
“There is no “ + indexName + “ index on the current
database (“ +
db.Name + “)”);
/*
* QueryParser obtains token stream using the Analizer and creates the Query
* baseing on internal rules.
* QueryParser need to know content field in index to be able to parse queries like
* “Search” or “Example”. These queries will be transformed into
* [content_field]:Search and [content_field]:Example
*/
/*
* In default mode (OR_OPERATOR) terms without any modifiers are considered optional:
* for example Test search is equal to Test OR search.
* In AND_OPERATOR mode terms are considered to be in conjuction: the above mentioned
* query is parsed as Test AND search
*/
qp.SetDefaultOperator(QueryParser.OR_OPERATOR);
30 | BEST PRACTICES FOR SITECORE
/*
* This method converts string query to object Query that can be used in searching
*/
Query query = qp.Parse(search);
includeInSearch.SetBoost(0);
fullQuery.Add(query, BooleanClause.Occur.SHOULD);
fullQuery.Add(includeInSearch, BooleanClause.Occur.MUST);
/*
* Execute search using query and search objects
* This method returns Hits object. It contains documents (search results) collection
* and some additional result information.
*/
//Hits hits = searcher.Search(query);
Hits hits = searcher.Search(fullQuery);
int docsCount = 0;
}
}
//Add some overall search inforamtion
SetResultsSummary(search, docsCount);
}
catch
{
//If search is failed for some reason it’s necessary to inform user about it
string errorText = Translate.Text(“Error executing search request”) + “. “;
errorText += Translate.Text(“Please input a valid search string”) + “.”;
LiteralControl errorControl =
new LiteralControl(“<span style=\”color:Red;
SearchResults.Controls.Add(errorControl);
}
finally
{
// DO NOT forget to close searcher. Because it may lock index.
// Be careful not to call this method while you are still using objects like Hits.
searcher.Close();
}
}