Solrnet Example



Getting SolrNet and Modeling the Data. Solr provides a REST-like API that you can easily use from any application. Even better, there’s a library called SolrNet (bit.ly/2XwkROA) that provides an abstraction over Solr, allowing you to easily work with strongly typed objects, with plenty of functionality to make search application development. There may be use cases where you want to integrate with Solr using the SolrNet library instead of going through Sitecore Content Search API. This post describes how to configure and work with Solr using SolrNet library with code snippets to perform different queries such as FilterQuery Parameter, Facet Parameters, Filter Query Parameters with Values, Facet Pivot Parameters, Grouping Parameters.

  1. Solrnet Facet Query Example
  2. Solrnet Example C
  3. Solrnet Query Example
  4. Solrnet Cloud Example
  5. Solrnet Example Sample

SolrNet is a .NET Open Source client for Apache Solr. This version of SolrNet is compatible with Solr 1.x to Solr 7.x. This package comes with a build in easy to use Dependency Injection for SolrNet.Core.

Solrnet Facet Query Example

For projects that support PackageReference, copy this XML node into the project file to reference the package.
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

Dependencies

  • .NETFramework 4.6

    • CommonServiceLocator(>= 2.0.2)
    • SolrNet.Core(>= 1.0.19)
  • .NETStandard 2.0

    • CommonServiceLocator(>= 2.0.2)
    • SolrNet.Core(>= 1.0.19)

Used By

NuGet packages (3)

Showing the top 3 NuGet packages that depend on SolrNet:

PackageDownloads
SolrNet.Cloud
SolrNet.Cloud is a .NET Open Source client for Apache SolrCloud. This version of SolrNet.Cloud is compatible with Solr 1.x to Solr 7.x. This package comes with buildin Dependency Injection.
SolisSearch
Solis Search core library for easy integration with your favorite CMS and Apache Solr search server. Indexer currently available for Umbraco and EPiServer.
SoundFingerprinting.Solr
SoundFingerprinting is a C# framework that implements an efficient algorithm of audio fingerprinting and identification. Designed for developers, enthusiasts, researchers in the fields of audio processing, data mining, digital signal processing.
Example

GitHub repositories

This package is not used by any popular GitHub repositories.

Version History

Solrnet Example C

VersionDownloadsLast updated
1.0.19 93,952 11/21/2019
1.0.18 17,620 10/9/2019
1.0.17 52,086 6/25/2019
1.0.16 9,280 6/10/2019
1.0.15 36,650 3/21/2019
1.0.14 30,851 1/28/2019
1.0.13 201,933 10/29/2018
1.0.12 57,886 10/11/2018
1.0.11 15,968 9/22/2018
1.0.10 6,160 7/26/2018
1.0.9 31,119 5/14/2018
1.0.8 92,628 4/2/2018
1.0.7 8,258 3/5/2018
1.0.6 2,101 2/26/2018
1.0.5 8,160 2/13/2018
1.0.3 2,590 2/6/2018
1.0.2 3,460 1/25/2018
1.0.1 10,183 1/16/2018
1.0.0 9,045 1/1/2018
0.9.1 10,951 11/2/2017
0.8.1 5,456 9/27/2017
0.7.1 11,298 8/28/2017
0.5.0-alpha2 32,703 8/20/2015
0.5.0-alpha1 2,172 5/4/2015
0.4.0.4001 159,389 5/3/2015
0.4.0-beta2 19,649 3/5/2012
0.3.1 53,471 3/31/2011
0.3.0 5,044 1/7/2011
Show more

UPDATE 2/19/2009: by now most of this is obsolete, please check out more recent releases

Example

Last month I've been working my a** off integrating Solr to our main site. The first step was to find out how to communicate with the Solr server. Naturally, I came to SolrSharp. But I found it to be really IoC-unfriendly: lots of inheritance, no interfaces, no unit-tests, so it would have been a real PITA to integrate it to Castle. So, instead of wrapping it, I built SolrNet.

Before explaining how it works, a disclaimer: I'm a complete newbie to Solr, Lucene and full-text searching in general. The code works on my machine and does what I need it to do for the task that I have at hand. This project is not, and might never be, feature complete like SolrSharp. Currently it doesn't support facets (UPDATE 8/20/08: I added facet support) or highlights, and maybe some other stuff. If you absolutely need those features right now, either use SolrSharp or write a patch for SolrNet. However, the next step in the integration is implementing faceted search, so I will definitely implement facets sooner or later.

Solrnet Example

Solrnet Query Example

Usage

First we have to map the Solr document to a class (Solr supports only one document type per instance at the moment). Let's use a subset of the default schema that comes with the Solr distribution:

It's just a POCO with a marker interface (ISolrDocument)[1] and some attributes: SolrField maps the attribute to a Solr field and SolrUniqueKey (optional) maps an attribute to a Solr unique key field. Let's add a document (make sure you have a running Solr instance first):

Let's see if the document is there:

Solrnet

For more examples, see the tests.

Solrnet Example

DSL

Solrnet Cloud Example

Since DSLs are such a hot topic nowadays, I decided to give it a try to see what happened. I just defined the syntax I wanted in a test, then wrote the interfaces to comply to the syntax and chain the methods, then built the implementations for those interfaces. The result is pretty much self-explanatory:

Run() is the explicit kicker method[1]. The DSL is defined in a separate DLL, in case you don't want/need it. There are some more examples in the tests.

Solrnet Example Sample

I TDDd most of the project, so the code coverage is near 75%. I'll add the remaining tests if/when I have the time. Of course, as usual, patches/bugfixes are more than welcome :-)

[1] I might drop this requirement in the future.