使用solrnet查询时出错 - "根级别的数据无效。第1行,第1和第34行;

时间:2017-12-27 11:22:52

标签: asp.net .net solr asp.net-mvc-5 solrnet

我正在使用 solr 7 solrnet 0.4.0.4001 。当我查询solr时发生异常:

  

类型' System.Xml.XmlException'的例外情况发生在   System.Xml.dll但未在用户代码中处理

其他信息:

  

根级别的数据无效。第1行,第1位。

using Microsoft.Practices.ServiceLocation;
using SolrApp.Entities;
using SolrApp.Models;
using SolrNet;
using SolrNet.Commands.Parameters;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace SolrApp.Controllers
{
    public class HomeController : Controller
    {
        // GET: Home
        public ActionResult Index()
        {
            // find the service   
            Startup.Init<Products>("http://localhost:8983/solr/pro");
            ISolrOperations<Products> solr = ServiceLocator.Current.GetInstance<ISolrOperations<Products>>();

            var entityObj = new testEntities();

            var pro = entityObj.Products.Select(x => new Products { Id = x.Id, Name = x.Name }).ToList();
            solr.Delete(SolrQuery.All);
            solr.AddRange(pro);

            // commit to the index  
            solr.Commit();

            return View();
        }

        public JsonResult Search()
        {
            ISolrOperations<Products> solr = ServiceLocator.Current.GetInstance<ISolrOperations<Products>>();



            var appleProducts = solr.Query(new SolrQuery("*:*"));

            List<Products> prodList = new List<Products>();
            foreach (Products product in appleProducts)
            {
                var prod = new Products()
                { Id = product.Id, Name = product.Name };
                prodList.Add(prod);
            }
            return Json("", JsonRequestBehavior.AllowGet);
        }
    }
}

0 个答案:

没有答案