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;
}
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);
}
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));
}
}
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());
}
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"));
}
Aggregations