本文整理汇总了Java中org.elasticsearch.search.lookup.LeafSearchLookup类的典型用法代码示例。如果您正苦于以下问题:Java LeafSearchLookup类的具体用法?Java LeafSearchLookup怎么用?Java LeafSearchLookup使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
LeafSearchLookup类属于org.elasticsearch.search.lookup包,在下文中一共展示了LeafSearchLookup类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: ScriptImpl
import org.elasticsearch.search.lookup.LeafSearchLookup; //导入依赖的package包/类
/**
* Creates a ScriptImpl for the a previously compiled Painless script.
* @param script The previously compiled Painless script.
* @param vars The initial variables to run the script with.
* @param lookup The lookup to allow search fields to be available if this is run as a search script.
*/
ScriptImpl(final GenericElasticsearchScript script, final Map<String, Object> vars, final LeafSearchLookup lookup) {
this.script = script;
this.lookup = lookup;
this.variables = new HashMap<>();
if (vars != null) {
variables.putAll(vars);
}
if (lookup != null) {
variables.putAll(lookup.asMap());
doc = lookup.doc();
} else {
doc = null;
}
scoreLookup = script.uses$_score() ? ScriptImpl::getScore : scorer -> 0.0;
ctxLookup = script.uses$ctx() ? variables -> (Map<?, ?>) variables.get("ctx") : variables -> null;
}
示例2: initialize
import org.elasticsearch.search.lookup.LeafSearchLookup; //导入依赖的package包/类
public void initialize(Engine.Searcher docSearcher, ParsedDocument parsedDocument) {
this.docSearcher = docSearcher;
IndexReader indexReader = docSearcher.reader();
LeafReaderContext atomicReaderContext = indexReader.leaves().get(0);
LeafSearchLookup leafLookup = lookup().getLeafSearchLookup(atomicReaderContext);
leafLookup.setDocument(0);
leafLookup.source().setSource(parsedDocument.source());
Map<String, SearchHitField> fields = new HashMap<>();
for (IndexableField field : parsedDocument.rootDoc().getFields()) {
fields.put(field.name(), new InternalSearchHitField(field.name(), Collections.emptyList()));
}
hitContext().reset(
new InternalSearchHit(0, "unknown", new Text(parsedDocument.type()), fields),
atomicReaderContext, 0, docSearcher.searcher()
);
}
示例3: search
import org.elasticsearch.search.lookup.LeafSearchLookup; //导入依赖的package包/类
@SuppressWarnings({"unchecked"})
@Override
public SearchScript search(final CompiledScript compiledScript, final SearchLookup lookup, @Nullable final Map<String, Object> vars) {
return new SearchScript() {
@Override
public LeafSearchScript getLeafSearchScript(LeafReaderContext context) throws IOException {
final LeafSearchLookup leafLookup = lookup.getLeafSearchLookup(context);
boolean debug = true;
if (vars != null && vars.containsKey("debug")) {
debug = (Boolean)vars.get("debug");
}
return ((Factory) compiledScript.compiled()).newScript(leafLookup, debug);
}
@Override
public boolean needsScores() {
// TODO: can we reliably know if a vectorizer script does not make use of _score
return false;
}
};
}
示例4: PMMLModel
import org.elasticsearch.search.lookup.LeafSearchLookup; //导入依赖的package包/类
private PMMLModel(ModelInputEvaluator<Input> features, EsModelEvaluator<Input, Output> model,
LeafSearchLookup lookup, boolean debug) {
this.dataSource = new EsDataSource() {
@Override
protected LeafDocLookup getDocLookup() {
return lookup.doc();
}
@Override
protected LeafIndexLookup getLeafIndexLookup() {
return lookup.indexLookup();
}
};
this.lookup = lookup;
this.features = features;
this.model = model;
this.debug = debug;
}
示例5: getLeafSearchScript
import org.elasticsearch.search.lookup.LeafSearchLookup; //导入依赖的package包/类
@Override
public LeafSearchScript getLeafSearchScript(LeafReaderContext context) throws IOException {
LeafSearchLookup leafLookup = lookup.getLeafSearchLookup(context);
Map<String, Object> ctx = new HashMap<>();
ctx.putAll(leafLookup.asMap());
if (vars != null) {
ctx.putAll(vars);
}
AbstractSearchScript leafSearchScript = new AbstractSearchScript() {
@Override
public Object run() {
return script.apply(ctx);
}
@Override
public void setNextVar(String name, Object value) {
ctx.put(name, value);
}
@Override
public void setScorer(Scorer scorer) {
super.setScorer(scorer);
ctx.put("_score", new ScoreAccessor(scorer));
}
};
leafSearchScript.setLookup(leafLookup);
return leafSearchScript;
}
示例6: setLookup
import org.elasticsearch.search.lookup.LeafSearchLookup; //导入依赖的package包/类
void setLookup(LeafSearchLookup lookup) {
this.lookup = lookup;
}
示例7: search
import org.elasticsearch.search.lookup.LeafSearchLookup; //导入依赖的package包/类
@Override
public SearchScript search(CompiledScript compiledScript, SearchLookup lookup, Map<String, Object> vars) {
final long inc;
if (vars == null || vars.containsKey("inc") == false) {
inc = 0;
} else {
inc = ((Number) vars.get("inc")).longValue();
}
return new SearchScript() {
private Map<String, Object> vars = new HashMap<>(2);
@Override
public LeafSearchScript getLeafSearchScript(LeafReaderContext context) throws IOException {
final LeafSearchLookup leafLookup = lookup.getLeafSearchLookup(context);
return new LeafSearchScript() {
@Override
public void setNextVar(String name, Object value) {
vars.put(name, value);
}
@Override
public Object run() {
throw new UnsupportedOperationException();
}
@Override
public void setScorer(Scorer scorer) {
}
@Override
public void setSource(Map<String, Object> source) {
}
@Override
public void setDocument(int doc) {
if (leafLookup != null) {
leafLookup.setDocument(doc);
}
}
@Override
public long runAsLong() {
return ((Number) vars.get("_value")).longValue() + inc;
}
@Override
public double runAsDouble() {
return ((Number) vars.get("_value")).doubleValue() + inc;
}
};
}
@Override
public boolean needsScores() {
return false;
}
};
}
示例8: newScript
import org.elasticsearch.search.lookup.LeafSearchLookup; //导入依赖的package包/类
public PMMLModel<Input, Output> newScript(LeafSearchLookup lookup, boolean debug) {
return new PMMLModel<>(features, model, lookup, debug);
}