0

solrからデータを取得しているときに、エラーが発生しています

同じキーを持つアイテムが既に追加されています

    public  static void Solryeg()
    {
        ISolrOperations<SolrContent> solr = ServiceLocator.Current
                                  .GetInstance<ISolrOperations<SolrContent>>();

        var q = solr.Query(SolrQuery.All);
    }

SolrContent.cs

public class SolrContent
{
    [SolrUniqueKey("ContentId")]
    public int ContentId { get; set; }


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

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

    [SolrField("ContentIsActive")]
    public bool ContentIsActive { get; set; }

    [SolrField("ContentRatingEnabled")]
    public bool ContentRatingEnabled { get; set; }

   ...
4

1 に答える 1

1

In your SolrContent.cs class you have added the SolrUniqueKey attribute to the ContentId property that maps to the ContentId field in your schema. This is therefore, stating that the ContentId field in the Solr index will always contain a unique value. However, your index currently has multiple items with the same ContentId value. There are a couple of ways around this error.

  1. Change the attribute on ContentId property to be just [SolrField("ContentId")]
  2. Fix your index so that the ContentId field only contains unique values.

I recommend you go with the 2nd option as this will follow the true intent of what you are trying to achieve. However, you might try the first one just to validate you can query the Solr index without the error and then figure out how your index has multiple items with the same ContentId and the fix that issue as well.

于 2012-10-08T14:55:03.880 に答える