zoukankan      html  css  js  c++  java
  • es 插件

    类 若 实现NativeScriptFactory接口。A factory to create instances of either {@link ExecutableScript} or {@link SearchScript}

    只是一个工厂类,仍需要 创建 上面二者之一。实际中 需 创建 类 继承 SearchScript接口的实现类AbstractSearchScript 的 子类@ AbstractLongSearchScript @AbstractDoubleSearchScript。

    我们使用 它是因为public List<NativeScriptFactory> getNativeScripts() 需要返回的是工厂。 

    NativeScriptFactory

    /**
    * A factory to create instances of either {@link ExecutableScript} or {@link SearchScript}. Note,
    * if this factory creates {@link SearchScript}, it must extend {@link AbstractSearchScript}.
    *
    * @see AbstractExecutableScript
    * @see AbstractSearchScript
    * @see AbstractLongSearchScript
    * @see AbstractDoubleSearchScript
    */
    public interface NativeScriptFactory {

    ExecutableScript (一般不用,忽略)

    * An executable script, can't be used concurrently.

    SearchScript  接口

    AbstractSearchScript (核心类,提供了绝大部分功能的实现)

    /**
    * A base class for any script type that is used during the search process (custom score, aggs, and so on).
    * <p>
    * If the script returns a specific numeric type, consider overriding the type specific base classes
    * such as {@link AbstractDoubleSearchScript} and {@link AbstractLongSearchScript}
    * for better performance.
    * <p>
    * The use is required to implement the {@link #run()} method.
    */
    public abstract class AbstractSearchScript extends AbstractExecutableScript implements LeafSearchScript {

    它 的核心是 属性:

    private LeafSearchLookup lookup;
    private Scorer scorer;

    所有方法的实现同和这两个属性有关。

    setLookup()实现lookup的初始化

    通过SearchLookup调用lookup.getLeafSearchLookup(context)实现

    searchLookUp则通过DefaultSearchContext.lookup()实现初始化

      lookup():  getQueryShardContext().lookup();

    DefaultSearchContext则通过createContext实现初始化

    也就是通过QueryShardContext.lookup() 实现。

    QueryShardContext : lookup = new SearchLookup(getMapperService(), indexFieldDataService, types);

      其主要属性 及初始化: 

    public class SearchLookup {

    final DocLookup docMap;

    final SourceLookup sourceLookup;

    final FieldsLookup fieldsLookup;

    public SearchLookup(MapperService mapperService, IndexFieldDataService fieldDataService, @Nullable String[] types) {
    docMap = new DocLookup(mapperService, fieldDataService, types);
    sourceLookup = new SourceLookup();
    fieldsLookup = new FieldsLookup(mapperService, types);
    }

    public class FieldsLookup {

    private final MapperService mapperService;
    @Nullable
    private final String[] types;

    FieldsLookup(MapperService mapperService, @Nullable String[] types) {
    this.mapperService = mapperService;
    this.types = types;
    }

    然后追踪 传参的来源:

    queryShardContext.setTypes(ShardSearchRequest.types());

    LocalTransport.sendRequest()

      targetTransport.receiveMessage(version, data, action, requestId, this);

        processReceivedMessage(data, action, sourceTransport, version, requestId);

          StreamInput stream = StreamInput.wrap(data);

          handleRequest(stream, requestId, data.length, sourceTransport, version);

            request.readFrom(stream);

              TaskId.readFromStream(in);

                ShardSearchTransportRequest.readFrom()

                  shardSearchLocalRequest.innerReadFrom(in);

                      types = in.readStringArray();

    总结: 数据有了,直接用

     plsSearchScript 继承自AbstractSearchScript 类。

     覆写了run(),run方法会执行plsExScript接口的run().

    我们只需要提供一个实现plsExScirpt接口的类

  • 相关阅读:
    对函数的推广
    自然语言也支持泛型
    用委托实现对List的常用方法提取
    C#中的特性(Attributes)(翻译)(转)
    用JQUERY增删元素
    表格折叠展开
    下一代编程语言可能具有的特点
    一种多继承方案
    几年前毕业设计做的CAD二次开发
    数据结构 003.1.1 栈的基本概念
  • 原文地址:https://www.cnblogs.com/ydxblog/p/8074058.html
Copyright © 2011-2022 走看看