All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.greencheek.related.plugins.relateddocsmerger.RelatedDocsMergerFactory Maven / Gradle / Ivy

Go to download

Related Content Document Merging Plugin that updates related document based on if the content has changed or not.

The newest version!
package org.greencheek.related.plugins.relateddocsmerger;

import org.elasticsearch.common.Nullable;
import org.elasticsearch.script.ExecutableScript;
import org.elasticsearch.script.NativeScriptFactory;
 
import java.util.Map;
 
public class RelatedDocsMergerFactory implements NativeScriptFactory {

    protected static final String DEFAULT_COMPARATOR_STRING_KEY = "sha256";
    protected static final String COMPARATOR_PARAM = "comparator-key";

    @Override
    public ExecutableScript newScript(@Nullable Map params) {
        if(params==null) {
            return new RelatedDocsMergerScript(params,DEFAULT_COMPARATOR_STRING_KEY,null);
        }

        String documentComparatorValue = null;
        String documentComparatorKey = DEFAULT_COMPARATOR_STRING_KEY;
        Object comparator = params.remove(COMPARATOR_PARAM);
        if(comparator==null) {
            comparator = params.get(DEFAULT_COMPARATOR_STRING_KEY);

        } else {
            if(comparator instanceof String) {
                documentComparatorKey = (String)comparator;
            }
            comparator = params.get(documentComparatorKey);
            if(comparator == null) {
                documentComparatorKey = DEFAULT_COMPARATOR_STRING_KEY;
                comparator = params.get(DEFAULT_COMPARATOR_STRING_KEY);
            }
        }

        if(comparator instanceof String) {
            documentComparatorValue = (String)comparator;
        }

        return new RelatedDocsMergerScript(params,documentComparatorKey,documentComparatorValue);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy