c# - Solr & SolrNET connection not working -
c# - Solr & SolrNET connection not working -
i trying larn how utilize solr , solrnet client adapter c#.
i can't past first illustration found @ basics.
is there doing wrong here? can navigate url utilize in code , it's , running. service set using windows installer installer
my solr instance:
my object:
public class product { [solruniquekey("id")] public string id { get; set; } [solrfield("manu_exact")] public string manufacturer { get; set; } [solrfield("cat")] public icollection<string> categories { get; set; } [solrfield("price")] public decimal cost { get; set; } [solrfield("instock")] public bool instock { get; set; } #region overrides of object /// <summary> /// returns string represents current object. /// </summary> /// <returns> /// string represents current object. /// </returns> public override string tostring() { var sb = new stringbuilder("product\n"); sb.appendline(string.format("id - {0}", id)); sb.appendline(string.format("manufacturer - {0}", manufacturer)); sb.appendline(string.format("categories - {0}", categories)); sb.appendline(string.format("price - {0}", price)); sb.appendline(string.format("in stock - {0}", instock)); homecoming sb.tostring(); } #endregion my attempts @ connecting. in unit test project practicing purposes.
[testclass] public class basicexample { private const string solr_connection = "http://localhost:9001/solr"; [testinitialize] public void testinitialize() { startup.init<product>(solr_connection); } [testmethod] public void add() { var product = new product { id = "someid", manufacturer = "samdung of poop", instock = true, cost = 92, categories = new[]{ "electronics", "hard drive"} }; var solr = servicelocator.current.getinstance<isolroperations<product>>(); solr.add(product); solr.commit(); } [testmethod] public void query() { var solr = servicelocator.current.getinstance<isolroperations<product>>(); var result = solr.query(new solrquerybyfield("id", "someid")); result.should().notbenull(); result.count.shouldbeequivalentto(1); console.writeline(result.first().tostring()); } } the error add together method:
test method solr.playground.basicexample.add threw exception: solrnet.exceptions.solrconnectionexception: remote server returned error: (400) bad request. ---> system.net.webexception: remote server returned error: (400) bad request.
the error arises query (i know fail because add together didn't happen, message doesn't indicate issue):
initialization method solr.playground.basicexample.testinitialize threw exception. system.applicationexception: system.applicationexception: key 'solrnet.impl.solrconnection.solr.playground.objects.product.solrnet.impl.solrconnection' registered in container.
edit
i found nuget bundle didn't install latest. pulled update , errors different.
when code calls .commit() method error message:
<?xml version="1.0" encoding="utf-8"?> <response> <lst name="responseheader"><int name="status">400</int><int name="qtime">0</int></lst><lst name="error"><str name="msg">unknown commit parameter 'waitflush'</str><int name="code">400</int></lst> </response> ---> system.net.webexception: remote server returned error: (400) bad request.
you should specify core want connect in url. name of default core comes packaged in installation "collection1", url be: http://localhost:9001/solr/collection1
also, need alter way initializing connection. testinitialize set method called 1 time before each test, if phone call startup.init() multiple times exception. can utilize classinitialize attribute instead, run 1 time tests in class. seek changing test class this:
private const string solr_connection = "http://localhost:9001/solr/collection1"; [classinitialize] public static void testinitialize(testcontext context) { startup.init<product>(solr_connection); } hope it! cheers.
c# solr
Comments
Post a Comment