2016-05-15 41 views
0

我想从用户输入的标签中索引一组图像,并带有相关的权重。我正在尝试使用输入的权重作为有效载荷。我遵循这个post并创建了字典对象。Solrnet Payloads - 当我添加文档时出现异常

我不知道在哪里添加分隔场colors.Add(tag_name, (float)score);还是应colors.Add("color_p", "tag_name |score");

如何使用在后提到的字典对象?

Dictionary<string, float> colors = new Dictionary<string, float>(); 
          tags = TagUtils.GetTags(image, models["colors"]); 
          N = tags.TagNames.Count; 
          for (int n = 0; n < N; n++) 
          { 
           string tag_name = tags.TagNames[n]; 
           int score = tags.Scores[n]; 
           colors.Add(tag_name, (float)score); 
          } 

          docs_list.Add(new SolrDocument 
          { 
           _product_id = product_id, 
           _product_type = product_type, 
           _url = url, 
           _sku = sku, 
           _images = images.ToList<string>(), 
           _price = (float)price, 
           _name = name, 
           _color_p = colors,<--my payloads type field 
          }); 

schema.xml看起来是这样的:

<field name="color_p" type="payloads" indexed="true" stored="true" multiValued="true"/> 

和定义是这样的:

<fieldtype name="payloads" stored="false" indexed="true" class="solr.TextField" > 
     <analyzer> 
      <tokenizer class="solr.WhitespaceTokenizerFactory"/> 
      <filter class="solr.DelimitedPayloadTokenFilterFactory" encoder="float" delimiter="|" /> 
     </analyzer> 
    </fieldtype> 

回答

0

发布一个答案,希望它可以帮助别人卡住,好像我是:

*Dictionary<string, float> colors = new Dictionary<string, float>();* 

实际上应该是

Dictionary<string> colors = new Dictionary<string>(); 

,并添加如下:

       tags = colorTags.Result; 
           N = tags.TagNames.Count; 
           for (int n = 0; n < N; n++) 
           { 
            string tag_name = tags.TagNames[n]; 
            int score = tags.Scores[n]; 
            if (score > 0) 
             colors.Add(tag_name + "|" + score); 
           } 
相关问题