Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public String printFeatureVector(LTRScoringQuery.FeatureInfo[] featuresInfo) {
}
}

final String features = (sb.length() > 0 ? sb.substring(0, sb.length() - 1) : "");
final String features = (!sb.isEmpty() ? sb.substring(0, sb.length() - 1) : "");

return features;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public abstract class FeatureLogger {
public enum FeatureFormat {
DENSE,
SPARSE
};
}

protected final FeatureFormat featureFormat;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ public ModelWeight createWeight(IndexSearcher searcher, ScoreMode scoreMode, flo
extractedFeatureWeights[i++] = fw;
}
for (final Feature f : modelFeatures) {
// we can lookup by featureid because all features will be extracted
// we can look up by featureid because all features will be extracted
modelFeaturesWeights[j++] = extractedFeatureWeights[f.getIndex()];
}
} else {
Expand All @@ -248,10 +248,9 @@ private void createWeights(
IndexSearcher searcher,
boolean needsScores,
List<Feature.FeatureWeight> featureWeights,
Collection<Feature> features)
throws IOException {
Collection<Feature> features) {
final SolrQueryRequest req = getRequest();
// since the feature store is a linkedhashmap order is preserved
// since the feature store is a linked hashmap order is preserved
for (final Feature f : features) {
try {
Feature.FeatureWeight fw = f.createWeight(searcher, needsScores, req, originalQuery, efi);
Expand Down Expand Up @@ -465,7 +464,7 @@ public ScorerSupplier scorerSupplier(LeafReaderContext context) throws IOExcepti
public ModelScorer modelScorer(LeafReaderContext context) throws IOException {

final List<Feature.FeatureWeight.FeatureScorer> featureScorers =
new ArrayList<Feature.FeatureWeight.FeatureScorer>(extractedFeatureWeights.length);
new ArrayList<>(extractedFeatureWeights.length);
for (final Feature.FeatureWeight featureWeight : extractedFeatureWeights) {
final Feature.FeatureWeight.FeatureScorer scorer = featureWeight.featureScorer(context);
if (scorer != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public void acquireLTRSemaphore() throws InterruptedException {
ltrSemaphore.acquire();
}

public void releaseLTRSemaphore() throws InterruptedException {
public void releaseLTRSemaphore() {
ltrSemaphore.release();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ public DocIdSetIterator iterator() {
}

// Currently (Q1 2021) we intentionally don't delegate twoPhaseIterator()
// because it doesn't always work and we don't yet know why, please see
// because it doesn't always work, and we don't yet know why, please see
// SOLR-15071 for more details.

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ protected void validate() throws FeatureException {
}

/** Decodes the norm value, assuming it is a single byte. */
private final float decodeNorm(long norm) {
private float decodeNorm(long norm) {
return NORM_TABLE[(int) (norm & 0xFF)]; // & 0xFF maps negative bytes to
// positive above 127
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@ public FieldValueFeatureWeight(
}

/**
* Override this method in sub classes that wish to use not an absolute time but an interval
* such as document age or remaining shelf life relative to a specific date or relative to now.
* Override this method in subclasses that wish to use not an absolute time but an interval such
* as document age or remaining shelf life relative to a specific date or relative to now.
*
* @param val value of the field
* @return value after transformation
Expand Down Expand Up @@ -179,14 +179,12 @@ public FeatureScorer featureScorer(LeafReaderContext context) throws IOException
/** A FeatureScorer that reads the stored value for a field */
public class FieldValueFeatureScorer extends FeatureScorer {

private final LeafReaderContext context;
private final StoredFields storedFields;

public FieldValueFeatureScorer(
FeatureWeight weight, LeafReaderContext context, DocIdSetIterator itr)
throws IOException {
super(weight, itr);
this.context = context;
this.storedFields = (context == null ? null : context.reader().storedFields());
}

Expand All @@ -205,7 +203,7 @@ public float score() throws IOException {
} else {
final String string = indexableField.stringValue();
if (string.length() == 1) {
// boolean values in the index are encoded with the
// boolean values in the index are encoded with
// a single char contained in TRUE_TOKEN or FALSE_TOKEN
// (see BoolField)
if (string.charAt(0) == BoolField.TRUE_TOKEN[0]) {
Expand All @@ -217,8 +215,7 @@ public float score() throws IOException {
}
}
} catch (final IOException e) {
throw new FeatureException(
e.toString() + ": " + "Unable to extract feature for " + name, e);
throw new FeatureException(e + ": " + "Unable to extract feature for " + name, e);
}
return getDefaultValue();
}
Expand Down Expand Up @@ -320,7 +317,7 @@ public float score() throws IOException {
private float readSortedDocValues(BytesRef bytesRef) {
String string = bytesRef.utf8ToString();
if (string.length() == 1) {
// boolean values in the index are encoded with the
// boolean values in the index are encoded with
// a single char contained in TRUE_TOKEN or FALSE_TOKEN
// (see BoolField)
if (string.charAt(0) == BoolField.TRUE_TOKEN[0]) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
* differently if the search came from a mobile device, or maybe you want to use your external query
* intent system as a feature. In the rerank request you can pass in rq={... efi.userFromMobile=1},
* and the above feature will return 1 for all the docs for that request. If required is set to
* true, the request will return an error since you failed to pass in the efi, otherwise if will
* true, the request will return an error since you failed to pass in the efi, otherwise it will
* just skip the feature and use a default value of 0 instead.
*/
public class ValueFeature extends Feature {
Expand All @@ -64,7 +64,7 @@ public void setValue(Object value) {
} else if (value instanceof Double) {
configValue = ((Double) value).floatValue();
} else if (value instanceof Float) {
configValue = ((Float) value).floatValue();
configValue = (Float) value;
} else if (value instanceof Integer) {
configValue = ((Integer) value).floatValue();
} else if (value instanceof Long) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,20 @@
import org.apache.solr.search.RankQuery;

/**
* A learning to rank Query with Interleaving, will incapsulate two models, and delegate to it the
* A learning to rank Query with Interleaving, will encapsulate two models, and delegate to it the
* rescoring of the documents.
*/
public class LTRInterleavingQuery extends LTRQuery {
private final LTRInterleavingScoringQuery[] rerankingQueries;
private final Interleaving interlavingAlgorithm;
private final Interleaving interleavingAlgorithm;

public LTRInterleavingQuery(
Interleaving interleavingAlgorithm,
LTRInterleavingScoringQuery[] rerankingQueries,
int rerankDocs) {
super(null, rerankDocs, new LTRInterleavingRescorer(interleavingAlgorithm, rerankingQueries));
this.rerankingQueries = rerankingQueries;
this.interlavingAlgorithm = interleavingAlgorithm;
this.interleavingAlgorithm = interleavingAlgorithm;
}

@Override
Expand Down Expand Up @@ -79,7 +79,7 @@ public String toString(String field) {

@Override
protected Query rewrite(Query rewrittenMainQuery) throws IOException {
return new LTRInterleavingQuery(interlavingAlgorithm, rerankingQueries, reRankDocs)
return new LTRInterleavingQuery(interleavingAlgorithm, rerankingQueries, reRankDocs)
.wrap(rewrittenMainQuery);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ public int hashCode() {
return hashCode;
}

private final int calculateHashCode() {
private int calculateHashCode() {
final int prime = 31;
int result = 1;
result = (prime * result) + Objects.hashCode(features);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,7 @@ public Explanation explain(
index++;
}

return Explanation.match(
finalScore, toString() + " model applied to features, sum of:", details);
return Explanation.match(finalScore, this + " model applied to features, sum of:", details);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ public class MultipleAdditiveTreesModel extends LTRScoringModel {

private boolean isNullSameAsZero = true;

public void setIsNullSameAsZero(boolean nullSameAsZero) {
isNullSameAsZero = nullSameAsZero;
}

private RegressionTree createRegressionTree(Map<String, Object> map) {
final RegressionTree rt = new RegressionTree();
if (map != null) {
Expand All @@ -132,10 +136,6 @@ private RegressionTreeNode createRegressionTreeNode(Map<String, Object> map) {
return rtn;
}

public void setIsNullSameAsZero(boolean nullSameAsZero) {
isNullSameAsZero = nullSameAsZero;
}

public class RegressionTreeNode {
private static final float NODE_SPLIT_SLACK = 1E-6f;

Expand Down Expand Up @@ -197,7 +197,7 @@ public String toString() {
sb.append(value);
} else {
sb.append("(feature=").append(feature);
sb.append(",threshold=").append(threshold.floatValue() - NODE_SPLIT_SLACK);
sb.append(",threshold=").append(threshold - NODE_SPLIT_SLACK);
if (missing != null) {
sb.append(",missing=").append(missing);
}
Expand Down Expand Up @@ -231,9 +231,9 @@ public void setRoot(Object root) {

public float score(float[] featureVector) {
if (isNullSameAsZero) {
return weight.floatValue() * scoreNode(featureVector, root);
return weight * scoreNode(featureVector, root);
} else {
return weight.floatValue() * scoreNodeWithNullSupport(featureVector, root);
return weight * scoreNodeWithNullSupport(featureVector, root);
}
}

Expand Down Expand Up @@ -500,8 +500,7 @@ public Explanation explain(
index++;
}

return Explanation.match(
finalScore, toString() + " model applied to features, sum of:", details);
return Explanation.match(finalScore, this + " model applied to features, sum of:", details);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,11 @@ protected interface Activation {
}

public interface Layer {
public float[] calculateOutput(float[] inputVec);
float[] calculateOutput(float[] inputVec);

public int validate(int inputDim) throws ModelException;
int validate(int inputDim) throws ModelException;

public String describe();
String describe();
}

public class DefaultLayer implements Layer {
Expand Down Expand Up @@ -235,19 +235,19 @@ public int validate(int inputDim) throws ModelException {
"Dimension mismatch in model \""
+ name
+ "\". Layer "
+ Integer.toString(this.layerID)
+ this.layerID
+ " has "
+ Integer.toString(this.numUnits)
+ this.numUnits
+ " bias weights but "
+ Integer.toString(this.matrixRows)
+ this.matrixRows
+ " weight matrix rows.");
}
if (this.activation == null) {
throw new ModelException(
"Invalid activation function (\""
+ this.activationStr
+ "\") in layer "
+ Integer.toString(this.layerID)
+ this.layerID
+ " of model \""
+ name
+ "\".");
Expand All @@ -258,23 +258,23 @@ public int validate(int inputDim) throws ModelException {
"Dimension mismatch in model \""
+ name
+ "\". The input has "
+ Integer.toString(inputDim)
+ inputDim
+ " features, but the weight matrix for layer 0 has "
+ Integer.toString(this.matrixCols)
+ this.matrixCols
+ " columns.");
} else {
throw new ModelException(
"Dimension mismatch in model \""
+ name
+ "\". The weight matrix for layer "
+ Integer.toString(this.layerID - 1)
+ (this.layerID - 1)
+ " has "
+ Integer.toString(inputDim)
+ inputDim
+ " rows, but the "
+ "weight matrix for layer "
+ Integer.toString(this.layerID)
+ this.layerID
+ " has "
+ Integer.toString(this.matrixCols)
+ this.matrixCols
+ " columns.");
}
}
Expand All @@ -285,9 +285,9 @@ public int validate(int inputDim) throws ModelException {
public String describe() {
final StringBuilder sb = new StringBuilder();
sb.append("(matrix=")
.append(Integer.toString(this.matrixRows))
.append(this.matrixRows)
.append('x')
.append(Integer.toString(this.matrixCols))
.append(this.matrixCols)
.append(",activation=")
.append(this.activationStr)
.append(")");
Expand Down Expand Up @@ -338,7 +338,7 @@ protected void validate() throws ModelException {
"The output matrix for model \""
+ name
+ "\" has "
+ Integer.toString(inputDim)
+ inputDim
+ " rows, but should only have one.");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,6 @@ public Explanation getNormalizerExplanation(Explanation e, int idx) {

@Override
public String toString() {
final StringBuilder sb = new StringBuilder(getClass().getSimpleName());
sb.append("(name=").append(getName());
sb.append(",model=(").append(model.toString()).append(")");

return sb.toString();
return getClass().getSimpleName() + "(name=" + getName() + ",model=(" + model.toString() + ")";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public abstract class Normalizer {

public Explanation explain(Explanation explain) {
final float normalized = normalize(explain.getValue().floatValue());
final String explainDesc = "normalized using " + toString();
final String explainDesc = "normalized using " + this;

return Explanation.match(normalized, explainDesc, explain);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ public Explanation explain(
float finalScore,
List<Explanation> featureExplanations) {
return Explanation.match(
finalScore, toString() + " logging model, used only for logging the features");
finalScore, this + " logging model, used only for logging the features");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,9 @@ public QParser createParser(
}

/**
* Given a set of local SolrParams, extract all of the efi.key=value params into a map
* Given a set of local SolrParams, extract all the efi.key=value params into a map
*
* @param localParams Local request parameters that might conatin efi params
* @param localParams Local request parameters that might contain efi params
* @return Map of efi params, where the key is the name of the efi param, and the value is the
* value of the efi param
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import org.apache.solr.search.RankQuery;

/**
* A learning to rank Query, will incapsulate a learning to rank model, and delegate to it the
* A learning to rank Query, will encapsulate a learning to rank model, and delegate to it the
* rescoring of the documents.
*/
public class LTRQuery extends AbstractReRankQuery {
Expand Down
Loading
Loading