我已经到了 SolrNet 执行“添加”方法的地步,但是当我尝试“提交”时,我收到了错误。以下是我的 schema.xml、模型、调用它的代码以及我得到的错误。更奇怪的是,尽管出现了错误,但在我重新启动 Tomcat 之后,模型仍被添加到了我的 Solr 索引中(因此尽管出现了错误,但它仍然添加了我的模型,但不是立即添加):
schema.xml(字段和字段类型):
<!-- Fields -->
<field name="part_numbers" type="my_string_exact" indexed="true" stored="true" multiValued="true" />
<field name="page_url" type="my_string_exact" indexed="true" stored="true" />
<field name="product_name" type="my_string" indexed="true" stored="true" />
<!-- FieldTypes -->
<fieldType name="my_string_exact" class="solr.StrField" sortMissingLast="true" omitNorms="true"/>
<fieldType name="my_string" class="solr.TextField" sortMissingLast="true" omitNorms="true">
<analyzer type="index">
<tokenizer class="solr.KeywordTokenizerFactory" />
<filter class="solr.LowerCaseFilterFactory" />
</analyzer>
<analyzer type="query">
<tokenizer class="solr.KeywordTokenizerFactory" />
<filter class="solr.LowerCaseFilterFactory" />
</analyzer>
</fieldType>
<fieldType name="my_int" class="solr.IntField" omitNorms="true" />
模型 (Product.cs) *注意 - PageId 使用 Solr 默认“id”,它是一个字符串,唯一且必需:
public class Product
{
[SolrUniqueKey("id")]
public string PageId { get; set; }
[SolrField("part_numbers")]
public ICollection<string> PartNumbers { get; set; }
[SolrField("page_url")]
public string PageUrl { get; set; }
[SolrField("product_name")]
public string Name { get; set; }
}
代码初始化,调用 Add and Commit *注意 - 这是一个单元测试,所以 init 只被调用一次:
Startup.Init<Product>("http://localhost:8080/solr");
Product testProd = new Product() {
EPiPageId = "44",
Name = "TestProd3",
PageUrl = "/TestProd3",
PartNumbers = new List<string>() { "000022222", "000000333333" }
};
var solr = ServiceLocator.Current.GetInstance<ISolrOperations<Product>>();
solr.Add(testProd);
solr.Commit(); // Bad Request Error occurs here.
错误消息:
SolrNet.Exceptions.SolrConnectionException was unhandled by user code
HResult=-2146232832
Message=The remote server returned an error: (400) Bad Request.
Source=SolrNet
StackTrace:
at SolrNet.Impl.SolrConnection.Post(String relativeUrl, String s) in c:\prg\SolrNet\svn\SolrNet\Impl\SolrConnection.cs:line 104
at SolrNet.Commands.CommitCommand.Execute(ISolrConnection connection) in c:\prg\SolrNet\svn\SolrNet\Commands\CommitCommand.cs:line 71
at SolrNet.Impl.SolrBasicServer`1.Send(ISolrCommand cmd) in c:\prg\SolrNet\svn\SolrNet\Impl\SolrBasicServer.cs:line 87
at SolrNet.Impl.SolrBasicServer`1.SendAndParseHeader(ISolrCommand cmd) in c:\prg\SolrNet\svn\SolrNet\Impl\SolrBasicServer.cs:line 91
at SolrNet.Impl.SolrBasicServer`1.Commit(CommitOptions options) in c:\prg\SolrNet\svn\SolrNet\Impl\SolrBasicServer.cs:line 54
at SolrNet.Impl.SolrServer`1.Commit() in c:\prg\SolrNet\svn\SolrNet\Impl\SolrServer.cs:line 24
InnerException: System.Net.WebException
HResult=-2146233079
Message=The remote server returned an error: (400) Bad Request.
Source=System
StackTrace:
at System.Net.HttpWebRequest.GetResponse()
at HttpWebAdapters.Adapters.HttpWebRequestAdapter.GetResponse() in c:\prg\SolrNet\svn\HttpWebAdapters\Impl\HttpWebRequestAdapter.cs:line 36
at SolrNet.Impl.SolrConnection.GetResponse(IHttpWebRequest request) in c:\prg\SolrNet\svn\SolrNet\Impl\SolrConnection.cs:line 160
at SolrNet.Impl.SolrConnection.Post(String relativeUrl, String s) in c:\prg\SolrNet\svn\SolrNet\Impl\SolrConnection.cs:line 101
InnerException:
编辑感谢 Paige 的回答:问题是“waitFlush”错误,这是旧版本 SolrNet 的错误。我使用的 SolrNet 版本来自 VS NuGet,它是 0.3.1(我认为这是他们最新的稳定版本)。他们的谷歌代码站点没有最新的构建,但构建服务器(这里:http ://teamcity.codebetter.com/project.html?projectId=project36&guest=1在“artifacts”下)确实有最新的修复这个错误。问题为我解决了。