簡體   English   中英

如何覆蓋Solr文檔字段?

[英]How to overwrite the Solr document field?

<arr name="itemDescSpell">
<str>Cable Tie, 4.0L (102mm), Miniature, Nyl</str>
<str>Cable Tie, 4.0L (102mm), Miniature, Nyl</str>
</arr>

itemDescSpellcopyField ,在每次更新Solr Document時copyField導致錯誤。 我不想將字段設置為multiValued="true"

在架構中,copyField的定義如下

<field name="itemDescSpell" type="textSpell"/>
  <copyField source="description" dest="itemDescSpell"/>

錯誤是:

multiple values encountered for non multiValued field itemDescSpell.

在將此字段類型保持為textSpell同時,有人可以通過SolrJ幫助我解決此問題嗎?

嘗試使用自定義的UpdateRequestProcessor覆蓋itemDescSpell字段中存在的值。 Solr會在復制字段目標已經填充時拋出異常,因此您要做的是從架構中刪除copyField行,並將自定義UpdateRequestProcessor添加到配置中,如下所示:

public class CustomFactory extends UpdateRequestProcessorFactory {
    @Override
    public UpdateRequestProcessor getInstance(SolrQueryRequest req, SolrQueryResponse rsp, UpdateRequestProcessor next) {
        return new Custom(next);
    }

    public class Custom extends UpdateRequestProcessor {

        public Custom(UpdateRequestProcessor next){
            super(next);
        }

        @Override
        public void processAdd(AddUpdateCommand cmd) throws IOException {
            cmd.solrDoc.setField("foo",cmd.solrDoc.getFieldValue("bar"));
        }
    }
}

這不是生產就緒的代碼,但是應該使您了解最終代碼的外觀。 要自定義字段值,您可以在工廠中覆蓋init方法,並在配置中傳遞它們。

主要區別在於,solr在遇到copyField時使用addField,而此類使用setField

暫無
暫無

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

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