Search in sources :

Example 6 with FeatureStore

use of org.apache.solr.ltr.store.FeatureStore in project lucene-solr by apache.

the class ManagedModelStore method fromLTRScoringModelMap.

@SuppressWarnings("unchecked")
public static LTRScoringModel fromLTRScoringModelMap(SolrResourceLoader solrResourceLoader, Map<String, Object> modelMap, ManagedFeatureStore managedFeatureStore) {
    final FeatureStore featureStore = managedFeatureStore.getFeatureStore((String) modelMap.get(STORE_KEY));
    final List<Feature> features = new ArrayList<>();
    final List<Normalizer> norms = new ArrayList<>();
    final List<Object> featureList = (List<Object>) modelMap.get(FEATURES_KEY);
    if (featureList != null) {
        for (final Object feature : featureList) {
            final Map<String, Object> featureMap = (Map<String, Object>) feature;
            features.add(lookupFeatureFromFeatureMap(featureMap, featureStore));
            norms.add(createNormalizerFromFeatureMap(solrResourceLoader, featureMap));
        }
    }
    return LTRScoringModel.getInstance(solrResourceLoader, // modelClassName
    (String) modelMap.get(CLASS_KEY), // modelName
    (String) modelMap.get(NAME_KEY), features, norms, featureStore.getName(), featureStore.getFeatures(), (Map<String, Object>) modelMap.get(PARAMS_KEY));
}
Also used : Normalizer(org.apache.solr.ltr.norm.Normalizer) IdentityNormalizer(org.apache.solr.ltr.norm.IdentityNormalizer) ArrayList(java.util.ArrayList) NamedList(org.apache.solr.common.util.NamedList) ArrayList(java.util.ArrayList) List(java.util.List) Feature(org.apache.solr.ltr.feature.Feature) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) FeatureStore(org.apache.solr.ltr.store.FeatureStore)

Example 7 with FeatureStore

use of org.apache.solr.ltr.store.FeatureStore in project lucene-solr by apache.

the class TestManagedFeatureStore method testFeatureStoreGet.

@Test
public void testFeatureStoreGet() throws FeatureException {
    final FeatureStore fs = fstore.getFeatureStore("fstore-testFeature2");
    for (int i = 0; i < 5; i++) {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("value", i);
        final String name = "c" + i;
        fstore.addFeature(createMap(name, ValueFeature.class.getCanonicalName(), params), "fstore-testFeature2");
    }
    for (int i = 0; i < 5; i++) {
        final Feature f = fs.get("c" + i);
        assertEquals("c" + i, f.getName());
        assertTrue(f instanceof ValueFeature);
        final ValueFeature vf = (ValueFeature) f;
        assertEquals(i, vf.getValue());
    }
}
Also used : HashMap(java.util.HashMap) ValueFeature(org.apache.solr.ltr.feature.ValueFeature) ValueFeature(org.apache.solr.ltr.feature.ValueFeature) Feature(org.apache.solr.ltr.feature.Feature) OriginalScoreFeature(org.apache.solr.ltr.feature.OriginalScoreFeature) FeatureStore(org.apache.solr.ltr.store.FeatureStore) ManagedFeatureStore(org.apache.solr.ltr.store.rest.ManagedFeatureStore) Test(org.junit.Test)

Example 8 with FeatureStore

use of org.apache.solr.ltr.store.FeatureStore in project lucene-solr by apache.

the class TestManagedFeatureStore method testDefaultFeatureStoreName.

@Test
public void testDefaultFeatureStoreName() {
    assertEquals("_DEFAULT_", FeatureStore.DEFAULT_FEATURE_STORE_NAME);
    final FeatureStore expectedFeatureStore = fstore.getFeatureStore(FeatureStore.DEFAULT_FEATURE_STORE_NAME);
    final FeatureStore actualFeatureStore = fstore.getFeatureStore(null);
    assertEquals("getFeatureStore(null) should return the default feature store", expectedFeatureStore, actualFeatureStore);
}
Also used : FeatureStore(org.apache.solr.ltr.store.FeatureStore) ManagedFeatureStore(org.apache.solr.ltr.store.rest.ManagedFeatureStore) Test(org.junit.Test)

Aggregations

FeatureStore (org.apache.solr.ltr.store.FeatureStore)8 Feature (org.apache.solr.ltr.feature.Feature)4 ManagedFeatureStore (org.apache.solr.ltr.store.rest.ManagedFeatureStore)4 Test (org.junit.Test)4 HashMap (java.util.HashMap)3 ArrayList (java.util.ArrayList)2 LinkedHashMap (java.util.LinkedHashMap)2 List (java.util.List)2 Map (java.util.Map)2 NamedList (org.apache.solr.common.util.NamedList)2 OriginalScoreFeature (org.apache.solr.ltr.feature.OriginalScoreFeature)2 ValueFeature (org.apache.solr.ltr.feature.ValueFeature)2 SolrException (org.apache.solr.common.SolrException)1 IdentityNormalizer (org.apache.solr.ltr.norm.IdentityNormalizer)1 Normalizer (org.apache.solr.ltr.norm.Normalizer)1 SolrQueryResponse (org.apache.solr.response.SolrQueryResponse)1