diff --git a/src/main/java/com/yelp/nrtsearch/server/luceneserver/IndexState.java b/src/main/java/com/yelp/nrtsearch/server/luceneserver/IndexState.java index d22b57bbe..923b3f76a 100644 --- a/src/main/java/com/yelp/nrtsearch/server/luceneserver/IndexState.java +++ b/src/main/java/com/yelp/nrtsearch/server/luceneserver/IndexState.java @@ -44,7 +44,6 @@ import java.util.regex.Pattern; import org.apache.lucene.analysis.Analyzer; import org.apache.lucene.analysis.AnalyzerWrapper; -import org.apache.lucene.expressions.Bindings; import org.apache.lucene.facet.FacetsConfig; import org.apache.lucene.index.IndexWriterConfig; import org.apache.lucene.search.similarities.PerFieldSimilarityWrapper; @@ -95,7 +94,7 @@ public abstract class IndexState implements Closeable { * Index level doc values lookup. Generates {@link * com.yelp.nrtsearch.server.luceneserver.doc.SegmentDocLookup} for a given lucene segment. */ - public final DocLookup docLookup = new DocLookup(this, this::getField); + public final DocLookup docLookup = new DocLookup(this::getField); /** Search-time analyzer. */ public final Analyzer searchAnalyzer = @@ -362,9 +361,6 @@ public abstract void start( /** Get fields with doc values that do eager global ordinal building. */ public abstract Map getEagerFieldGlobalOrdinalFields(); - /** Get field bindings to use for javascript expressions. */ - public abstract Bindings getExpressionBindings(); - /** Verifies if it has nested child object fields. */ public abstract boolean hasNestedChildFields(); diff --git a/src/main/java/com/yelp/nrtsearch/server/luceneserver/doc/DocLookup.java b/src/main/java/com/yelp/nrtsearch/server/luceneserver/doc/DocLookup.java index e2a4aa040..bc754e29a 100644 --- a/src/main/java/com/yelp/nrtsearch/server/luceneserver/doc/DocLookup.java +++ b/src/main/java/com/yelp/nrtsearch/server/luceneserver/doc/DocLookup.java @@ -15,7 +15,6 @@ */ package com.yelp.nrtsearch.server.luceneserver.doc; -import com.yelp.nrtsearch.server.luceneserver.IndexState; import com.yelp.nrtsearch.server.luceneserver.field.FieldDef; import java.util.function.Function; import org.apache.lucene.index.LeafReaderContext; @@ -25,11 +24,9 @@ * SegmentDocLookup} bound to single lucene segment. */ public class DocLookup { - private final IndexState indexState; private final Function fieldDefLookup; - public DocLookup(IndexState indexState, Function fieldDefLookup) { - this.indexState = indexState; + public DocLookup(Function fieldDefLookup) { this.fieldDefLookup = fieldDefLookup; } @@ -43,15 +40,6 @@ public SegmentDocLookup getSegmentLookup(LeafReaderContext context) { return new SegmentDocLookup(fieldDefLookup, context); } - /** - * Get the state information associated with this index. - * - * @return index state - */ - public IndexState getIndexState() { - return indexState; - } - /** * Get the field definition for the given field name. * diff --git a/src/main/java/com/yelp/nrtsearch/server/luceneserver/field/FieldDefBindings.java b/src/main/java/com/yelp/nrtsearch/server/luceneserver/field/FieldDefBindings.java index d4604804a..4a5dc37d7 100644 --- a/src/main/java/com/yelp/nrtsearch/server/luceneserver/field/FieldDefBindings.java +++ b/src/main/java/com/yelp/nrtsearch/server/luceneserver/field/FieldDefBindings.java @@ -16,7 +16,7 @@ package com.yelp.nrtsearch.server.luceneserver.field; import com.yelp.nrtsearch.server.luceneserver.field.properties.Bindable; -import java.util.Map; +import java.util.function.Function; import org.apache.lucene.expressions.Bindings; import org.apache.lucene.expressions.js.VariableContext; import org.apache.lucene.expressions.js.VariableContext.Type; @@ -25,11 +25,11 @@ /** Implements {@link Bindings} on top of the registered fields. */ public final class FieldDefBindings extends Bindings { - private final Map fields; + private final Function fieldDefLookup; /** Sole constructor. */ - public FieldDefBindings(Map fields) { - this.fields = fields; + public FieldDefBindings(Function fieldDefLookup) { + this.fieldDefLookup = fieldDefLookup; } /** @@ -55,7 +55,7 @@ public DoubleValuesSource getDoubleValuesSource(String name) { if (name.equals("_score")) { return DoubleValuesSource.SCORES; } - FieldDef fd = fields.get(name); + FieldDef fd = fieldDefLookup.apply(name); String property = Bindable.VALUE_PROPERTY; String fieldName = name; if (fd == null) { @@ -72,7 +72,7 @@ public DoubleValuesSource getDoubleValuesSource(String name) { "Invalid field binding format: " + name + ", expected: doc['field_name'].property"); } fieldName = parsed[1].text; - fd = fields.get(fieldName); + fd = fieldDefLookup.apply(fieldName); if (fd == null) { throw new IllegalArgumentException("Unknown field to bind: " + fieldName); } diff --git a/src/main/java/com/yelp/nrtsearch/server/luceneserver/index/FieldAndFacetState.java b/src/main/java/com/yelp/nrtsearch/server/luceneserver/index/FieldAndFacetState.java index 561ee6810..93e71569b 100644 --- a/src/main/java/com/yelp/nrtsearch/server/luceneserver/index/FieldAndFacetState.java +++ b/src/main/java/com/yelp/nrtsearch/server/luceneserver/index/FieldAndFacetState.java @@ -17,7 +17,6 @@ import com.yelp.nrtsearch.server.grpc.Field; import com.yelp.nrtsearch.server.luceneserver.field.FieldDef; -import com.yelp.nrtsearch.server.luceneserver.field.FieldDefBindings; import com.yelp.nrtsearch.server.luceneserver.field.IdFieldDef; import com.yelp.nrtsearch.server.luceneserver.field.IndexableFieldDef; import com.yelp.nrtsearch.server.luceneserver.field.ObjectFieldDef; @@ -31,7 +30,6 @@ import java.util.Map; import java.util.Optional; import java.util.Set; -import org.apache.lucene.expressions.Bindings; import org.apache.lucene.facet.FacetsConfig; import org.apache.lucene.facet.FacetsConfig.DimConfig; @@ -48,7 +46,6 @@ public class FieldAndFacetState { private final List indexedAnalyzedFields; private final Map eagerGlobalOrdinalFields; private final Map eagerFieldGlobalOrdinalFields; - private final Bindings exprBindings; // facet private final FacetsConfig facetsConfig; @@ -62,7 +59,6 @@ public FieldAndFacetState() { indexedAnalyzedFields = Collections.emptyList(); eagerGlobalOrdinalFields = Collections.emptyMap(); eagerFieldGlobalOrdinalFields = Collections.emptyMap(); - exprBindings = new FieldDefBindings(fields); facetsConfig = new FacetsConfig(); internalFacetFieldNames = Collections.emptySet(); @@ -81,7 +77,6 @@ public FieldAndFacetState() { eagerGlobalOrdinalFields = Collections.unmodifiableMap(builder.eagerGlobalOrdinalFields); eagerFieldGlobalOrdinalFields = Collections.unmodifiableMap(builder.eagerFieldGlobalOrdinalFields); - exprBindings = builder.exprBindings; facetsConfig = builder.facetsConfig; internalFacetFieldNames = Collections.unmodifiableSet(builder.internalFacetFieldNames); @@ -117,11 +112,6 @@ public Map getFieldEagerGlobalOrdinalFields() { return eagerFieldGlobalOrdinalFields; } - /** Get field expression {@link Bindings} used for js scripting language. */ - public Bindings getExprBindings() { - return exprBindings; - } - /** Get facet config. */ public FacetsConfig getFacetsConfig() { return facetsConfig; @@ -145,7 +135,6 @@ public static class Builder { private final List indexedAnalyzedFields; private final Map eagerGlobalOrdinalFields; private final Map eagerFieldGlobalOrdinalFields; - private final Bindings exprBindings; // facet private final FacetsConfig facetsConfig; @@ -158,7 +147,6 @@ private Builder(FieldAndFacetState initial) { this.indexedAnalyzedFields = new ArrayList<>(initial.indexedAnalyzedFields); this.eagerGlobalOrdinalFields = new HashMap<>(initial.eagerGlobalOrdinalFields); this.eagerFieldGlobalOrdinalFields = new HashMap<>(initial.eagerFieldGlobalOrdinalFields); - this.exprBindings = new FieldDefBindings(this.fields); this.facetsConfig = new FacetsConfig(); this.internalFacetFieldNames = new HashSet<>(); @@ -174,8 +162,13 @@ private Builder(FieldAndFacetState initial) { } } - public Bindings getBindings() { - return exprBindings; + /** + * Get fields currently registered with the builder. + * + * @return map of registered fields + */ + public Map getFields() { + return fields; } /** diff --git a/src/main/java/com/yelp/nrtsearch/server/luceneserver/index/ImmutableIndexState.java b/src/main/java/com/yelp/nrtsearch/server/luceneserver/index/ImmutableIndexState.java index ba834e16f..3041c5d8c 100644 --- a/src/main/java/com/yelp/nrtsearch/server/luceneserver/index/ImmutableIndexState.java +++ b/src/main/java/com/yelp/nrtsearch/server/luceneserver/index/ImmutableIndexState.java @@ -54,7 +54,6 @@ import java.util.Optional; import java.util.Set; import java.util.stream.Collectors; -import org.apache.lucene.expressions.Bindings; import org.apache.lucene.facet.FacetsConfig; import org.apache.lucene.index.ConcurrentMergeScheduler; import org.apache.lucene.index.IndexWriterConfig; @@ -469,11 +468,6 @@ public Map getEagerFieldGlobalOrdinalFields() { return fieldAndFacetState.getFieldEagerGlobalOrdinalFields(); } - @Override - public Bindings getExpressionBindings() { - return fieldAndFacetState.getExprBindings(); - } - @Override public boolean hasNestedChildFields() { return fieldAndFacetState.getHasNestedChildFields(); diff --git a/src/main/java/com/yelp/nrtsearch/server/luceneserver/index/handlers/FieldUpdateHandler.java b/src/main/java/com/yelp/nrtsearch/server/luceneserver/index/handlers/FieldUpdateHandler.java index 0cb314575..c78720d71 100644 --- a/src/main/java/com/yelp/nrtsearch/server/luceneserver/index/handlers/FieldUpdateHandler.java +++ b/src/main/java/com/yelp/nrtsearch/server/luceneserver/index/handlers/FieldUpdateHandler.java @@ -20,6 +20,7 @@ import com.yelp.nrtsearch.server.grpc.FieldDefResponse; import com.yelp.nrtsearch.server.grpc.FieldType; import com.yelp.nrtsearch.server.luceneserver.IndexState; +import com.yelp.nrtsearch.server.luceneserver.doc.DocLookup; import com.yelp.nrtsearch.server.luceneserver.field.FieldDef; import com.yelp.nrtsearch.server.luceneserver.field.FieldDefCreator; import com.yelp.nrtsearch.server.luceneserver.field.IndexableFieldDef; @@ -28,7 +29,6 @@ import com.yelp.nrtsearch.server.luceneserver.index.IndexStateManager; import com.yelp.nrtsearch.server.luceneserver.script.ScoreScript; import com.yelp.nrtsearch.server.luceneserver.script.ScriptService; -import com.yelp.nrtsearch.server.luceneserver.script.js.JsScriptEngine; import com.yelp.nrtsearch.server.utils.ScriptParamsUtils; import java.io.IOException; import java.util.ArrayList; @@ -179,21 +179,8 @@ public static void parseVirtualField(Field field, FieldAndFacetState.Builder fie ScoreScript.Factory factory = ScriptService.getInstance().compile(field.getScript(), ScoreScript.CONTEXT); Map params = ScriptParamsUtils.decodeParams(field.getScript().getParamsMap()); - // Workaround for the fact that the javascript expression may need bindings to other fields in - // this request. - // Build the complete bindings and pass it as a script parameter. We might want to think about a - // better way of - // doing this (or maybe updating index state in general). - if (field.getScript().getLang().equals(JsScriptEngine.LANG)) { - params = new HashMap<>(params); - params.put("bindings", fieldStateBuilder.getBindings()); - } else { - // TODO fix this, by removing DocLookup dependency on IndexState. Should be possible to just - // use the fields from the field state builder - throw new IllegalArgumentException("Only js lang supported for index virtual fields"); - } - // js scripts use Bindings instead of DocLookup - DoubleValuesSource values = factory.newFactory(params, null); + DoubleValuesSource values = + factory.newFactory(params, new DocLookup(fieldStateBuilder.getFields()::get)); FieldDef virtualFieldDef = new VirtualFieldDef(field.getName(), values); fieldStateBuilder.addField(virtualFieldDef, field); diff --git a/src/main/java/com/yelp/nrtsearch/server/luceneserver/script/js/JsScriptEngine.java b/src/main/java/com/yelp/nrtsearch/server/luceneserver/script/js/JsScriptEngine.java index 64dbcac57..72f173256 100644 --- a/src/main/java/com/yelp/nrtsearch/server/luceneserver/script/js/JsScriptEngine.java +++ b/src/main/java/com/yelp/nrtsearch/server/luceneserver/script/js/JsScriptEngine.java @@ -15,12 +15,11 @@ */ package com.yelp.nrtsearch.server.luceneserver.script.js; +import com.yelp.nrtsearch.server.luceneserver.field.FieldDefBindings; import com.yelp.nrtsearch.server.luceneserver.script.ScoreScript; import com.yelp.nrtsearch.server.luceneserver.script.ScriptContext; import com.yelp.nrtsearch.server.luceneserver.script.ScriptEngine; import java.text.ParseException; -import java.util.HashMap; -import java.util.Map; import org.apache.lucene.expressions.Bindings; import org.apache.lucene.expressions.Expression; import org.apache.lucene.expressions.js.JavascriptCompiler; @@ -71,22 +70,8 @@ public T compile(String source, ScriptContext context) { } ScoreScript.Factory factory = ((params, docLookup) -> { - Map scriptParams; - Bindings fieldBindings; - Object bindingsParam = params.get("bindings"); - if (bindingsParam instanceof Bindings) { - fieldBindings = (Bindings) bindingsParam; - - // we do not want the bindings to be used as an expression parameter, so remove it. - // the extra copy may not be absolutely needed, but this only happens when a new - // virtual field is added to the index, and this keeps the code thread safe. - scriptParams = new HashMap<>(params); - scriptParams.remove("bindings"); - } else { - fieldBindings = docLookup.getIndexState().getExpressionBindings(); - scriptParams = params; - } - return expr.getDoubleValuesSource(new JsScriptBindings(fieldBindings, scriptParams)); + Bindings fieldBindings = new FieldDefBindings(docLookup::getFieldDef); + return expr.getDoubleValuesSource(new JsScriptBindings(fieldBindings, params)); }); return context.factoryClazz.cast(factory); } diff --git a/src/main/java/com/yelp/nrtsearch/server/luceneserver/search/SearchRequestProcessor.java b/src/main/java/com/yelp/nrtsearch/server/luceneserver/search/SearchRequestProcessor.java index 3a89f987c..80d41f9b3 100644 --- a/src/main/java/com/yelp/nrtsearch/server/luceneserver/search/SearchRequestProcessor.java +++ b/src/main/java/com/yelp/nrtsearch/server/luceneserver/search/SearchRequestProcessor.java @@ -68,7 +68,6 @@ import java.util.Map; import java.util.Map.Entry; import java.util.concurrent.ConcurrentHashMap; -import java.util.function.Function; import java.util.stream.Collectors; import org.apache.lucene.facet.DrillDownQuery; import org.apache.lucene.facet.taxonomy.SearcherTaxonomyManager; @@ -143,8 +142,7 @@ public static SearchContext buildContextForRequest( getRetrieveFields(searchRequest.getRetrieveFieldsList(), queryFields); contextBuilder.setRetrieveFields(Collections.unmodifiableMap(retrieveFields)); - Function fieldDefLookup = (String s) -> queryFields.get(s); - DocLookup docLookup = new DocLookup(indexState, fieldDefLookup); + DocLookup docLookup = new DocLookup(queryFields::get); contextBuilder.setDocLookup(docLookup); String rootQueryNestedPath = @@ -418,8 +416,8 @@ private static Map getRetrieveFields( /** * Add index fields to given query fields map. * - * @param indexState state for query index * @param queryFields mutable current map of query fields + * @param otherFields fields to add to query fields * @throws IllegalArgumentException if any index field already exists */ private static void addToQueryFields( diff --git a/src/test/java/com/yelp/nrtsearch/server/luceneserver/index/ImmutableIndexStateTest.java b/src/test/java/com/yelp/nrtsearch/server/luceneserver/index/ImmutableIndexStateTest.java index a63eeb1a2..6fea1c89b 100644 --- a/src/test/java/com/yelp/nrtsearch/server/luceneserver/index/ImmutableIndexStateTest.java +++ b/src/test/java/com/yelp/nrtsearch/server/luceneserver/index/ImmutableIndexStateTest.java @@ -72,7 +72,6 @@ import java.util.Set; import java.util.function.Consumer; import java.util.function.Function; -import org.apache.lucene.expressions.Bindings; import org.apache.lucene.facet.FacetsConfig; import org.apache.lucene.index.ConcurrentMergeScheduler; import org.apache.lucene.index.IndexWriterConfig; @@ -1030,17 +1029,6 @@ public void testGetEagerGlobalOrdinalFields() throws IOException { verifyNoMoreInteractions(mockFieldState); } - @Test - public void testGetExpressionBindings() throws IOException { - FieldAndFacetState mockFieldState = mock(FieldAndFacetState.class); - Bindings mockBindings = mock(Bindings.class); - when(mockFieldState.getExprBindings()).thenReturn(mockBindings); - ImmutableIndexState indexState = getIndexState(getEmptyState(), mockFieldState); - assertSame(mockBindings, indexState.getExpressionBindings()); - verify(mockFieldState, times(1)).getExprBindings(); - verifyNoMoreInteractions(mockFieldState); - } - @Test public void testHasNestedChildFields() throws IOException { FieldAndFacetState mockFieldState = mock(FieldAndFacetState.class); diff --git a/src/test/java/com/yelp/nrtsearch/server/luceneserver/index/handlers/FieldUpdateHandlerTest.java b/src/test/java/com/yelp/nrtsearch/server/luceneserver/index/handlers/FieldUpdateHandlerTest.java index 0ebb6cf04..aa4fdfe24 100644 --- a/src/test/java/com/yelp/nrtsearch/server/luceneserver/index/handlers/FieldUpdateHandlerTest.java +++ b/src/test/java/com/yelp/nrtsearch/server/luceneserver/index/handlers/FieldUpdateHandlerTest.java @@ -17,7 +17,6 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; @@ -116,7 +115,6 @@ private UpdatedFieldInfo initializeAndCheckSimple() { assertTrue(fieldAndFacetState.getIdFieldDef().isEmpty()); assertTrue(fieldAndFacetState.getIndexedAnalyzedFields().isEmpty()); assertTrue(fieldAndFacetState.getEagerGlobalOrdinalFields().isEmpty()); - assertNotNull(fieldAndFacetState.getExprBindings()); assertTrue(fieldAndFacetState.getFacetsConfig().getDimConfigs().isEmpty()); assertTrue(fieldAndFacetState.getInternalFacetFieldNames().isEmpty()); return updatedFieldInfo; @@ -168,7 +166,6 @@ public void testRegisterAdditionalFields() { assertTrue(fieldAndFacetState.getIdFieldDef().isEmpty()); assertTrue(fieldAndFacetState.getIndexedAnalyzedFields().isEmpty()); assertTrue(fieldAndFacetState.getEagerGlobalOrdinalFields().isEmpty()); - assertNotNull(fieldAndFacetState.getExprBindings()); assertTrue(fieldAndFacetState.getFacetsConfig().getDimConfigs().isEmpty()); assertTrue(fieldAndFacetState.getInternalFacetFieldNames().isEmpty()); } @@ -215,7 +212,6 @@ public void testRegisterIdField() { fieldAndFacetState.getFields().get("field4"), fieldAndFacetState.getIdFieldDef().get()); assertTrue(fieldAndFacetState.getIndexedAnalyzedFields().isEmpty()); assertTrue(fieldAndFacetState.getEagerGlobalOrdinalFields().isEmpty()); - assertNotNull(fieldAndFacetState.getExprBindings()); assertTrue(fieldAndFacetState.getFacetsConfig().getDimConfigs().isEmpty()); assertTrue(fieldAndFacetState.getInternalFacetFieldNames().isEmpty()); } @@ -303,7 +299,6 @@ public void testRegisterAnalyzedFields() { assertEquals( Set.of("field3", "field4"), Sets.newHashSet(fieldAndFacetState.getIndexedAnalyzedFields())); assertTrue(fieldAndFacetState.getEagerGlobalOrdinalFields().isEmpty()); - assertNotNull(fieldAndFacetState.getExprBindings()); assertTrue(fieldAndFacetState.getFacetsConfig().getDimConfigs().isEmpty()); assertTrue(fieldAndFacetState.getInternalFacetFieldNames().isEmpty()); } @@ -339,7 +334,6 @@ public void testRegisterVirtualField() { assertTrue(fieldAndFacetState.getIdFieldDef().isEmpty()); assertTrue(fieldAndFacetState.getIndexedAnalyzedFields().isEmpty()); assertTrue(fieldAndFacetState.getEagerGlobalOrdinalFields().isEmpty()); - assertNotNull(fieldAndFacetState.getExprBindings()); assertTrue(fieldAndFacetState.getFacetsConfig().getDimConfigs().isEmpty()); assertTrue(fieldAndFacetState.getInternalFacetFieldNames().isEmpty()); } @@ -385,7 +379,6 @@ public void testRegisterVirtualFieldRefRequest() { assertTrue(fieldAndFacetState.getIdFieldDef().isEmpty()); assertTrue(fieldAndFacetState.getIndexedAnalyzedFields().isEmpty()); assertTrue(fieldAndFacetState.getEagerGlobalOrdinalFields().isEmpty()); - assertNotNull(fieldAndFacetState.getExprBindings()); assertTrue(fieldAndFacetState.getFacetsConfig().getDimConfigs().isEmpty()); assertTrue(fieldAndFacetState.getInternalFacetFieldNames().isEmpty()); } @@ -455,7 +448,6 @@ public void testRegisterFieldWithChildren() { Set.of("field3.child1", "field3.child3.grandchild1"), Sets.newHashSet(fieldAndFacetState.getIndexedAnalyzedFields())); assertTrue(fieldAndFacetState.getEagerGlobalOrdinalFields().isEmpty()); - assertNotNull(fieldAndFacetState.getExprBindings()); assertTrue(fieldAndFacetState.getFacetsConfig().getDimConfigs().isEmpty()); assertTrue(fieldAndFacetState.getInternalFacetFieldNames().isEmpty()); } @@ -526,7 +518,6 @@ public void testRegisterFieldWithNestedChildren() { Set.of("field3.child1", "field3.child3.grandchild1"), Sets.newHashSet(fieldAndFacetState.getIndexedAnalyzedFields())); assertTrue(fieldAndFacetState.getEagerGlobalOrdinalFields().isEmpty()); - assertNotNull(fieldAndFacetState.getExprBindings()); assertTrue(fieldAndFacetState.getFacetsConfig().getDimConfigs().isEmpty()); assertTrue(fieldAndFacetState.getInternalFacetFieldNames().isEmpty()); } @@ -578,7 +569,6 @@ public void testRegisterFieldsWithFacets() { assertEquals(List.of("field3"), fieldAndFacetState.getIndexedAnalyzedFields()); assertEquals(1, fieldAndFacetState.getEagerGlobalOrdinalFields().size()); assertTrue(fieldAndFacetState.getEagerGlobalOrdinalFields().containsKey("field3")); - assertNotNull(fieldAndFacetState.getExprBindings()); assertEquals(1, fieldAndFacetState.getFacetsConfig().getDimConfigs().size()); DimConfig dimConfig = fieldAndFacetState.getFacetsConfig().getDimConfig("field3"); assertTrue(dimConfig.multiValued); @@ -619,7 +609,6 @@ public void testRegisterFieldsWithFacets() { assertEquals(Set.of("field3"), Sets.newHashSet(fieldAndFacetState.getIndexedAnalyzedFields())); assertEquals(1, fieldAndFacetState.getEagerGlobalOrdinalFields().size()); assertTrue(fieldAndFacetState.getEagerGlobalOrdinalFields().containsKey("field3")); - assertNotNull(fieldAndFacetState.getExprBindings()); assertEquals(2, fieldAndFacetState.getFacetsConfig().getDimConfigs().size()); dimConfig = fieldAndFacetState.getFacetsConfig().getDimConfig("field3"); assertTrue(dimConfig.multiValued); diff --git a/src/test/java/com/yelp/nrtsearch/server/luceneserver/script/ScoreScriptTest.java b/src/test/java/com/yelp/nrtsearch/server/luceneserver/script/ScoreScriptTest.java index 0a5c3c034..694684754 100644 --- a/src/test/java/com/yelp/nrtsearch/server/luceneserver/script/ScoreScriptTest.java +++ b/src/test/java/com/yelp/nrtsearch/server/luceneserver/script/ScoreScriptTest.java @@ -60,7 +60,6 @@ import org.junit.After; import org.junit.Assert; import org.junit.Before; -import org.junit.Ignore; import org.junit.Rule; import org.junit.Test; import org.junit.rules.TemporaryFolder; @@ -713,7 +712,6 @@ public void testScriptDocValues() throws Exception { testQueryFieldScript("verify_doc_values", "registerFieldsBasic.json", "addDocs.csv", 1.5); } - @Ignore("Only js scripting language is supported in index fields now, enable after fix") @Test public void testScriptDocValuesIndexField() throws Exception { GrpcServer.TestServer testAddDocs = @@ -841,7 +839,6 @@ public void testScriptUsingScore() throws Exception { Math.ulp(2.0)); } - @Ignore("Only js scripting language is supported in index fields now, enable after fix") @Test public void testScriptUsingScoreInIndexField() throws Exception { GrpcServer.TestServer testAddDocs = diff --git a/src/test/java/com/yelp/nrtsearch/server/luceneserver/script/js/JsScriptBindingsTest.java b/src/test/java/com/yelp/nrtsearch/server/luceneserver/script/js/JsScriptBindingsTest.java index 393038ad9..ee284fd02 100644 --- a/src/test/java/com/yelp/nrtsearch/server/luceneserver/script/js/JsScriptBindingsTest.java +++ b/src/test/java/com/yelp/nrtsearch/server/luceneserver/script/js/JsScriptBindingsTest.java @@ -79,7 +79,7 @@ public void testNullFieldBindings() { @Test(expected = NullPointerException.class) public void testNullParams() { - new JsScriptBindings(new FieldDefBindings(Collections.emptyMap()), null); + new JsScriptBindings(new FieldDefBindings(name -> null), null); } @Test @@ -88,8 +88,7 @@ public void testGetBindingForParam() throws IOException { params.put("param1", 100); params.put("param2", 1.11); - JsScriptBindings bindings = - new JsScriptBindings(new FieldDefBindings(Collections.emptyMap()), params); + JsScriptBindings bindings = new JsScriptBindings(new FieldDefBindings(name -> null), params); DoubleValuesSource p1Source = bindings.getDoubleValuesSource("param1"); assertEquals(100D, p1Source.getValues(null, null).doubleValue(), 0.001); DoubleValuesSource p2Source = bindings.getDoubleValuesSource("param2"); @@ -108,7 +107,8 @@ public void testGetBindingForField() { fieldDefMap.put("field1", new VirtualFieldDef("field1", field1Source)); fieldDefMap.put("field2", new VirtualFieldDef("field2", field2Source)); - JsScriptBindings bindings = new JsScriptBindings(new FieldDefBindings(fieldDefMap), params); + JsScriptBindings bindings = + new JsScriptBindings(new FieldDefBindings(fieldDefMap::get), params); DoubleValuesSource f1Source = bindings.getDoubleValuesSource("field1"); DoubleValuesSource f2Source = bindings.getDoubleValuesSource("field2"); assertNotSame(f1Source, f2Source); @@ -128,7 +128,8 @@ public void testInvalidName() { fieldDefMap.put("field1", new VirtualFieldDef("field1", field1Source)); fieldDefMap.put("field2", new VirtualFieldDef("field2", field2Source)); - JsScriptBindings bindings = new JsScriptBindings(new FieldDefBindings(fieldDefMap), params); + JsScriptBindings bindings = + new JsScriptBindings(new FieldDefBindings(fieldDefMap::get), params); bindings.getDoubleValuesSource("invalid"); } @@ -144,7 +145,8 @@ public void testExtendedInvalidName() { fieldDefMap.put("field1", new VirtualFieldDef("field1", field1Source)); fieldDefMap.put("field2", new VirtualFieldDef("field2", field2Source)); - JsScriptBindings bindings = new JsScriptBindings(new FieldDefBindings(fieldDefMap), params); + JsScriptBindings bindings = + new JsScriptBindings(new FieldDefBindings(fieldDefMap::get), params); bindings.getDoubleValuesSource("doc['invalid'].value"); } @@ -160,7 +162,8 @@ public void testExtendedIntIndex() { fieldDefMap.put("field1", new VirtualFieldDef("field1", field1Source)); fieldDefMap.put("field2", new VirtualFieldDef("field2", field2Source)); - JsScriptBindings bindings = new JsScriptBindings(new FieldDefBindings(fieldDefMap), params); + JsScriptBindings bindings = + new JsScriptBindings(new FieldDefBindings(fieldDefMap::get), params); bindings.getDoubleValuesSource("doc[1].value"); } @@ -176,7 +179,8 @@ public void testExtendedInvalidPrefix() { fieldDefMap.put("field1", new VirtualFieldDef("field1", field1Source)); fieldDefMap.put("field2", new VirtualFieldDef("field2", field2Source)); - JsScriptBindings bindings = new JsScriptBindings(new FieldDefBindings(fieldDefMap), params); + JsScriptBindings bindings = + new JsScriptBindings(new FieldDefBindings(fieldDefMap::get), params); bindings.getDoubleValuesSource("not_doc['field1'].value"); } @@ -192,7 +196,8 @@ public void testExtendedMissingProperty() { fieldDefMap.put("field1", new VirtualFieldDef("field1", field1Source)); fieldDefMap.put("field2", new VirtualFieldDef("field2", field2Source)); - JsScriptBindings bindings = new JsScriptBindings(new FieldDefBindings(fieldDefMap), params); + JsScriptBindings bindings = + new JsScriptBindings(new FieldDefBindings(fieldDefMap::get), params); bindings.getDoubleValuesSource("doc['field1']"); } @@ -202,8 +207,7 @@ public void testParamBindingIsCached() { params.put("param1", 100); params.put("param2", 1.11); - JsScriptBindings bindings = - new JsScriptBindings(new FieldDefBindings(Collections.emptyMap()), params); + JsScriptBindings bindings = new JsScriptBindings(new FieldDefBindings(name -> null), params); DoubleValuesSource p1Source = bindings.getDoubleValuesSource("param1"); DoubleValuesSource p2Source = bindings.getDoubleValuesSource("param2"); DoubleValuesSource p1SourceNext = bindings.getDoubleValuesSource("param1"); diff --git a/src/test/java/com/yelp/nrtsearch/server/luceneserver/search/SearchContextTest.java b/src/test/java/com/yelp/nrtsearch/server/luceneserver/search/SearchContextTest.java index 5d81b4246..878169428 100644 --- a/src/test/java/com/yelp/nrtsearch/server/luceneserver/search/SearchContextTest.java +++ b/src/test/java/com/yelp/nrtsearch/server/luceneserver/search/SearchContextTest.java @@ -88,7 +88,7 @@ private SearchContext.Builder getCompleteBuilder() throws IOException { .setCollector(new DummyCollector()) .setFetchTasks(new FetchTasks(Collections.emptyList())) .setRescorers(Collections.emptyList()) - .setDocLookup(new DocLookup(getGlobalState().getIndex(DEFAULT_TEST_INDEX), null)) + .setDocLookup(new DocLookup(getGlobalState().getIndex(DEFAULT_TEST_INDEX)::getField)) .setSharedDocContext(new DefaultSharedDocContext()); }