use of com.yelp.nrtsearch.server.luceneserver.field.FieldDefBindings in project nrtsearch by Yelp.
the class JsScriptBindingsTest method testGetBindingForParam.
@Test
public void testGetBindingForParam() throws IOException {
Map<String, Object> params = new HashMap<>();
params.put("param1", 100);
params.put("param2", 1.11);
JsScriptBindings bindings = new JsScriptBindings(new FieldDefBindings(Collections.emptyMap()), params);
DoubleValuesSource p1Source = bindings.getDoubleValuesSource("param1");
assertEquals(100D, p1Source.getValues(null, null).doubleValue(), 0.001);
DoubleValuesSource p2Source = bindings.getDoubleValuesSource("param2");
assertEquals(1.11, p2Source.getValues(null, null).doubleValue(), 0.001);
}
use of com.yelp.nrtsearch.server.luceneserver.field.FieldDefBindings in project nrtsearch by Yelp.
the class JsScriptBindingsTest method testExtendedIntIndex.
@Test(expected = IllegalArgumentException.class)
public void testExtendedIntIndex() {
Map<String, Object> params = new HashMap<>();
params.put("param1", 100);
params.put("param2", 1.11);
DoubleValuesSource field1Source = new DummyValuesSource();
DoubleValuesSource field2Source = new DummyValuesSource();
Map<String, FieldDef> fieldDefMap = new HashMap<>();
fieldDefMap.put("field1", new VirtualFieldDef("field1", field1Source));
fieldDefMap.put("field2", new VirtualFieldDef("field2", field2Source));
JsScriptBindings bindings = new JsScriptBindings(new FieldDefBindings(fieldDefMap), params);
bindings.getDoubleValuesSource("doc[1].value");
}
use of com.yelp.nrtsearch.server.luceneserver.field.FieldDefBindings in project nrtsearch by Yelp.
the class JsScriptBindingsTest method testExtendedInvalidPrefix.
@Test(expected = IllegalArgumentException.class)
public void testExtendedInvalidPrefix() {
Map<String, Object> params = new HashMap<>();
params.put("param1", 100);
params.put("param2", 1.11);
DoubleValuesSource field1Source = new DummyValuesSource();
DoubleValuesSource field2Source = new DummyValuesSource();
Map<String, FieldDef> fieldDefMap = new HashMap<>();
fieldDefMap.put("field1", new VirtualFieldDef("field1", field1Source));
fieldDefMap.put("field2", new VirtualFieldDef("field2", field2Source));
JsScriptBindings bindings = new JsScriptBindings(new FieldDefBindings(fieldDefMap), params);
bindings.getDoubleValuesSource("not_doc['field1'].value");
}
use of com.yelp.nrtsearch.server.luceneserver.field.FieldDefBindings in project nrtsearch by Yelp.
the class RegisterFieldsHandler method parseOneVirtualFieldType.
private FieldDef parseOneVirtualFieldType(IndexState indexState, Map<String, FieldDef> pendingFieldDefs, String fieldName, Field currentField) throws RegisterFieldsException {
ScoreScript.Factory factory = ScriptService.getInstance().compile(currentField.getScript(), ScoreScript.CONTEXT);
Map<String, Object> params = ScriptParamsUtils.decodeParams(currentField.getScript().getParamsMap());
// doing this (or maybe updating index state in general).
if (currentField.getScript().getLang().equals(JsScriptEngine.LANG)) {
params = new HashMap<>(params);
Map<String, FieldDef> allFields = new HashMap<>(indexState.getAllFields());
allFields.putAll(pendingFieldDefs);
params.put("bindings", new FieldDefBindings(allFields));
}
DoubleValuesSource values = factory.newFactory(params, indexState.docLookup);
return new VirtualFieldDef(fieldName, values);
}
Aggregations