Question

I'm using SolrNet.0.3.1 and SolrNet.Ninject.0.3.1 in an ASP.NET MVC 3 app pointing to a Solr 3.4 instance.

I'm using multiple cores so I can test out schema changes on a second core without breaking the app. Multiple cores are not the problem per se; the app happily uses "core-live" while I'm beating "core-ondeck" to death with dumb typos and tweaks to the schema.

Solrnet's service location is http://[server]:8983/[solr-instance]/ and defaults to core-live via the instance's solr.xml defaultCoreName setting.

# solrnet service location
http://[server]:8983/[solr-instance]/

# instance's solr.xml settings for multiple cores
<solr sharedLib="lib" persistent="true">
  <cores adminPath="/admin/cores" defaultCoreName="core-live">
    <core name="core-live" instanceDir="conf/core0/" />
    <core name="core-ondeck" instanceDir="conf/core1/" />
  </cores>
</solr>

After testing schema changes on the second core from Solr's browser admin GUI, I swap cores and the app should now use the core I just modified.

# swap cores so app uses modified schema and index
curl "http://[server]:8983/[solr-instance]/admin/cores?action=SWAP&name=core-live&other=core-ondeck"

Except solrnet doesn't take notice of the schema changes and, for example, blows up on a query because the field that was of type String in the old schema is now of type DateTime in the new.

[ArgumentException: Object of type 'System.DateTime' cannot be converted to type 'System.String'.]
   System.RuntimeType.TryChangeType(Object value, Binder binder, CultureInfo culture, Boolean needsSpecialCast) +6429224
   System.RuntimeType.CheckValue(Object value, Binder binder, CultureInfo culture, BindingFlags invokeAttr) +12711129
   System.Reflection.MethodBase.CheckArguments(Object[] parameters, Binder binder, BindingFlags invokeAttr, CultureInfo culture, Signature sig) +129
   System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks) +522
   System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) +38
   System.Reflection.RuntimePropertyInfo.SetValue(Object obj, Object value, Object[] index) +44
   SolrNet.Impl.DocumentPropertyVisitors.RegularDocumentVisitor.Visit(Object doc, String fieldName, XmlNode field) in c:\prg\SolrNet\svn\SolrNet\Impl\DocumentPropertyVisitors\RegularDocumentVisitor.cs:48
   SolrNet.Impl.DocumentPropertyVisitors.AggregateDocumentVisitor.Visit(Object doc, String fieldName, XmlNode field) in c:\prg\SolrNet\svn\SolrNet\Impl\DocumentPropertyVisitors\AggregateDocumentVisitor.cs:37
   SolrNet.Impl.DocumentPropertyVisitors.DefaultDocumentVisitor.Visit(Object doc, String fieldName, XmlNode field) in c:\prg\SolrNet\svn\SolrNet\Impl\DocumentPropertyVisitors\DefaultDocumentVisitor.cs:39
   SolrNet.Impl.SolrDocumentResponseParser`1.ParseDocument(XmlNode node, ICollection`1 fields) in c:\prg\SolrNet\svn\SolrNet\Impl\SolrDocumentResponseParser.cs:65
   SolrNet.Impl.SolrDocumentResponseParser`1.ParseResults(XmlNode parentNode) in c:\prg\SolrNet\svn\SolrNet\Impl\SolrDocumentResponseParser.cs:50
   SolrNet.Impl.ResponseParsers.ResultsResponseParser`1.Parse(XmlDocument xml, SolrQueryResults`1 results) in c:\prg\SolrNet\svn\SolrNet\Impl\ResponseParsers\ResultsResponseParser.cs:41
   SolrNet.Impl.SolrQueryResultParser`1.Parse(String r) in c:\prg\SolrNet\svn\SolrNet\Impl\SolrQueryResultParser.cs:46
   SolrNet.Impl.SolrQueryExecuter`1.Execute(ISolrQuery q, QueryOptions options) in c:\prg\SolrNet\svn\SolrNet\Impl\SolrQueryExecuter.cs:309
   SolrNet.Impl.SolrBasicServer`1.Query(ISolrQuery query, QueryOptions options) in c:\prg\SolrNet\svn\SolrNet\Impl\SolrBasicServer.cs:83
   SolrNet.Impl.SolrServer`1.Query(ISolrQuery query, QueryOptions options) in c:\prg\SolrNet\svn\SolrNet\Impl\SolrServer.cs:50
   Andornot.FhaPhem.Core.Search.SolrSearchOperations.GetResults(ISearchParameters searchParameters) in C:\svn\Client Projects\Fraser Health\PHEM\trunk\Web\Andornot.FhaPhem.Core\Search\SolrSearchOperations.cs:55
   Andornot.FhaPhem.Core.Search.SolrSearchOperations.Query(ISearchParameters searchParameters) in C:\svn\Client Projects\Fraser Health\PHEM\trunk\Web\Andornot.FhaPhem.Core\Search\SolrSearchOperations.cs:29
   Andornot.FhaPhem.Web.Controllers.SearchController.Results(Nullable`1 id) in C:\svn\Client Projects\Fraser Health\PHEM\trunk\Web\Andornot.FhaPhem.Web\Controllers\SearchController.cs:77
   lambda_method(Closure , ControllerBase , Object[] ) +118
   System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) +264
   System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +39
   System.Web.Mvc.<>c__DisplayClass15.<InvokeActionMethodWithFilters>b__12() +129
   System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation) +826410
   System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation) +826410
   System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext controllerContext, IList`1 filters, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +314
   System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +825632
   System.Web.Mvc.Controller.ExecuteCore() +159
   System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +335
   System.Web.Mvc.<>c__DisplayClassb.<BeginProcessRequest>b__5() +62
   System.Web.Mvc.Async.<>c__DisplayClass1.<MakeVoidDelegate>b__0() +20
   System.Web.Mvc.<>c__DisplayClasse.<EndProcessRequest>b__d() +54
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +469
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +375

How do I refresh solrnet's understanding of the schema on the fly, in a way that would work with core swapping?

Was it helpful?

Solution

Here's an analogous situation, using tools that are probably more familiar:

You have a relational database (let's say Microsoft SQL Server) with a table "Person" with a field "data" of type varchar. In your code, you access this table through an ORM (NHibernate or EF, doesn't matter), where you have a class Person with a property data of type string in C# .

Now you edit the table's schema with SQL Server Enterprise Manager, and change the datatype of the field "data" to datetime.

Unless you update your code too to reflect this schema change, your code will break.

This is exactly what's happening in your case, except with Solr instead of a relational database, and SolrNet instead of an ORM. You're trying to get a date from Solr into a string property.

Solutions:

  • Update your code to reflect the changes in your new schema.
  • Switch to SolrNet fully loose mapping. Not really recommended, it will probably blow up anyway with a change like that.

OTHER TIPS

I believe your issue is related to how you have your mapping setup in SolrNet. If you are changing the field type in your Solr schema, you will need to make the same corresponding change in your SolrNet mapping.

In order to allow SolrNet to work with on the fly schema changes, you will need to implemetn one of the following:

  1. Follow the "Fully loose mapping" section defined in the SolrNet Mapping documentation.
  2. Dynamically change your SolrNet mapped class when the schema has been changed to a new mapped class that matches the new schema.

The first option will probably be the easiest way.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top