Search in sources :

Example 1 with FeatureStore

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

the class ManagedFeatureStore method applyUpdatesToManagedData.

@SuppressWarnings("unchecked")
@Override
public Object applyUpdatesToManagedData(Object updates) {
    if (updates instanceof List) {
        final List<Map<String, Object>> up = (List<Map<String, Object>>) updates;
        for (final Map<String, Object> u : up) {
            final String featureStore = (String) u.get(FEATURE_STORE_NAME_KEY);
            addFeature(u, featureStore);
        }
    }
    if (updates instanceof Map) {
        // a unique feature
        Map<String, Object> updatesMap = (Map<String, Object>) updates;
        final String featureStore = (String) updatesMap.get(FEATURE_STORE_NAME_KEY);
        addFeature(updatesMap, featureStore);
    }
    final List<Object> features = new ArrayList<>();
    for (final FeatureStore fs : stores.values()) {
        features.addAll(featuresAsManagedResources(fs));
    }
    return features;
}
Also used : ArrayList(java.util.ArrayList) NamedList(org.apache.solr.common.util.NamedList) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) FeatureStore(org.apache.solr.ltr.store.FeatureStore)

Example 2 with FeatureStore

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

the class ManagedFeatureStore method addFeature.

public synchronized void addFeature(Map<String, Object> map, String featureStore) {
    log.info("register feature based on {}", map);
    final FeatureStore fstore = getFeatureStore(featureStore);
    final Feature feature = fromFeatureMap(solrResourceLoader, map);
    fstore.add(feature);
}
Also used : Feature(org.apache.solr.ltr.feature.Feature) FeatureStore(org.apache.solr.ltr.store.FeatureStore)

Example 3 with FeatureStore

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

the class ManagedFeatureStore method doGet.

/**
   * Called to retrieve a named part (the given childId) of the resource at the
   * given endpoint. Note: since we have a unique child feature store we ignore
   * the childId.
   */
@Override
public void doGet(BaseSolrResource endpoint, String childId) {
    final SolrQueryResponse response = endpoint.getSolrResponse();
    // If no feature store specified, show all the feature stores available
    if (childId == null) {
        response.add(FEATURE_STORE_JSON_FIELD, stores.keySet());
    } else {
        final FeatureStore store = getFeatureStore(childId);
        if (store == null) {
            throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "missing feature store [" + childId + "]");
        }
        response.add(FEATURES_JSON_FIELD, featuresAsManagedResources(store));
    }
}
Also used : SolrQueryResponse(org.apache.solr.response.SolrQueryResponse) FeatureStore(org.apache.solr.ltr.store.FeatureStore) SolrException(org.apache.solr.common.SolrException)

Example 4 with FeatureStore

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

the class TestManagedFeatureStore method testFeatureStoreAdd.

@Test
public void testFeatureStoreAdd() throws FeatureException {
    final FeatureStore fs = fstore.getFeatureStore("fstore-testFeature");
    for (int i = 0; i < 5; i++) {
        final String name = "c" + i;
        fstore.addFeature(createMap(name, OriginalScoreFeature.class.getCanonicalName(), null), "fstore-testFeature");
        final Feature f = fs.get(name);
        assertNotNull(f);
    }
    assertEquals(5, fs.getFeatures().size());
}
Also used : 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 5 with FeatureStore

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

the class TestManagedFeatureStore method testMissingFeatureReturnsNull.

@Test
public void testMissingFeatureReturnsNull() {
    final FeatureStore fs = fstore.getFeatureStore("fstore-testFeature3");
    for (int i = 0; i < 5; i++) {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("value", i);
        final String name = "testc" + (float) i;
        fstore.addFeature(createMap(name, ValueFeature.class.getCanonicalName(), params), "fstore-testFeature3");
    }
    assertNull(fs.get("missing_feature_name"));
}
Also used : HashMap(java.util.HashMap) 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