use of org.opengis.filter.sort.SortBy in project ddf by codice.
the class SolrMetacardClientImpl method setSortProperty.
protected String setSortProperty(QueryRequest request, SolrQuery query, SolrFilterDelegate solrFilterDelegate) {
SortBy sortBy = request.getQuery().getSortBy();
String sortProperty = "";
if (sortBy != null && sortBy.getPropertyName() != null) {
sortProperty = sortBy.getPropertyName().getPropertyName();
SolrQuery.ORDER order = SolrQuery.ORDER.desc;
if (sortBy.getSortOrder() == SortOrder.ASCENDING) {
order = SolrQuery.ORDER.asc;
}
query.setFields("*", RELEVANCE_SORT_FIELD);
if (Result.RELEVANCE.equals(sortProperty)) {
query.addSort(RELEVANCE_SORT_FIELD, order);
} else if (Result.DISTANCE.equals(sortProperty)) {
addDistanceSort(query, GEOMETRY_SORT_FIELD, order, solrFilterDelegate);
} else if (sortProperty.equals(Result.TEMPORAL)) {
query.addSort(resolver.getSortKey(resolver.getField(Metacard.EFFECTIVE, AttributeType.AttributeFormat.DATE, false)), order);
} else {
List<String> resolvedProperties = resolver.getAnonymousField(sortProperty);
if (!resolvedProperties.isEmpty()) {
for (String sortField : resolvedProperties) {
if (sortField.endsWith(SchemaFields.GEO_SUFFIX)) {
addDistanceSort(query, resolver.getSortKey(sortField), order, solrFilterDelegate);
} else if (!(sortField.endsWith(SchemaFields.BINARY_SUFFIX) || sortField.endsWith(SchemaFields.OBJECT_SUFFIX))) {
query.addSort(resolver.getSortKey(sortField), order);
}
}
} else {
LOGGER.debug("No schema field was found for sort property [{}]. No sort field was added to the query.", sortProperty);
}
}
}
return resolver.getSortKey(sortProperty);
}
use of org.opengis.filter.sort.SortBy in project ddf by codice.
the class SolrProviderTest method testSpatialNearestNeighbor.
@Test
public void testSpatialNearestNeighbor() throws Exception {
deleteAllIn(provider);
MetacardImpl metacard1 = new MockMetacard(Library.getFlagstaffRecord());
MetacardImpl metacard2 = new MockMetacard(Library.getTampaRecord());
MetacardImpl metacard3 = new MockMetacard(Library.getShowLowRecord());
// Add in the geometry
metacard1.setLocation(FLAGSTAFF_AIRPORT_POINT_WKT);
metacard2.setLocation(TAMPA_AIRPORT_POINT_WKT);
metacard3.setLocation(SHOW_LOW_AIRPORT_POINT_WKT);
List<Metacard> list = Arrays.asList((Metacard) metacard1, metacard2, metacard3);
create(list);
// Ascending
Filter positiveFilter = filterBuilder.attribute(Metacard.GEOGRAPHY).beyond().wkt(PHOENIX_POINT_WKT, 0);
QueryImpl query = new QueryImpl(positiveFilter);
SourceResponse sourceResponse = provider.query(new QueryRequestImpl(query));
assertEquals("Failed to find two records within 1000 nautical miles.", 2, sourceResponse.getResults().size());
assertTrue("Flagstaff record was not first in ascending order.", sourceResponse.getResults().get(0).getMetacard().getMetadata().indexOf(FLAGSTAFF_QUERY_PHRASE) > 0);
// Descending
SortBy sortby = new ddf.catalog.filter.impl.SortByImpl(Result.DISTANCE, org.opengis.filter.sort.SortOrder.DESCENDING);
query.setSortBy(sortby);
sourceResponse = provider.query(new QueryRequestImpl(query));
assertEquals("Failed to find two records within 1000 nautical miles.", 2, sourceResponse.getResults().size());
assertTrue("Flagstaff record was not last in descending order.", sourceResponse.getResults().get(1).getMetacard().getMetadata().indexOf(FLAGSTAFF_QUERY_PHRASE) > 0);
// Using WKT polygon
positiveFilter = filterBuilder.attribute(Metacard.GEOGRAPHY).beyond().wkt(ARIZONA_POLYGON_WKT, 0);
query = new QueryImpl(positiveFilter);
sourceResponse = provider.query(new QueryRequestImpl(query));
assertEquals("Failed to find two records based on polygon centroid.", 2, sourceResponse.getResults().size());
}
use of org.opengis.filter.sort.SortBy in project ddf by codice.
the class SolrProviderTest method testSortedPointRadiusWithComplexQuery.
@Test
public void testSortedPointRadiusWithComplexQuery() throws Exception {
deleteAllIn(provider);
MetacardImpl metacard1 = new MockMetacard(Library.getFlagstaffRecord());
MetacardImpl metacard2 = new MockMetacard(Library.getTampaRecord());
MetacardImpl metacard3 = new MockMetacard(Library.getShowLowRecord());
// Add in the geometry
metacard1.setLocation(FLAGSTAFF_AIRPORT_POINT_WKT);
metacard2.setLocation(TAMPA_AIRPORT_POINT_WKT);
metacard3.setLocation(SHOW_LOW_AIRPORT_POINT_WKT);
// Add in a content type
metacard1.setAttribute(Metacard.CONTENT_TYPE, "product");
List<Metacard> list = Arrays.asList((Metacard) metacard1, metacard2, metacard3);
/** CREATE **/
create(list);
// create a filter that has spatial and content type criteria
Filter contentFilter = filterBuilder.attribute(Metacard.CONTENT_TYPE).is().text("product");
Filter spatialFilter = filterBuilder.attribute(Metacard.GEOGRAPHY).intersecting().wkt(FLAGSTAFF_AIRPORT_POINT_WKT);
Filter finalFilter = filterBuilder.allOf(filterBuilder.attribute(Metacard.ANY_TEXT).like().text("flagstaff"), filterBuilder.allOf(contentFilter, spatialFilter));
// sort by distance
QueryImpl query = new QueryImpl(finalFilter);
SortBy sortby = new ddf.catalog.filter.impl.SortByImpl(Result.DISTANCE, org.opengis.filter.sort.SortOrder.DESCENDING);
query.setSortBy(sortby);
SourceResponse sourceResponse = provider.query(new QueryRequestImpl(query));
assertEquals(1, sourceResponse.getResults().size());
}
use of org.opengis.filter.sort.SortBy in project ddf by codice.
the class CswQueryFactoryTest method testPostGetRecordsValidSort.
@Test
public void testPostGetRecordsValidSort() throws CswException, UnsupportedQueryException, SourceUnavailableException, FederationException {
GetRecordsType grr = createDefaultPostRecordsRequest();
grr.setResultType(ResultType.RESULTS);
QueryType query = new QueryType();
SortByType incomingSort = new SortByType();
SortPropertyType propType = new SortPropertyType();
PropertyNameType propName = new PropertyNameType();
propName.setContent(Collections.singletonList(TITLE_TEST_ATTRIBUTE));
propType.setPropertyName(propName);
incomingSort.getSortProperty().add(propType);
query.setSortBy(incomingSort);
JAXBElement<QueryType> jaxbQuery = new JAXBElement<>(cswQnameOutPutSchema, QueryType.class, query);
grr.setAbstractQuery(jaxbQuery);
QueryRequest queryRequest = queryFactory.getQuery(grr);
SortBy resultSort = queryRequest.getQuery().getSortBy();
assertThat(resultSort.getPropertyName().getPropertyName(), is(CQL_FRAMEWORK_TEST_ATTRIBUTE));
assertThat(resultSort.getSortOrder(), is(SortOrder.ASCENDING));
}
use of org.opengis.filter.sort.SortBy in project ddf by codice.
the class TestWfsSource method testResultNumReturnedNegative.
@Test
public void testResultNumReturnedNegative() throws WfsException, SecurityServiceException, TransformerConfigurationException, UnsupportedQueryException {
//Setup
final String TITLE = "title";
final String searchPhrase = "*";
final int pageSize = 1;
WfsSource source = getWfsSource(ONE_TEXT_PROPERTY_SCHEMA, MockWfsServer.getFilterCapabilities(), GeospatialUtil.EPSG_4326_URN, 3, false, true, -1);
QueryImpl query = new QueryImpl(builder.attribute(Metacard.ANY_TEXT).is().like().text(searchPhrase));
query.setPageSize(pageSize);
SortBy sortBy = new SortByImpl(TITLE, SortOrder.DESCENDING);
query.setSortBy(sortBy);
QueryRequestImpl queryReq = new QueryRequestImpl(query);
// Perform test
SourceResponse resp = source.query(queryReq);
}
Aggregations