当前位置: 首页>>代码示例>>Java>>正文


Java ScoreFunction类代码示例

本文整理汇总了Java中org.elasticsearch.common.lucene.search.function.ScoreFunction的典型用法代码示例。如果您正苦于以下问题:Java ScoreFunction类的具体用法?Java ScoreFunction怎么用?Java ScoreFunction使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ScoreFunction类属于org.elasticsearch.common.lucene.search.function包,在下文中一共展示了ScoreFunction类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testWeightFactorNeedsScore

import org.elasticsearch.common.lucene.search.function.ScoreFunction; //导入依赖的package包/类
public void testWeightFactorNeedsScore() {
    for (boolean needsScore : new boolean[] {true, false}) {
        WeightFactorFunction function = new WeightFactorFunction(10.0f, new ScoreFunction(CombineFunction.REPLACE) {
            @Override
            public LeafScoreFunction getLeafScoreFunction(LeafReaderContext ctx) throws IOException {
                return null;
            }

            @Override
            public boolean needsScores() {
                return needsScore;
            }

            @Override
            protected boolean doEquals(ScoreFunction other) {
                return false;
            }

            @Override
            protected int doHashCode() {
                return 0;
            }
        });
        assertEquals(needsScore, function.needsScores());
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:27,代码来源:FunctionScoreTests.java

示例2: doToFunction

import org.elasticsearch.common.lucene.search.function.ScoreFunction; //导入依赖的package包/类
@Override
protected ScoreFunction doToFunction(QueryShardContext context) {
    try {
        SearchScript searchScript = context.getSearchScript(script, ScriptContext.Standard.SEARCH);
        return new ScriptScoreFunction(script, searchScript);
    } catch (Exception e) {
        throw new QueryShardException(context, "script_score: the script could not be loaded", e);
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:10,代码来源:ScriptScoreFunctionBuilder.java

示例3: doToFunction

import org.elasticsearch.common.lucene.search.function.ScoreFunction; //导入依赖的package包/类
@Override
protected ScoreFunction doToFunction(QueryShardContext context) {
    MappedFieldType fieldType = context.getMapperService().fullName(field);
    IndexNumericFieldData fieldData = null;
    if (fieldType == null) {
        if(missing == null) {
            throw new ElasticsearchException("Unable to find a field mapper for field [" + field + "]. No 'missing' value defined.");
        }
    } else {
        fieldData = context.getForField(fieldType);
    }
    return new FieldValueFactorFunction(field, factor, modifier, missing, fieldData);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:14,代码来源:FieldValueFactorFunctionBuilder.java

示例4: doToFunction

import org.elasticsearch.common.lucene.search.function.ScoreFunction; //导入依赖的package包/类
@Override
protected ScoreFunction doToFunction(QueryShardContext context) throws IOException {
    AbstractDistanceScoreFunction scoreFunction;
    // EMPTY is safe because parseVariable doesn't use namedObject
    try (XContentParser parser = XContentFactory.xContent(functionBytes).createParser(NamedXContentRegistry.EMPTY, functionBytes)) {
        scoreFunction = parseVariable(fieldName, parser, context, multiValueMode);
    }
    return scoreFunction;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:10,代码来源:DecayFunctionBuilder.java

示例5: doEquals

import org.elasticsearch.common.lucene.search.function.ScoreFunction; //导入依赖的package包/类
@Override
protected boolean doEquals(ScoreFunction other) {
    NumericFieldDataScoreFunction numericFieldDataScoreFunction = (NumericFieldDataScoreFunction) other;
    if (super.doEquals(other) == false) {
        return false;
    }
    return Objects.equals(this.origin, numericFieldDataScoreFunction.origin);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:9,代码来源:DecayFunctionBuilder.java

示例6: doToFunction

import org.elasticsearch.common.lucene.search.function.ScoreFunction; //导入依赖的package包/类
@Override
protected ScoreFunction doToFunction(QueryShardContext context) {
    final MappedFieldType fieldType = context.getMapperService().fullName("_uid");
    if (fieldType == null) {
        // mapper could be null if we are on a shard with no docs yet, so this won't actually be used
        return new RandomScoreFunction();
    }
    final int salt = (context.index().getName().hashCode() << 10) | context.getShardId();
    final IndexFieldData<?> uidFieldData = context.getForField(fieldType);
    return new RandomScoreFunction(this.seed == null ? hash(context.nowInMillis()) : seed, salt, uidFieldData);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:12,代码来源:RandomScoreFunctionBuilder.java

示例7: toFunction

import org.elasticsearch.common.lucene.search.function.ScoreFunction; //导入依赖的package包/类
/**
 * Called on a data node, converts this ScoreFunctionBuilder into its corresponding Lucene function object.
 */
public final ScoreFunction toFunction(QueryShardContext context) throws IOException {
    ScoreFunction scoreFunction = doToFunction(context);
    if (weight == null) {
        return scoreFunction;
    }
    return new WeightFactorFunction(weight, scoreFunction);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:11,代码来源:ScoreFunctionBuilder.java

示例8: getFiltersFunctionScoreQuery

import org.elasticsearch.common.lucene.search.function.ScoreFunction; //导入依赖的package包/类
public FiltersFunctionScoreQuery getFiltersFunctionScoreQuery(FiltersFunctionScoreQuery.ScoreMode scoreMode,
        CombineFunction combineFunction, ScoreFunction... scoreFunctions) {
    FilterFunction[] filterFunctions = new FilterFunction[scoreFunctions.length];
    for (int i = 0; i < scoreFunctions.length; i++) {
        filterFunctions[i] = new FiltersFunctionScoreQuery.FilterFunction(
            new TermQuery(TERM), scoreFunctions[i]);
    }
    return new FiltersFunctionScoreQuery(new TermQuery(TERM), scoreMode, filterFunctions, Float.MAX_VALUE, Float.MAX_VALUE * -1,
            combineFunction);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:11,代码来源:FunctionScoreTests.java

示例9: parse

import org.elasticsearch.common.lucene.search.function.ScoreFunction; //导入依赖的package包/类
/**
 * Parses bodies of the kind
 *
 * <pre>
 * <code>
 * {
 *      "fieldname1" : {
 *          "origin" = "someValue",
 *          "scale" = "someValue"
 *      }
 *
 * }
 * </code>
 * </pre>
 *
 * */
@Override
public ScoreFunction parse(QueryParseContext parseContext, XContentParser parser) throws IOException, QueryParsingException {
    String currentFieldName;
    XContentParser.Token token;
    AbstractDistanceScoreFunction scoreFunction;
    String multiValueMode = "MIN";
    XContentBuilder variableContent = XContentFactory.jsonBuilder();
    String fieldName = null;
    while ((token = parser.nextToken()) == XContentParser.Token.FIELD_NAME) {
        currentFieldName = parser.currentName();
        token = parser.nextToken();
        if (token == XContentParser.Token.START_OBJECT) {
            variableContent.copyCurrentStructure(parser);
            fieldName = currentFieldName;
        } else if (parseContext.parseFieldMatcher().match(currentFieldName, MULTI_VALUE_MODE)) {
            multiValueMode = parser.text();
        } else {
            throw new ElasticsearchParseException("malformed score function score parameters.");
        }
    }
    if (fieldName == null) {
        throw new ElasticsearchParseException("malformed score function score parameters.");
    }
    XContentParser variableParser = XContentFactory.xContent(variableContent.string()).createParser(variableContent.string());
    scoreFunction = parseVariable(fieldName, variableParser, parseContext, MultiValueMode.fromString(multiValueMode.toUpperCase(Locale.ROOT)));
    return scoreFunction;
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:44,代码来源:DecayFunctionParser.java

示例10: parse

import org.elasticsearch.common.lucene.search.function.ScoreFunction; //导入依赖的package包/类
@Override
public ScoreFunction parse(QueryParseContext parseContext, XContentParser parser) throws IOException, QueryParsingException {
    String currentFieldName = null;
    List<CondBoostEntry> condArray = new LinkedList<>();
    float defaultBoost = 1.0f;
    float boostFactor = 1.0f;
    CondBoostFactorFunction.Modifier modifier = CondBoostFactorFunction.Modifier.NONE;
    XContentParser.Token token;
    while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
        if (token == XContentParser.Token.FIELD_NAME) {
            currentFieldName = parser.currentName();
        } else if (token == XContentParser.Token.START_ARRAY) {
            condArray = parseCondArray(parseContext, parser, currentFieldName);
        } else if (token.isValue()) {
            if (currentFieldName != null) {
                switch (currentFieldName) {
                    case CondBoostEntry.BOOST:
                        defaultBoost = parser.floatValue();
                        break;
                    case "factor":
                        boostFactor = parser.floatValue();
                        break;
                    case "modifier":
                        modifier = CondBoostFactorFunction.Modifier.valueOf(parser.text().toUpperCase(Locale.ROOT));
                        break;
                    default:
                        throw new QueryParsingException(parseContext, NAMES[0] + " query does not support [" + currentFieldName + "]");
                }
            }
        }
    }
    return new CondBoostFactorFunction(parseContext, condArray, defaultBoost, boostFactor, modifier);
}
 
开发者ID:jprante,项目名称:elasticsearch-functionscore-conditionalboost,代码行数:34,代码来源:CondBoostFactorFunctionParser.java

示例11: doToFunction

import org.elasticsearch.common.lucene.search.function.ScoreFunction; //导入依赖的package包/类
@Override
protected ScoreFunction doToFunction(QueryShardContext context) throws IOException {
    //nothing to do here, weight will be applied by the parent class, no score function
    return null;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:6,代码来源:WeightBuilder.java

示例12: getFunctionScoreExplanation

import org.elasticsearch.common.lucene.search.function.ScoreFunction; //导入依赖的package包/类
public Explanation getFunctionScoreExplanation(IndexSearcher searcher, ScoreFunction scoreFunction) throws IOException {
    FunctionScoreQuery functionScoreQuery = new FunctionScoreQuery(new TermQuery(TERM), scoreFunction, 0.0f, CombineFunction.AVG, 100);
    Weight weight = searcher.createNormalizedWeight(functionScoreQuery, true);
    Explanation explanation = weight.explain(searcher.getIndexReader().leaves().get(0), 0);
    return explanation.getDetails()[1];
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:7,代码来源:FunctionScoreTests.java

示例13: getFiltersFunctionScoreExplanation

import org.elasticsearch.common.lucene.search.function.ScoreFunction; //导入依赖的package包/类
public Explanation getFiltersFunctionScoreExplanation(IndexSearcher searcher, ScoreFunction... scoreFunctions) throws IOException {
    FiltersFunctionScoreQuery filtersFunctionScoreQuery = getFiltersFunctionScoreQuery(FiltersFunctionScoreQuery.ScoreMode.AVG,
            CombineFunction.AVG, scoreFunctions);
    return getExplanation(searcher, filtersFunctionScoreQuery).getDetails()[1];
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:6,代码来源:FunctionScoreTests.java

示例14: doEquals

import org.elasticsearch.common.lucene.search.function.ScoreFunction; //导入依赖的package包/类
@Override
protected boolean doEquals(ScoreFunction other) {
    return false;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:5,代码来源:FunctionScoreTests.java

示例15: testFunctionScoreHashCodeAndEquals

import org.elasticsearch.common.lucene.search.function.ScoreFunction; //导入依赖的package包/类
public void testFunctionScoreHashCodeAndEquals() {
    Float minScore = randomBoolean() ? null : 1.0f;
    CombineFunction combineFunction = randomFrom(CombineFunction.values());
    float maxBoost = randomBoolean() ? Float.POSITIVE_INFINITY : randomFloat();
    ScoreFunction function = randomBoolean() ? null : new DummyScoreFunction(combineFunction);

    FunctionScoreQuery q = new FunctionScoreQuery(new TermQuery(new Term("foo", "bar")), function, minScore, combineFunction, maxBoost);
    FunctionScoreQuery q1 = new FunctionScoreQuery(new TermQuery(new Term("foo", "bar")), function, minScore, combineFunction,
            maxBoost);
    assertEquals(q, q);
    assertEquals(q.hashCode(), q.hashCode());
    assertEquals(q, q1);
    assertEquals(q.hashCode(), q1.hashCode());

    FunctionScoreQuery diffQuery = new FunctionScoreQuery(new TermQuery(new Term("foo", "baz")), function, minScore, combineFunction,
            maxBoost);
    FunctionScoreQuery diffMinScore = new FunctionScoreQuery(q.getSubQuery(), function, minScore == null ? 1.0f : null, combineFunction,
            maxBoost);
    ScoreFunction otherFunciton = function == null ? new DummyScoreFunction(combineFunction) : null;
    FunctionScoreQuery diffFunction = new FunctionScoreQuery(q.getSubQuery(), otherFunciton, minScore, combineFunction, maxBoost);
    FunctionScoreQuery diffMaxBoost = new FunctionScoreQuery(new TermQuery(new Term("foo", "bar")), function, minScore, combineFunction,
            maxBoost == 1.0f ? 0.9f : 1.0f);
    FunctionScoreQuery[] queries = new FunctionScoreQuery[] { diffFunction,
        diffMinScore,
        diffQuery,
        q,
        diffMaxBoost
    };
    final int numIters = randomIntBetween(20, 100);
    for (int i = 0; i < numIters; i++) {
        FunctionScoreQuery left = randomFrom(queries);
        FunctionScoreQuery right = randomFrom(queries);
        if (left == right) {
            assertEquals(left, right);
            assertEquals(left.hashCode(), right.hashCode());
        } else {
            assertNotEquals(left + " == " + right, left, right);
        }
    }

}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:42,代码来源:FunctionScoreTests.java


注:本文中的org.elasticsearch.common.lucene.search.function.ScoreFunction类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。