Add mapper-extras and the RankFeatureQuery in the hlrc (#43713)

This change adds the support for the RankFeatureQuery in the HLRC by
providing an extra dependency on mapper-extras-client. It also removes
the dependency on lang-painless in mapper-extras which is not needed
anymore since the move of the vector field into a dedicated module.

Closes #43634
This commit is contained in:
Jim Ferenczi 2019-08-14 09:52:49 +02:00 committed by jimczi
parent 8142ca82f1
commit 79a1390935
7 changed files with 106 additions and 9 deletions

View File

@ -53,6 +53,7 @@ dependencies {
*/
compile project(':server')
compile project(':client:rest')
compile project(':modules:mapper-extras')
compile project(':modules:parent-join')
compile project(':modules:aggs-matrix-stats')
compile project(':modules:rank-eval')

View File

@ -29,6 +29,7 @@ import org.elasticsearch.index.query.GeoShapeQueryBuilder;
import org.elasticsearch.index.query.functionscore.FunctionScoreQueryBuilder;
import org.elasticsearch.index.query.functionscore.FunctionScoreQueryBuilder.FilterFunctionBuilder;
import org.elasticsearch.join.query.JoinQueryBuilders;
import org.elasticsearch.index.query.RankFeatureQueryBuilders;
import org.elasticsearch.script.Script;
import org.elasticsearch.script.ScriptType;
import org.elasticsearch.test.ESTestCase;
@ -453,4 +454,28 @@ public class QueryDSLDocumentationTests extends ESTestCase {
wrapperQuery(query);
// end::wrapper
}
public void testRankFeatureSaturation() {
RankFeatureQueryBuilders.saturation(
"pagerank"); // <1>
}
public void testRankFeatureSaturationPivot() {
RankFeatureQueryBuilders.saturation(
"pagerank", // <1>
8); // <2>
}
public void testRankFeatureLog() {
RankFeatureQueryBuilders.log(
"pagerank", // <1>
4f); // <2>
}
public void testRankFeatureSigmoid() {
RankFeatureQueryBuilders.sigmoid(
"pagerank", // <1>
7, // <2>
0.6f); // <3>
}
}

View File

@ -40,6 +40,7 @@ ifeval::["{release-state}"=="unreleased"]
:rest-client-javadoc: https://snapshots.elastic.co/javadoc/org/elasticsearch/client/elasticsearch-rest-client/{version}-SNAPSHOT
:rest-client-sniffer-javadoc: https://snapshots.elastic.co/javadoc/org/elasticsearch/client/elasticsearch-rest-client-sniffer/{version}-SNAPSHOT
:rest-high-level-client-javadoc: https://snapshots.elastic.co/javadoc/org/elasticsearch/client/elasticsearch-rest-high-level-client/{version}-SNAPSHOT
:mapper-extras-javadoc: https://snapshots.elastic.co/javadoc/org/elasticsearch/plugin/mapper-extras/{version}-SNAPSHOT
:painless-javadoc: https://snapshots.elastic.co/javadoc/org/elasticsearch/painless/lang-painless/{version}-SNAPSHOT
:parent-join-client-javadoc: https://snapshots.elastic.co/javadoc/org/elasticsearch/plugin/parent-join-client/{version}-SNAPSHOT
:percolator-client-javadoc: https://snapshots.elastic.co/javadoc/org/elasticsearch/plugin/percolator-client/{version}-SNAPSHOT
@ -54,6 +55,7 @@ ifeval::["{release-state}"!="unreleased"]
:rest-client-javadoc: https://artifacts.elastic.co/javadoc/org/elasticsearch/client/elasticsearch-rest-client/{version}
:rest-client-sniffer-javadoc: https://artifacts.elastic.co/javadoc/org/elasticsearch/client/elasticsearch-rest-client-sniffer/{version}
:rest-high-level-client-javadoc: https://artifacts.elastic.co/javadoc/org/elasticsearch/client/elasticsearch-rest-high-level-client/{version}
:mapper-extras-javadoc: https://snapshots.elastic.co/javadoc/org/elasticsearch/plugin/mapper-extras/{version}
:painless-javadoc: https://artifacts.elastic.co/javadoc/org/elasticsearch/painless/lang-painless/{version}
:parent-join-client-javadoc: https://artifacts.elastic.co/javadoc/org/elasticsearch/plugin/parent-join-client/{version}
:percolator-client-javadoc: https://artifacts.elastic.co/javadoc/org/elasticsearch/plugin/percolator-client/{version}

View File

@ -4,9 +4,10 @@
This page lists all the available search queries with their corresponding `QueryBuilder` class name and helper method name in the
`QueryBuilders` utility class.
:query-ref: {elasticsearch-javadoc}/org/elasticsearch/index/query
:parentjoin-ref: {parent-join-client-javadoc}/org/elasticsearch/join/query
:percolate-ref: {percolator-client-javadoc}/org/elasticsearch/percolator
:query-ref: {elasticsearch-javadoc}/org/elasticsearch/index/query
:mapper-extras-ref: {mapper-extras-client-javadoc}/org/elasticsearch/index/query
:parentjoin-ref: {parent-join-client-javadoc}/org/elasticsearch/join/query
:percolate-ref: {percolator-client-javadoc}/org/elasticsearch/percolator
==== Match All Query
[options="header"]
@ -83,6 +84,7 @@ This page lists all the available search queries with their corresponding `Query
| {ref}/query-dsl-script-query.html[Script] | {query-ref}/ScriptQueryBuilder.html[ScriptQueryBuilder] | {query-ref}/QueryBuilders.html#scriptQuery-org.elasticsearch.script.Script-[QueryBuilders.scriptQuery()]
| {ref}/query-dsl-percolate-query.html[Percolate] | {percolate-ref}/PercolateQueryBuilder.html[PercolateQueryBuilder] |
| {ref}/query-dsl-wrapper-query.html[Wrapper] | {query-ref}/WrapperQueryBuilder.html[WrapperQueryBuilder] | {query-ref}/QueryBuilders.html#wrapperQuery-java.lang.String-[QueryBuilders.wrapperQuery()]
| {ref}/query-dsl-rank-feature-query.html[Rank Feature] | {mapper-extras-ref}/RankFeatureQuery.html[RankFeatureQueryBuilder] |
|======
==== Span queries

View File

@ -20,9 +20,4 @@
esplugin {
description 'Adds advanced field mappers'
classname 'org.elasticsearch.index.mapper.MapperExtrasPlugin'
extendedPlugins = ['lang-painless']
}
dependencies {
compileOnly project(':modules:lang-painless')
}

View File

@ -299,6 +299,11 @@ public final class RankFeatureQueryBuilder extends AbstractQueryBuilder<RankFeat
private final String field;
private final ScoreFunction scoreFunction;
/**
*
* @param field The field name.
* @param scoreFunction Scoring function for the rank_feature field.
*/
public RankFeatureQueryBuilder(String field, ScoreFunction scoreFunction) {
this.field = Objects.requireNonNull(field);
this.scoreFunction = Objects.requireNonNull(scoreFunction);

View File

@ -0,0 +1,67 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.index.query;
public final class RankFeatureQueryBuilders {
private RankFeatureQueryBuilders() {}
/**
* Return a new {@link RankFeatureQueryBuilder} that will score documents as
* {@code boost * S / (S + pivot)} where S is the value of the static feature.
* @param fieldName field that stores features
* @param pivot feature value that would give a score contribution equal to weight/2, must be in (0, +Infinity)
*/
public static RankFeatureQueryBuilder saturation(String fieldName, float pivot) {
return new RankFeatureQueryBuilder(fieldName, new RankFeatureQueryBuilder.ScoreFunction.Saturation(pivot));
}
/**
* Same as {@link #saturation(String, float)} but a reasonably good default pivot value
* is computed based on index statistics and is approximately equal to the geometric mean of all
* values that exist in the index.
* @param fieldName field that stores features
*/
public static RankFeatureQueryBuilder saturation(String fieldName) {
return new RankFeatureQueryBuilder(fieldName, new RankFeatureQueryBuilder.ScoreFunction.Saturation());
}
/**
* Return a new {@link RankFeatureQueryBuilder} that will score documents as
* {@code boost * Math.log(scalingFactor + S)} where S is the value of the static feature.
* @param fieldName field that stores features
* @param scalingFactor scaling factor applied before taking the logarithm, must be in [1, +Infinity)
*/
public static RankFeatureQueryBuilder log(String fieldName, float scalingFactor) {
return new RankFeatureQueryBuilder(fieldName, new RankFeatureQueryBuilder.ScoreFunction.Log(scalingFactor));
}
/**
* Return a new {@link RankFeatureQueryBuilder} that will score documents as
* {@code boost * S^a / (S^a + pivot^a)} where S is the value of the static feature.
* @param fieldName field that stores features
* @param pivot feature value that would give a score contribution equal to weight/2, must be in (0, +Infinity)
* @param exp exponent, higher values make the function grow slower before 'pivot' and faster after 'pivot',
* must be in (0, +Infinity)
*/
public static RankFeatureQueryBuilder sigmoid(String fieldName, float pivot, float exp) {
return new RankFeatureQueryBuilder(fieldName, new RankFeatureQueryBuilder.ScoreFunction.Sigmoid(pivot, exp));
}
}