mirror of https://github.com/apache/lucene.git
SOLR-11931: Fix contrib/ltr custom inner class feature/normaliser/model persistence.
This commit is contained in:
parent
b6f683d30b
commit
a1a9341a9c
|
@ -195,6 +195,8 @@ Bug Fixes
|
|||
* SOLR-11459: In-place update of nonexistent doc following existing doc update fails to create the doc.
|
||||
(Andrey Kudryavtsev via Mikhail Khludnev)
|
||||
|
||||
* SOLR-11931: Fix contrib/ltr custom inner class feature/normaliser/model persistence. (Christine Poerschke)
|
||||
|
||||
Optimizations
|
||||
----------------------
|
||||
|
||||
|
|
|
@ -192,7 +192,7 @@ public class ManagedFeatureStore extends ManagedResource implements ManagedResou
|
|||
private static LinkedHashMap<String,Object> toFeatureMap(Feature feat) {
|
||||
final LinkedHashMap<String,Object> o = new LinkedHashMap<>(4, 1.0f); // 1 extra for caller to add store
|
||||
o.put(NAME_KEY, feat.getName());
|
||||
o.put(CLASS_KEY, feat.getClass().getCanonicalName());
|
||||
o.put(CLASS_KEY, feat.getClass().getName());
|
||||
o.put(PARAMS_KEY, feat.paramsToMap());
|
||||
return o;
|
||||
}
|
||||
|
|
|
@ -268,7 +268,7 @@ public class ManagedModelStore extends ManagedResource implements ManagedResourc
|
|||
final LinkedHashMap<String,Object> modelMap = new LinkedHashMap<>(5, 1.0f);
|
||||
|
||||
modelMap.put(NAME_KEY, model.getName());
|
||||
modelMap.put(CLASS_KEY, model.getClass().getCanonicalName());
|
||||
modelMap.put(CLASS_KEY, model.getClass().getName());
|
||||
modelMap.put(STORE_KEY, model.getFeatureStoreName());
|
||||
|
||||
final List<Map<String,Object>> features = new ArrayList<>();
|
||||
|
@ -321,7 +321,7 @@ public class ManagedModelStore extends ManagedResource implements ManagedResourc
|
|||
private static LinkedHashMap<String,Object> toNormalizerMap(Normalizer norm) {
|
||||
final LinkedHashMap<String,Object> normalizer = new LinkedHashMap<>(2, 1.0f);
|
||||
|
||||
normalizer.put(CLASS_KEY, norm.getClass().getCanonicalName());
|
||||
normalizer.put(CLASS_KEY, norm.getClass().getName());
|
||||
|
||||
final LinkedHashMap<String,Object> params = norm.paramsToMap();
|
||||
if (params != null) {
|
||||
|
|
|
@ -22,14 +22,17 @@ import java.io.FileOutputStream;
|
|||
import java.io.OutputStreamWriter;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.solr.ltr.TestRerankBase;
|
||||
import org.apache.solr.ltr.feature.Feature;
|
||||
import org.apache.solr.ltr.feature.FieldValueFeature;
|
||||
import org.apache.solr.ltr.feature.ValueFeature;
|
||||
import org.apache.solr.ltr.model.DefaultWrapperModel;
|
||||
import org.apache.solr.ltr.model.LinearModel;
|
||||
import org.apache.solr.ltr.norm.Normalizer;
|
||||
import org.apache.solr.ltr.store.FeatureStore;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
@ -261,4 +264,67 @@ public class TestModelManagerPersistence extends TestRerankBase {
|
|||
|
||||
// NOTE: we don't test the persistence of the deletion here because it's tested in testFilePersistence
|
||||
}
|
||||
|
||||
public static class DummyCustomFeature extends ValueFeature {
|
||||
public DummyCustomFeature(String name, Map<String,Object> params) {
|
||||
super(name, params);
|
||||
}
|
||||
}
|
||||
|
||||
public static class DummyCustomModel extends LinearModel {
|
||||
public DummyCustomModel(String name, List<Feature> features, List<Normalizer> norms, String featureStoreName,
|
||||
List<Feature> allFeatures, Map<String,Object> params) {
|
||||
super(name, features, norms, featureStoreName, allFeatures, params);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInnerCustomClassesPersistence() throws Exception {
|
||||
|
||||
final String featureStoreName = "test42";
|
||||
|
||||
final String featureName = "feature42";
|
||||
final String featureClassName;
|
||||
if (random().nextBoolean()) {
|
||||
featureClassName = ValueFeature.class.getName();
|
||||
} else {
|
||||
featureClassName = DummyCustomFeature.class.getName();
|
||||
}
|
||||
|
||||
loadFeature(featureName, featureClassName, "test42",
|
||||
"{\"value\":"+random().nextInt(100)+"}");
|
||||
assertJQ(ManagedFeatureStore.REST_END_POINT + "/"+featureStoreName,
|
||||
"/features/[0]/name=='"+featureName+"'");
|
||||
|
||||
final String modelName = "model42";
|
||||
final String modelClassName;
|
||||
if (random().nextBoolean()) {
|
||||
modelClassName = LinearModel.class.getName();
|
||||
} else {
|
||||
modelClassName = DummyCustomModel.class.getName();
|
||||
}
|
||||
|
||||
loadModel(modelName, modelClassName,
|
||||
new String[] { featureName }, featureStoreName,
|
||||
"{\"weights\":{\""+featureName+"\":1.0}}");
|
||||
assertJQ(ManagedModelStore.REST_END_POINT,
|
||||
"/models/[0]/name=='"+modelName+"'");
|
||||
|
||||
restTestHarness.reload();
|
||||
assertJQ(ManagedFeatureStore.REST_END_POINT + "/"+featureStoreName,
|
||||
"/features/[0]/name=='"+featureName+"'");
|
||||
assertJQ(ManagedModelStore.REST_END_POINT,
|
||||
"/models/[0]/name=='"+modelName+"'");
|
||||
|
||||
assertJDelete(ManagedModelStore.REST_END_POINT + "/"+modelName,
|
||||
"/responseHeader/status==0");
|
||||
assertJQ(ManagedModelStore.REST_END_POINT,
|
||||
"/models/==[]");
|
||||
|
||||
assertJDelete(ManagedFeatureStore.REST_END_POINT + "/"+featureStoreName,
|
||||
"/responseHeader/status==0");
|
||||
assertJQ(ManagedFeatureStore.REST_END_POINT + "/"+featureStoreName,
|
||||
"/features/==[]");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue