自定义插件不能通过 QuerySpec 构造函数进行推断



我尝试将我的自定义插件从 ES5.5 升级到 ES6.3。 在ES5.5中,我自己的插件运行良好。但是在 ES6.3 中,QuerySpec 构造函数无法推断它。 以下是 ES6.3 中的代码片段:

  1. 抽象向量查询
public abstract class AbstractVectorQuery extends Query
{
protected String field;
protected float[] qVector;
protected VectorFieldType vectorFieldType;
protected DistanceMeasure distHelper;
protected AbstractVectorQuery(String field, float[] qVector, DistanceMeasure distHelper, VectorFieldType fieldType)
{
this.field = field;
this.qVector = qVector;
this.distHelper = distHelper;
this.vectorFieldType = fieldType;
}
}
  1. VectorIterQuery
public class VectorIterQuery extends AbstractVectorQuery
{
public VectorIterQuery(String field, float[] vector, DistanceMeasure distHelper, VectorFieldType vectorFieldType)
{
super(field, vector, distHelper, vectorFieldType);
}
}
  1. DistanceVectorQueryBuilder
public abstract class DistanceVectorQueryBuilder<T extends DistanceVectorQueryBuilder<T>>
extends AbstractVectorQueryBuilder<T>
{
public static final DistanceType DEFAULT_DISTANCE_TYPE = DistanceType.L2;
protected DistanceType distanceType = DEFAULT_DISTANCE_TYPE;
protected abstract void innerInnerDoXContent(XContentBuilder builder, Params params) throws IOException;
protected DistanceVectorQueryBuilder(){}
protected DistanceVectorQueryBuilder(StreamInput in) throws IOException
{
super(in);
this.distanceType = in.readEnum(DistanceType.class);
}
}
  1. IterVectorQueryBuilder
public class IterVectorQueryBuilder extends DistanceVectorQueryBuilder<IterVectorQueryBuilder>
{
public static final String QUERY_NAME = "iter";
public IterVectorQueryBuilder(StreamInput input) throws IOException
{
super(input);
}
}
  1. 矢量插件
    在这里,IDE 报告:
    无法推断参数(无法解析构造函数(
public class VectorPlugin extends Plugin implements MapperPlugin, SearchPlugin
{
@Override
public List<QuerySpec<?>> getQueries()
{
List<QuerySpec<?>> list = new ArrayList<>();
QuerySpec<IterVectorQueryBuilder> iterQuery = new QuerySpec<>(
IterVectorQueryBuilder.QUERY_NAME,
IterVectorQueryBuilder::new,
IterVectorQueryBuilder::fromXContent
);
list.add(iterQuery);
}
}

任何建议都会非常感激。

解决了,实际上问题在我发布的代码片段中不存在,很抱歉造成误解。

更改 IterVectorQueryBuilder 的返回类型::fromXContent 从

Optional<IterVectorQueryBuilder> fromXContent(QueryParseContext parseContext) throws IOException { ... }

IterVectorQueryBuilder fromXContent(QueryParseContext parseContext) throws IOException { ... }  

会解决这个问题。

相关内容

  • 没有找到相关文章

最新更新