1

solrnet.dll および Microsoft.Practices.ServiceLocation.dll を使用して solrNet を使用して Tomcate Windows XP で実行すると、エラーが発生します。リモート サーバーがエラーを返します。(400) 要求が正しくありません。

このコードにコンテンツを追加するとき

solr.Add(new Article()
    {
        _id = 1,
        _title = "My Laptop",
        _content = "My laptop is portable power station",
        _tags = new List<string>() {
        "laptop","computer","device"
        }

    });

私は以下のコードを使用しています...

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SolrNet;
using SolrNet.Attributes;
using SolrNet.Commands.Parameters;
using Microsoft.Practices.ServiceLocation;

namespace solrIndex_creator
{

 class Article
  {
    [SolrUniqueKey("id1")]
    public int _id { get; set; }

    [SolrField("title1")]
    public string _title { get; set; }

    [SolrField("content1")]
    public string _content { get; set; }

    [SolrField("tag1")]
    public List<string> _tags { get; set; }

    ISolrOperations<Article> solr;

   public void _write_Data()
    {
      Startup.Init<Article>("http://localhost:8080/solr/");
      solr = ServiceLocator.Current.GetInstance<ISolrOperations<Article>>();

       solr.Add(new Article()
        {
            _id = 1,
            _title = "My Laptop",
            _content = "My laptop is portable power station",
            _tags = new List<string>() {
            "laptop","computer","device"
            }

        });

       solr.Add(new Article()
        {
            _id = 2,
            _title = "my iphone",
            _content = "my iphone consumes power",
            _tags = new List<string>() {   
                "phone",   
                "apple",  
                "device"  
            }
        });

        solr.Add(new Article()
        {
            _id = 3,
            _title = "your blackberry",
            _content = "your blackberry has an alt key",
            _tags = new List<string>() {   
            "phone",   
            "rim",  
            "device"  
            }
        });
        solr.Commit();
    }
4

1 に答える 1

2

このエラーは、Solr の schema.xml<fields>設定と Article クラスの不一致に関連している可能性があります。プログラムをデバッグし、Bad Request エラーを調べて、問題の詳細を確認できるはずです。または、(Jetty、Tomcat などのホスティング コンテナー内の) Solr のサーバー ログで詳細を調べることもできます。

Additionally, I would change your Tags property on the Article class to be the more generic ICollection like the multiValued examples on the SolrNet Mapping wiki.

于 2013-07-11T11:30:49.567 に答える