use of org.apache.solr.ltr.store.rest.ManagedFeatureStore in project lucene-solr by apache.
the class TestRerankBase method createModelFromFiles.
public static LTRScoringModel createModelFromFiles(String modelFileName, String featureFileName, String featureStoreName) throws ModelException, Exception {
URL url = TestRerankBase.class.getResource("/modelExamples/" + modelFileName);
final String modelJson = FileUtils.readFileToString(new File(url.toURI()), "UTF-8");
final ManagedModelStore ms = getManagedModelStore();
url = TestRerankBase.class.getResource("/featureExamples/" + featureFileName);
final String featureJson = FileUtils.readFileToString(new File(url.toURI()), "UTF-8");
Object parsedFeatureJson = null;
try {
parsedFeatureJson = ObjectBuilder.fromJSON(featureJson);
} catch (final IOException ioExc) {
throw new ModelException("ObjectBuilder failed parsing json", ioExc);
}
final ManagedFeatureStore fs = getManagedFeatureStore();
// fs.getFeatureStore(null).clear();
// is this safe??
fs.doDeleteChild(null, featureStoreName);
// based on my need to call this I dont think that
// "getNewManagedFeatureStore()"
// is actually returning a new feature store each time
fs.applyUpdatesToManagedData(parsedFeatureJson);
// can we skip this and just use fs directly below?
ms.setManagedFeatureStore(fs);
final LTRScoringModel ltrScoringModel = ManagedModelStore.fromLTRScoringModelMap(solrResourceLoader, mapFromJson(modelJson), ms.getManagedFeatureStore());
ms.addModel(ltrScoringModel);
return ltrScoringModel;
}
Aggregations