use of com.yelp.nrtsearch.server.luceneserver.field.VirtualFieldDef in project nrtsearch by Yelp.
the class SearchRequestProcessor method getVirtualFields.
/**
* Parses any virtualFields, which define dynamic (expression) fields for this one request.
*
* @throws IllegalArgumentException if there are multiple virtual fields with the same name
*/
private static Map<String, FieldDef> getVirtualFields(ShardState shardState, SearchRequest searchRequest) {
if (searchRequest.getVirtualFieldsList().isEmpty()) {
return new HashMap<>();
}
IndexState indexState = shardState.indexState;
Map<String, FieldDef> virtualFields = new HashMap<>();
for (VirtualField vf : searchRequest.getVirtualFieldsList()) {
if (virtualFields.containsKey(vf.getName())) {
throw new IllegalArgumentException("Multiple definitions of Virtual field: " + vf.getName());
}
ScoreScript.Factory factory = ScriptService.getInstance().compile(vf.getScript(), ScoreScript.CONTEXT);
Map<String, Object> params = ScriptParamsUtils.decodeParams(vf.getScript().getParamsMap());
FieldDef virtualField = new VirtualFieldDef(vf.getName(), factory.newFactory(params, indexState.docLookup));
virtualFields.put(vf.getName(), virtualField);
}
return virtualFields;
}
use of com.yelp.nrtsearch.server.luceneserver.field.VirtualFieldDef in project nrtsearch by Yelp.
the class JsScriptBindingsTest method testExtendedInvalidName.
@Test(expected = IllegalArgumentException.class)
public void testExtendedInvalidName() {
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['invalid'].value");
}
use of com.yelp.nrtsearch.server.luceneserver.field.VirtualFieldDef in project nrtsearch by Yelp.
the class JsScriptBindingsTest method testGetBindingForField.
@Test
public void testGetBindingForField() {
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);
DoubleValuesSource f1Source = bindings.getDoubleValuesSource("field1");
DoubleValuesSource f2Source = bindings.getDoubleValuesSource("field2");
assertNotSame(f1Source, f2Source);
assertSame(f1Source, field1Source);
assertSame(f2Source, field2Source);
}
use of com.yelp.nrtsearch.server.luceneserver.field.VirtualFieldDef in project nrtsearch by Yelp.
the class JsScriptBindingsTest method testInvalidName.
@Test(expected = IllegalArgumentException.class)
public void testInvalidName() {
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("invalid");
}
use of com.yelp.nrtsearch.server.luceneserver.field.VirtualFieldDef in project nrtsearch by Yelp.
the class JsScriptBindingsTest method testExtendedMissingProperty.
@Test(expected = IllegalArgumentException.class)
public void testExtendedMissingProperty() {
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['field1']");
}
Aggregations