我想使用 Solr.NET 从正在运行的 .NET Core 应用程序与本地运行的 solr 实例建立连接。问题是我在尝试查询 solr 时总是收到 404 错误。
这是代码:
在启动中.cs我将实例添加到 IServiceCollection:
services.AddSolrNet("https://localhost:8982/solr");
在我的控制器中,我尝试了这个:
List<AppointmentSearchResult> content = new List<AppointmentSearchResult>();
SolrQueryResults<AppointmentSearchResult> results = _solr.Query(new SolrQueryByField("locked", "true"));
foreach (AppointmentSearchResult result in results)
{
content.Add(result);
}
string json = JsonConvert.SerializeObject(content);
return this.Content(json);
AppointmentSearchResult 类如下所示:
public class AppointmentSearchResult
{
[SolrUniqueKey("id")]
public string id { get; set; }
[SolrField("locked")]
public bool? locked { get; set; }
[SolrField("unique_key")]
public string unique_key { get; set; }
[SolrField("busy")]
public bool? busy { get; set; }
[SolrField("done")]
public bool? done { get; set; }
[SolrField("duration")]
public string duration { get; set; }
[SolrField("customerid")]
public double customerid { get; set; }
[SolrField("planning")]
public string planning { get; set; }
[SolrField("employee_id")]
public int? employee_id { get; set; }
[SolrField("date")]
public DateTime date { get; set; }
[SolrField("done_date")]
public DateTime? done_date { get; set; }
[SolrField("calendar_event_id")]
public string calendar_event_id { get; set; }
[SolrField("note")]
public string note { get; set; }
}
这是正确的方法吗?我总是收到错误:处理请求时发生未处理的异常。Web异常:远程服务器返回错误:(404( 未找到。
如果有人对我有建议,那就太好了!
最好的问候,安德烈亚斯
SolrNet v1.0.17 的文档显示了两个 IServiceCollection 添加项,一个用于常规 solr 实例,就像您所做的那样,另一个用于指定文档类型的特定核心。 例如
services.AddSolrNet("https://localhost:8982/solr");
services.AddSolrNet<AppointmentSearchResult>("https://localhost:8982/solr/core1");
https://github.com/SolrNet/SolrNet/blob/master/Documentation/Initialization.md
这就是我在创业.cs中的做法,并且没有像您遇到的问题那样的问题。
solr 连接需要用户名和密码吗?试试这个。
services.AddSolrNet(o =>
{
o.ServerUrl = "https://localhost:8982/solr";
o.UserName = "sa";
o.Password = "sa";
});