SolrNet
SolrNet copied to clipboard
SolrNet using plain SolrConnection when AutoSolrConnection injected with Windsor
In our project we handle SolrNet operations through a repository which we instantiate like this:
//Our project deploys one "case" per client and each client has their own Solr core
//which we name based on their "caseId"
public SolrSearchRepository(int caseId, string solrServer)
{
var coreName = "core_" + caseId;
this.container = new WindsorContainer();
this.container.Register(Component.For<ISolrConnection>()
.ImplementedBy<AutoSolrConnection>()
.DependsOn(Parameter.ForKey("serverUrl").Eq(solrServer)));
this.facility = new SolrNetFacility(solrServer);
this.facility.AddCore(coreName, typeof(SolrDocument), solrServer + "/" + caseId);
this.container.AddFacility(this.facility);
solrOperation = this.container.Resolve<ISolrOperations<SolrDocument>>(coreName);
}
Where ISolrConnection
is implemented by the AutoSolrConnection
class @gjunge recently contributed.
With this setup SolrNet is still using a GET request when sending queries.
I looked deeper into the matter and luckily I found this:
https://github.com/SolrNet/SolrNet/blob/5793e6ccbe94f09bf9b45c594fbf7d86d0a84c4a/Castle.Facilities.SolrNetIntegration/SolrNetFacility.cs#L193
where I noticed that AddCore
takes a postConnection
parameter. Supplying a true
value for the postConnection
param toggled a POST request for queries.
I was thus able to reduce my core setup to:
//Our project deploys one "case" per client and each client has their own Solr core
//which we name based on their "caseId"
public SolrSearchRepository(int caseId, string solrServer)
{
var coreName = "core_" + caseId;
this.container = new WindsorContainer();
this.facility = new SolrNetFacility(solrServer);
this.facility.AddCore(coreName, typeof(SolrDocument), solrServer + "/" + caseId);
this.container.AddFacility(this.facility);
solrOperation = this.container.Resolve<ISolrOperations<SolrDocument>>(coreName);
}
I have the following questions and comments:
- Since I'm using the
SolrnetFacility
does that override any components I register on theWindsorContainer
? If yes, how could I useAutoSolrConnection
? - There is no documentation on how to implement
SolrPostConnection
on a multi-core setup. - There is no documentation on
AutoSolrcConnection
For comments 2) and 3) I'd be happy to push a PR if there's interest.
Regarding documentation, please contribute as much as possible. For the other question, perhaps @gjunge may have an answer.
AutosolrConnection
has not been added to the other DI containers. I'm not really familiar with Windsor, so I wouldn't be able to tell you what takes presedence. I do think it might be good to change the implementation, and by default use the AutoSolrConnection
.