use of ddf.catalog.data.impl.MetacardImpl in project ddf by codice.
the class SearchControllerTest method createFramework.
private CatalogFramework createFramework() {
final long COUNT = 2;
CatalogFramework framework = mock(CatalogFramework.class);
List<Result> results = new ArrayList<Result>();
for (int i = 0; i < COUNT; i++) {
Result result = mock(Result.class);
MetacardImpl metacard = new MetacardImpl();
metacard.setId("Metacard_" + i);
metacard.setTitle("Metacard " + i);
metacard.setLocation("POINT(" + i + " " + i + ")");
metacard.setType(BasicTypes.BASIC_METACARD);
metacard.setCreatedDate(TIMESTAMP);
metacard.setEffectiveDate(TIMESTAMP);
metacard.setExpirationDate(TIMESTAMP);
metacard.setModifiedDate(TIMESTAMP);
metacard.setContentTypeName("TEST");
metacard.setContentTypeVersion("1.0");
metacard.setTargetNamespace(URI.create(getClass().getPackage().getName()));
when(result.getDistanceInMeters()).thenReturn(100.0 * i);
when(result.getRelevanceScore()).thenReturn(100.0 * (COUNT - i) / COUNT);
when(result.getMetacard()).thenReturn(metacard);
results.add(result);
}
QueryResponse response = new QueryResponseImpl(mock(QueryRequest.class), new ArrayList<Result>(), COUNT);
response.getResults().addAll(results);
try {
when(framework.query(any(QueryRequest.class))).thenReturn(response);
} catch (UnsupportedQueryException e) {
LOGGER.debug("Error querying framework", e);
} catch (SourceUnavailableException e) {
LOGGER.debug("Error querying framework", e);
} catch (FederationException e) {
LOGGER.debug("Error querying framework", e);
}
return framework;
}
use of ddf.catalog.data.impl.MetacardImpl in project ddf by codice.
the class QueryRunnable method normalizeRelevance.
protected void normalizeRelevance(List<Result> indexResults, Map<String, Result> results) {
for (Result indexResult : indexResults) {
String resultKey = indexResult.getMetacard().getAttribute(FilteringDynamicSchemaResolver.SOURCE_ID).getValue() + indexResult.getMetacard().getId();
if (results.containsKey(resultKey)) {
MetacardImpl metacard = new MetacardImpl(results.get(resultKey).getMetacard());
metacard.setAttribute(Search.CACHED, null);
ResultImpl result = new ResultImpl(metacard);
result.setRelevanceScore(indexResult.getRelevanceScore());
results.put(resultKey, result);
}
}
}
use of ddf.catalog.data.impl.MetacardImpl in project ddf by codice.
the class QueryRunnable method normalizeDistances.
protected void normalizeDistances(Filter query, Map<String, Result> results) {
String wkt = extractQueryWkt(query);
if (StringUtils.isNotBlank(wkt)) {
Shape queryShape;
try {
queryShape = getShape(wkt);
} catch (ParseException e) {
LOGGER.debug("Unable to parse query WKT to calculate distance", e);
return;
}
for (Map.Entry<String, Result> entry : results.entrySet()) {
Result result = entry.getValue();
if (result.getMetacard() != null && StringUtils.isNotBlank(result.getMetacard().getLocation())) {
try {
Shape locationShape = getShape(result.getMetacard().getLocation());
double distance = DistanceUtils.degrees2Dist(SPATIAL_CONTEXT.calcDistance(locationShape.getCenter(), queryShape.getCenter()), DistanceUtils.EARTH_MEAN_RADIUS_KM) * METERS_IN_KILOMETERS;
ResultImpl updatedResult = new ResultImpl(new MetacardImpl(result.getMetacard()));
updatedResult.setDistanceInMeters(distance);
results.put(entry.getKey(), updatedResult);
} catch (ParseException e) {
LOGGER.debug("Unable to parse metacard WKT to calculate distance", e);
}
}
}
}
}
use of ddf.catalog.data.impl.MetacardImpl in project ddf by codice.
the class TestMetacardValueResolver method testResolveSourceId.
@Test
public void testResolveSourceId() {
MetacardImpl mc = new MetacardImpl();
String expected = "src";
mc.setSourceId(expected);
MetacardValueResolver mvr = new MetacardValueResolver();
Object props = mvr.resolve(mc, "properties");
Object actual = mvr.resolve(props, "source-id");
assertEquals(expected, actual);
}
use of ddf.catalog.data.impl.MetacardImpl in project ddf by codice.
the class CacheSolrMetacardClient method createMetacard.
@Override
public MetacardImpl createMetacard(SolrDocument doc) throws MetacardCreationException {
MetacardImpl metacard = super.createMetacard(doc);
metacard.setSourceId(getMetacardSource(doc));
metacard.setId(getMetacardId(doc));
return metacard;
}
Aggregations