private static ScoreFunction toScoreFunction()

in tablestore/src/main/java/com/alicloud/openservices/tablestore/core/protocol/SearchQueryParser.java [392:491]


    private static ScoreFunction toScoreFunction(Search.Function pb) throws IOException {
        ScoreFunction scoreFunction = new ScoreFunction();
        if (pb.hasFilter()) {
            scoreFunction.setFilter(toQuery(pb.getFilter()));
        }
        if (pb.hasWeight()) {
            scoreFunction.setWeight(pb.getWeight());
        }

        if (pb.hasFieldValueFactor()) {
            Search.FieldValueFactorFunction pbFvfFunction = pb.getFieldValueFactor();
            FieldValueFactorFunction fvfFunction = new FieldValueFactorFunction();
            if (pbFvfFunction.hasFieldName()) {
                fvfFunction.setFieldName(pbFvfFunction.getFieldName());
            }
            if (pbFvfFunction.hasFactor()) {
                fvfFunction.setFactor(pbFvfFunction.getFactor());
            }
            if (pbFvfFunction.hasModifier()) {
                fvfFunction.setModifier(toModifier(pbFvfFunction.getModifier()));
            }
            if (pbFvfFunction.hasMissing()) {
                fvfFunction.setMissing(pbFvfFunction.getMissing());
            }
            scoreFunction.setFieldValueFactorFunction(fvfFunction);
        }
        if (pb.hasDecay()) {
            Search.DecayFunction pbDFunction = pb.getDecay();
            DecayFunction dFunction = new DecayFunction();
            if (pbDFunction.hasParamType() && pbDFunction.hasParam()) {
                Search.DecayFuncParamType decayParamType = pbDFunction.getParamType();
                switch (decayParamType) {
                    case DF_DATE_PARAM:
                        DecayFuncDateParam decayFuncDateParam = new DecayFuncDateParam();
                        Search.DecayFuncDateParam pbDateParam = Search.DecayFuncDateParam.parseFrom(pbDFunction.getParam().toByteArray());
                        if (pbDateParam.hasOriginString()) {
                            decayFuncDateParam.setOriginString(pbDateParam.getOriginString());
                        }
                        if (pbDateParam.hasOriginLong()) {
                            decayFuncDateParam.setOriginLong(pbDateParam.getOriginLong());
                        }
                        if (pbDateParam.hasScale()) {
                            decayFuncDateParam.setScale(SearchProtocolParser.toDateTimeValue(pbDateParam.getScale()));
                        }
                        if (pbDateParam.hasOffset()) {
                            decayFuncDateParam.setOffset(SearchProtocolParser.toDateTimeValue(pbDateParam.getOffset()));
                        }
                        dFunction.setDecayParam(decayFuncDateParam);
                        break;
                    case DF_GEO_PARAM:
                        DecayFuncGeoParam decayFuncGeoParam = new DecayFuncGeoParam();
                        Search.DecayFuncGeoParam pbGeoParam = Search.DecayFuncGeoParam.parseFrom(pbDFunction.getParam().toByteArray());
                        if (pbGeoParam.hasOrigin()) {
                            decayFuncGeoParam.setOrigin(pbGeoParam.getOrigin());
                        }
                        if (pbGeoParam.hasScale()) {
                            decayFuncGeoParam.setScale(pbGeoParam.getScale());
                        }
                        if (pbGeoParam.hasOffset()) {
                            decayFuncGeoParam.setOffset(pbGeoParam.getOffset());
                        }
                        dFunction.setDecayParam(decayFuncGeoParam);
                        break;
                    case DF_NUMERIC_PARAM:
                        DecayFuncNumericParam decayFuncNumericParam = new DecayFuncNumericParam();
                        Search.DecayFuncNumericParam pbDoubleParam = Search.DecayFuncNumericParam.parseFrom(pbDFunction.getParam().toByteArray());
                        if (pbDoubleParam.hasOrigin()) {
                            decayFuncNumericParam.setOrigin(pbDoubleParam.getOrigin());
                        }
                        if (pbDoubleParam.hasScale()) {
                            decayFuncNumericParam.setScale(pbDoubleParam.getScale());
                        }
                        if (pbDoubleParam.hasOffset()) {
                            decayFuncNumericParam.setOffset(pbDoubleParam.getOffset());
                        }
                        dFunction.setDecayParam(decayFuncNumericParam);
                        break;
                    default:
                        dFunction.setDecayParam(DecayParam.unknownTypeParam());
                }
            }
            if (pbDFunction.hasFieldName()) {
                dFunction.setFieldName(pbDFunction.getFieldName());
            }
            if (pbDFunction.hasMathFunction()) {
                dFunction.setMathFunction(toDecayMathFunction(pbDFunction.getMathFunction()));
            }
            if (pbDFunction.hasDecay()) {
                dFunction.setDecay(pbDFunction.getDecay());
            }
            if (pbDFunction.hasMultiValueMode()) {
                dFunction.setMultiValueMode(toMultiValueMode(pbDFunction.getMultiValueMode()));
            }
            scoreFunction.setDecayFunction(dFunction);
        }
        if (pb.hasRandom()) {
            scoreFunction.setRandomFunction(new RandomFunction());
        }
        return scoreFunction;
    }