Skip to content

Commit

Permalink
asd
Browse files Browse the repository at this point in the history
  • Loading branch information
vim345 committed Feb 22, 2024
1 parent c27c13c commit 5d4d3ee
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
import org.apache.lucene.queries.function.ValueSource;

/**
* Field definition for a Virtual field. Virtual fields are able to produce a double value for each
* given index document.
* Field definition for a runtime field. Runtime fields are able to produce a value for each given
* index document.
*/
public class RuntimeFieldDef extends FieldDef {
private final ValueSource valuesSource;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ public static UpdatedFieldInfo updateFields(
List<Field> runtimeFields = new ArrayList<>();

for (Field field : updateFields) {
logger.info("TTTT: " + field.getType());
checkFieldName(field.getName());
if (FieldType.VIRTUAL.equals(field.getType())) {
virtualFields.add(field);
Expand All @@ -120,8 +119,6 @@ public static UpdatedFieldInfo updateFields(
// fields being registered. This is not a complete solution, since virtual fields can
// reference each other. TODO: fix to handle the chaining virtual field use case.
for (Field field : virtualFields) {
logger.info("VVVV: " + field.getType());

if (newFields.containsKey(field.getName())) {
throw new IllegalArgumentException("Duplicate field registration: " + field.getName());
}
Expand Down Expand Up @@ -238,7 +235,7 @@ public static void parseRuntimeField(Field field, FieldAndFacetState.Builder fie
} 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");
throw new IllegalArgumentException("Only js lang supported for index runtime fields");
}
// js scripts use Bindings instead of DocLookup
ValueSource values = factory.newFactory(params, null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,17 @@
import com.yelp.nrtsearch.server.luceneserver.doc.DocLookup;
import com.yelp.nrtsearch.server.luceneserver.doc.LoadedDocValues;
import com.yelp.nrtsearch.server.luceneserver.doc.SegmentDocLookup;
import com.yelp.nrtsearch.server.luceneserver.script.ScoreScript.SegmentFactory;
import java.io.IOException;
import java.util.Map;
import java.util.Objects;
import org.apache.lucene.index.LeafReaderContext;
import org.apache.lucene.queries.function.FunctionValues;
import org.apache.lucene.queries.function.ValueSource;
import org.apache.lucene.search.DoubleValues;
import org.apache.lucene.search.DoubleValuesSource;

/**
* Script to produce a double value for a given document. Implementations must have an execute
* function. This class conforms with the script compile contract, see {@link ScriptContext}. The
* script has access to the query parameters, the document doc values through {@link
* SegmentDocLookup}.
* Script to produce a value for a given document. Implementations must have an execute function.
* This class conforms with the script compile contract, see {@link ScriptContext}. The script has
* access to the query parameters, the document doc values through {@link SegmentDocLookup}.
*/
public abstract class RuntimeScript {

Expand All @@ -56,10 +52,9 @@ public abstract class RuntimeScript {
* @param leafContext lucene segment context
*/
public RuntimeScript(
Map<String, Object> params, DocLookup docLookup, LeafReaderContext leafContext, Object obj) {
Map<String, Object> params, DocLookup docLookup, LeafReaderContext leafContext) {
this.params = params;
this.segmentDocLookup = docLookup.getSegmentLookup(leafContext);
this.obj = obj;
}

/**
Expand All @@ -85,12 +80,12 @@ public Map<String, LoadedDocValues<?>> getDoc() {
}

/**
* Simple abstract implementation of a {@link DoubleValuesSource} this can be extended for engines
* that need to implement a custom {@link ScoreScript}. The newInstance and needs_score must be
* Simple abstract implementation of a {@link ValueSource} this can be extended for engines that
* need to implement a custom {@link RuntimeScript}. The newInstance and needs_score must be
* implemented. If more state is needed, the equals/hashCode should be redefined appropriately.
*
* <p>This class conforms with the script compile contract, see {@link ScriptContext}. However,
* Engines are also free to create there own {@link DoubleValuesSource} implementations instead.
* Engines are also free to create there own {@link ValueSource} implementations instead.
*/
public abstract static class SegmentFactory extends ValueSource {
private final Map<String, Object> params;
Expand All @@ -110,10 +105,10 @@ public DocLookup getDocLookup() {
}

/**
* Create a {@link DoubleValues} instance for the given lucene segment.
* Create a {@link FunctionValues} instance for the given lucene segment.
*
* @param ctx Context map for
* @param context segment context
* @param scores provider of segment document scores
* @return script to produce values for the given segment
*/
public abstract FunctionValues newInstance(Map ctx, LeafReaderContext context);
Expand All @@ -125,7 +120,7 @@ public DocLookup getDocLookup() {
*/
public abstract boolean needs_score();

/** Redirect {@link DoubleValuesSource} interface to script contract method. */
/** Redirect {@link ValueSource} interface to script contract method. */
@Override
public FunctionValues getValues(Map context, LeafReaderContext ctx) throws IOException {
return newInstance(context, ctx);
Expand All @@ -151,21 +146,21 @@ public boolean equals(Object obj) {

@Override
public String toString() {
return "ScoreScriptDoubleValuesSource: params: " + params + ", docLookup: " + docLookup;
return "RuntimeScriptValuesSource: params: " + params + ", docLookup: " + docLookup;
}
}

/**
* Factory required from the compilation of a ScoreScript. Used to produce request level {@link
* DoubleValuesSource}. See script compile contract {@link ScriptContext}.
* ValueSource}. See script compile contract {@link ScriptContext}.
*/
public interface Factory {
/**
* Create request level {@link SegmentFactory}.
*
* @param params parameters from script request
* @param docLookup index level doc value lookup provider
* @return {@link DoubleValuesSource} to evaluate script
* @return {@link ValueSource} to evaluate script
*/
ValueSource newFactory(Map<String, Object> params, DocLookup docLookup);
}
Expand Down

0 comments on commit 5d4d3ee

Please sign in to comment.