Once you have created your document class, you have to initialize the library in order to operate against the Solr instance. This is usually done once at application startup:
Startup.Init<Product>("http://localhost:8983/solr");Then you ask the service locator for the SolrNet service instance which allows you to issue any supported operation:
var solr = ServiceLocator.Current.GetInstance<ISolrOperations<Product>>();
await solr.DeleteAsync(SolrQuery.All);
await solr.AddAsync(p);
await solr.CommitAsync();
var products = await solr.QueryAsync(new SolrQueryByRange<decimal>("price", 10m, 100m));Install-Package SolrNet.Microsoft.DependencyInjectionTo use, with an IServiceCollection instance and one or more assemblies:
services.AddSolrNet("http://localhost:8983/solr");Install-Package SolrNet.WindsorAlternatively, if your app uses Castle Windsor you can set up SolrNet using the included facility:
container.AddFacility("solr", new SolrNetFacility("http://localhost:8983/solr"));Or using Windsor's xml config:
<castle>
<facilities>
<facility id="solr" type="Castle.Facilities.SolrNetIntegration.SolrNetFacility, SolrNet">
<solrURL>http://localhost:8983/solr</solrURL>
</facility>
</facilities>
</castle>
If you're using Ninject, you can use the Ninject module:
Install-Package SolrNet.Ninjectkernel.Load(new SolrNetModule("http://localhost:8983/solr"));Install-Package SolrNet.StructureMapIf you are using StructureMap, you can use the StructureMap module (StructureMap.SolrNetIntegration):
IEnumerable<SolrServer> solrServers = new[]
{
new SolrServer(id: "test", url: "http://localhost:8893", documentType: "testDocumentType")
};
var container = new StructureMap.Container(SolrNetRegistry.Create(solrServers));Install-Package SolrNet.Autofacvar builder = new ContainerBuilder();
builder.RegisterModule(new SolrNetModule("http://localhost:8983/solr"));
var container = builder.Build();Install-Package SolrNet.Autofacvar solrServers = new SolrServers {
new SolrServerElement {
Id = "test",
Url = "http://localhost:8893",
DocumentType = typeof (Entity).AssemblyQualifiedName,
}
};
container = new UnityContainer();
new SolrNetContainerConfiguration().ConfigureContainer(solrServers, container);If you need to map multiple Solr cores/instances, see this page.