Search in sources :

Example 1 with ManagedFeatureStore

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;
}
Also used : ManagedModelStore(org.apache.solr.ltr.store.rest.ManagedModelStore) ModelException(org.apache.solr.ltr.model.ModelException) IOException(java.io.IOException) File(java.io.File) URL(java.net.URL) ManagedFeatureStore(org.apache.solr.ltr.store.rest.ManagedFeatureStore) LTRScoringModel(org.apache.solr.ltr.model.LTRScoringModel)

Aggregations

File (java.io.File)1 IOException (java.io.IOException)1 URL (java.net.URL)1 LTRScoringModel (org.apache.solr.ltr.model.LTRScoringModel)1 ModelException (org.apache.solr.ltr.model.ModelException)1 ManagedFeatureStore (org.apache.solr.ltr.store.rest.ManagedFeatureStore)1 ManagedModelStore (org.apache.solr.ltr.store.rest.ManagedModelStore)1