Return to site

Solrnet Example

broken image


This tutorial will help in indexing sample Solr Docs using Post Utility. Indexing into specific core. Searching queries to fetch data based on Filter query a. SolrNet is a free Open Source API that can be integrated with your.NET web application to build queries programmatically and execute them over Solr. For example: To get search results for keyword 'twitter' we will enter the keyword in the 'Query String' textbox of Solr Admin UI and hit the Search button.

  1. Solrnet Example C#
  2. Solrnet Query Example
  3. Solrnet Example Definition
Solrnet example sample

I got a very relevant question on one of my prior Blog posts:

'I saw you mentioning using SolrNet but i thought ContentSearch was using

SolrNet underneath.what do i gain using one vs another?'

Solrnet example medical

This post shares some of my experiences and thought's on the above question.

First of all, 'Yes', Sitecore ContentSearch uses SolrNet when you choose to use Solr instead of Lucene. So if you are familiar with the Content Search API, you don't have to worry about it really; you just continue to do what you normally do.

Solrnet Example
Solrnet

If you dive in a little deeper there are some differences in flexibility and potentially performance. That's really no surprise since – I see the ContentSearch to be more abstract as it hides some of the specifics of Solr. But say you have a very high performance website, and you have to tune and configure Solr – the actual Solr queries will impact performance.

Let's look at an example. Say that we have some 'Article' items in Sitecore with Title, Body and Category fields. The Category is a Multilist. Below examples on how to do such a query using ContentSearch as well as SolrNet directly to find all Articles in a specific category.

ContentSearch API

The following Content Search query:

Results in a Solr Query like this:

Solrnet Example C#

SolrNet

The following SolrNet Query:

Solrnet Example

I got a very relevant question on one of my prior Blog posts:

'I saw you mentioning using SolrNet but i thought ContentSearch was using

SolrNet underneath.what do i gain using one vs another?'

This post shares some of my experiences and thought's on the above question.

First of all, 'Yes', Sitecore ContentSearch uses SolrNet when you choose to use Solr instead of Lucene. So if you are familiar with the Content Search API, you don't have to worry about it really; you just continue to do what you normally do.

If you dive in a little deeper there are some differences in flexibility and potentially performance. That's really no surprise since – I see the ContentSearch to be more abstract as it hides some of the specifics of Solr. But say you have a very high performance website, and you have to tune and configure Solr – the actual Solr queries will impact performance.

Let's look at an example. Say that we have some 'Article' items in Sitecore with Title, Body and Category fields. The Category is a Multilist. Below examples on how to do such a query using ContentSearch as well as SolrNet directly to find all Articles in a specific category.

ContentSearch API

The following Content Search query:

Results in a Solr Query like this:

Solrnet Example C#

SolrNet

The following SolrNet Query:

Results in a Solr Query like this:

SolrNet

So the difference is around the use of Solr 'FilterQueries' – the fq parameter. Sitecores ContentSearch API converts it into the use of logical AND, where the use of SolrNet directly converts it into separate filter queries.

So the question is what difference does this make?

If you have millions of items in Solr that you query – there will be a difference. The major difference is that with Filter Queries Solr can utilize a FilterCache. If you have a large index, uses a lot of facets and queries it can make a big difference in performance. Also – the filter cache can be configured with more dedicated memory if needed.

What to use?

Depends on the specific solution – as always. It's easy to use the ContentSearch API; so stick to that unless you know that you are working with a lot of data. In some cases, we do both – e.g. if we need a specific Solr function such as 'MoreLikeThis'. SolrNet implements this directly and is easy to use for such a special functionality.

Solrnet Query Example

An obvious question would be if one can extend the existing ContentSearch API – and force it to utilize fq instead? That could be a challenge worth for another Blog post.

Solrnet Example Definition

Relevant links





broken image