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接口的类

 

转载于:https://www.cnblogs.com/ydxblog/p/8074058.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值