Search in sources :

Example 1 with FieldDefBindings

use of com.yelp.nrtsearch.server.luceneserver.field.FieldDefBindings 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");
}
Also used : VirtualFieldDef(com.yelp.nrtsearch.server.luceneserver.field.VirtualFieldDef) FieldDef(com.yelp.nrtsearch.server.luceneserver.field.FieldDef) HashMap(java.util.HashMap) FieldDefBindings(com.yelp.nrtsearch.server.luceneserver.field.FieldDefBindings) DoubleValuesSource(org.apache.lucene.search.DoubleValuesSource) VirtualFieldDef(com.yelp.nrtsearch.server.luceneserver.field.VirtualFieldDef) Test(org.junit.Test)

Example 2 with FieldDefBindings

use of com.yelp.nrtsearch.server.luceneserver.field.FieldDefBindings 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);
}
Also used : VirtualFieldDef(com.yelp.nrtsearch.server.luceneserver.field.VirtualFieldDef) FieldDef(com.yelp.nrtsearch.server.luceneserver.field.FieldDef) HashMap(java.util.HashMap) FieldDefBindings(com.yelp.nrtsearch.server.luceneserver.field.FieldDefBindings) DoubleValuesSource(org.apache.lucene.search.DoubleValuesSource) VirtualFieldDef(com.yelp.nrtsearch.server.luceneserver.field.VirtualFieldDef) Test(org.junit.Test)

Example 3 with FieldDefBindings

use of com.yelp.nrtsearch.server.luceneserver.field.FieldDefBindings in project nrtsearch by Yelp.

the class JsScriptBindingsTest method testParamBindingIsCached.

@Test
public void testParamBindingIsCached() {
    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");
    DoubleValuesSource p2Source = bindings.getDoubleValuesSource("param2");
    DoubleValuesSource p1SourceNext = bindings.getDoubleValuesSource("param1");
    DoubleValuesSource p2SourceNext = bindings.getDoubleValuesSource("param2");
    assertNotSame(p1Source, p2Source);
    assertSame(p1Source, p1SourceNext);
    assertSame(p2Source, p2SourceNext);
}
Also used : HashMap(java.util.HashMap) FieldDefBindings(com.yelp.nrtsearch.server.luceneserver.field.FieldDefBindings) DoubleValuesSource(org.apache.lucene.search.DoubleValuesSource) Test(org.junit.Test)

Example 4 with FieldDefBindings

use of com.yelp.nrtsearch.server.luceneserver.field.FieldDefBindings 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");
}
Also used : VirtualFieldDef(com.yelp.nrtsearch.server.luceneserver.field.VirtualFieldDef) FieldDef(com.yelp.nrtsearch.server.luceneserver.field.FieldDef) HashMap(java.util.HashMap) FieldDefBindings(com.yelp.nrtsearch.server.luceneserver.field.FieldDefBindings) DoubleValuesSource(org.apache.lucene.search.DoubleValuesSource) VirtualFieldDef(com.yelp.nrtsearch.server.luceneserver.field.VirtualFieldDef) Test(org.junit.Test)

Example 5 with FieldDefBindings

use of com.yelp.nrtsearch.server.luceneserver.field.FieldDefBindings 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']");
}
Also used : VirtualFieldDef(com.yelp.nrtsearch.server.luceneserver.field.VirtualFieldDef) FieldDef(com.yelp.nrtsearch.server.luceneserver.field.FieldDef) HashMap(java.util.HashMap) FieldDefBindings(com.yelp.nrtsearch.server.luceneserver.field.FieldDefBindings) DoubleValuesSource(org.apache.lucene.search.DoubleValuesSource) VirtualFieldDef(com.yelp.nrtsearch.server.luceneserver.field.VirtualFieldDef) Test(org.junit.Test)

Aggregations

FieldDefBindings (com.yelp.nrtsearch.server.luceneserver.field.FieldDefBindings)9 HashMap (java.util.HashMap)9 DoubleValuesSource (org.apache.lucene.search.DoubleValuesSource)9 Test (org.junit.Test)8 FieldDef (com.yelp.nrtsearch.server.luceneserver.field.FieldDef)7 VirtualFieldDef (com.yelp.nrtsearch.server.luceneserver.field.VirtualFieldDef)7 JsonObject (com.google.gson.JsonObject)1 IdFieldDef (com.yelp.nrtsearch.server.luceneserver.field.IdFieldDef)1 IndexableFieldDef (com.yelp.nrtsearch.server.luceneserver.field.IndexableFieldDef)1 ScoreScript (com.yelp.nrtsearch.server.luceneserver.script.ScoreScript)1