簡體   English   中英

Solrnet有效負載-添加文檔時出現異常

[英]Solrnet Payloads - exception when I add documents

我正在嘗試從用戶輸入的具有關聯權重的標簽中索引一組圖像。 我正在嘗試使用輸入的權重作為有效載荷。 我按照這篇文章創建了字典對象。

我不確定在哪里添加分隔的字段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>

發布答案,希望它能像我一樣幫助其他人:

*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);
                                }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM