简体   繁体   English

在Solr上,我如何仅将所选值从多值字段复制到另一个多值字段?

[英]On solr how can i copy selected values only from multi valued field to another multi valued field?

I have indexed solr one of the field is multivalued and it has different values in it and i want to copy selected values into new field. 我已索引Solr该字段之一是多值的,它具有不同的值,我想将选择的值复制到新字段中。

Field1 has value a , b, c and want to copy into Field2 but only value a and c Field1的值分别为a,b和c,并且想要复制到Field2中,但仅值为a和c

The data is came from another instance of solr using dataimport processor="SolrEntityProcessor" 数据是使用dataimportprocessor =“ SolrEntityProcessor”来自另一个Solr实例的

Am using solr 4.9 我正在使用solr 4.9

StatelessScriptUpdateProcessorFactory that enables the use of update processors implemented as scripts during update request. StatelessScriptUpdateProcessorFactory ,用于在更新请求期间使用作为脚本实现的更新处理器。
When we are indexing we get multivalued Field1 and then copy those values which we needed into another field Field2 . 当我们索引,我们得到的多值字段1,然后复制它,我们需要进入另一个领域字段2的值。
[Managed-Schema] [托管模式]

<field name="Field1" type="custom" multiValued="true" indexed="true" stored="true"/>
  <field name="Field2" type="custom" multiValued="true" indexed="true" stored="true"/>

Below is the sample update-script.js . 以下是示例update-script.js

function processAdd(cmd) {
    doc = cmd.solrDoc;
    id = doc.getFieldValue("id");
    Field1 = doc.getFieldValues("Field1");
    logger.info("Size : "+Field1.size());
    for(i = 0; i < Field1.size();i++){
        if(Field1.get(i).equals("a") || Field1.get(i).equals("c")){
            doc.addField("Field2", Field1.get(i));
        }
    }
    logger.info("UpdateScript processed: "+id);

}
function processDelete(cmd) {
  // no-op
}

function processMergeIndexes(cmd) {
  // no-op
}

function processCommit(cmd) {
  // no-op
}

function processRollback(cmd) {
  // no-op
}

function finish() {
  // no-op
}

Add the StatelessScriptUpdateProcessorFactory processor to the updateRequestProcessorChain in solrconfig.xml. 将StatelessScriptUpdateProcessorFactory处理器添加到solrconfig.xml中的updateRequestProcessorChain。

<processor class="solr.StatelessScriptUpdateProcessorFactory">
   <str name="script">update-script.js</str>
 </processor>

What does it mean I want ? 我想要什么意思? Solr can't read your mind. 索尔看不懂你的想法。 So, do you want to skip a specific value, an item in specific position, any item that does not match particular rules? 那么,您是否要跳过特定值,位于特定位置的项目,与特定规则不匹配的任何项目?

In all of the cases, most likely, you will use the UpdateRequestProcessor, but which specific one depends on what your business rule actually means. 在所有情况下,很可能都将使用UpdateRequestProcessor,但是哪种具体情况取决于您的业务规则的实际含义。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM