use of ddf.catalog.operation.impl.QueryImpl in project ddf by codice.
the class SolrProviderTest method testSpatialWithWkt.
private void testSpatialWithWkt(String metacardWkt, Filter positiveFilter, Filter negativeFilter) throws Exception {
deleteAllIn(provider, 4);
MetacardImpl metacard = new MockMetacard(Library.getFlagstaffRecord());
metacard.setLocation(metacardWkt);
List<Metacard> list = Arrays.asList((Metacard) metacard);
create(list);
SourceResponse sourceResponse = provider.query(new QueryRequestImpl(new QueryImpl(positiveFilter)));
assertEquals("Failed to find metacard WKT with filter", 1, sourceResponse.getResults().size());
sourceResponse = provider.query(new QueryRequestImpl(new QueryImpl(negativeFilter)));
assertEquals("Should not have found metacard record.", 0, sourceResponse.getResults().size());
}
use of ddf.catalog.operation.impl.QueryImpl in project ddf by codice.
the class SolrProviderTest method testContextualCaseSensitiveWildcardWithPunctuation.
@Test
public void testContextualCaseSensitiveWildcardWithPunctuation() throws Exception {
deleteAllIn(provider);
List<Metacard> list = Arrays.asList((Metacard) new MockMetacard(Library.getFlagstaffRecord()), (Metacard) new MockMetacard(Library.getTampaRecord()));
create(list);
CommonQueryBuilder queryBuilder = new CommonQueryBuilder();
boolean isCaseSensitive = true;
boolean isFuzzy = false;
QueryImpl query = null;
SourceResponse sourceResponse = null;
/** WILDCARD CASE SENSITIVE CONTEXTUAL QUERY **/
query = queryBuilder.like(Metacard.ANY_TEXT, "http://www.flagstaffchamber.com/arizona-cardinals*", isCaseSensitive, isFuzzy);
sourceResponse = provider.query(new QueryRequestImpl(query));
assertEquals(1, sourceResponse.getResults().size());
query = queryBuilder.like(Metacard.ANY_TEXT, "http://*10160", isCaseSensitive, isFuzzy);
sourceResponse = provider.query(new QueryRequestImpl(query));
assertEquals(1, sourceResponse.getResults().size());
/** NEGATIVE CASES **/
query = queryBuilder.like(Metacard.ANY_TEXT, "HTTP://www.flagstaffchamber.com/arizona-cardinals*", isCaseSensitive, isFuzzy);
query.setStartIndex(1);
sourceResponse = provider.query(new QueryRequestImpl(query));
assertEquals(0, sourceResponse.getResults().size());
query = queryBuilder.like(Metacard.ANY_TEXT, "10160*", isCaseSensitive, isFuzzy);
query.setStartIndex(1);
sourceResponse = provider.query(new QueryRequestImpl(query));
assertEquals(0, sourceResponse.getResults().size());
}
use of ddf.catalog.operation.impl.QueryImpl in project ddf by codice.
the class SolrProviderTest method testTextualSort.
@Test
public void testTextualSort() throws Exception {
deleteAllIn(provider);
List<Metacard> list = new ArrayList<Metacard>();
DateTime now = new DateTime();
for (int i = 65; i < 65 + 5; i++) {
MockMetacard m = new MockMetacard(Library.getFlagstaffRecord());
m.setEffectiveDate(now.minus(5L * i).toDate());
m.setTitle((char) i + " Record ");
list.add(m);
}
create(list);
Filter filter = null;
QueryImpl query = null;
SourceResponse sourceResponse = null;
// Sort all Textual ASCENDING
filter = filterBuilder.attribute(Metacard.EFFECTIVE).before().date(now.plusMillis(1).toDate());
query = new QueryImpl(filter);
query.setSortBy(new ddf.catalog.filter.impl.SortByImpl(Metacard.TITLE, SortOrder.ASCENDING.name()));
sourceResponse = provider.query(new QueryRequestImpl(query));
assertEquals(list.size(), sourceResponse.getResults().size());
int ascii = 65;
for (int i = 0; i < list.size(); i++) {
Result r = sourceResponse.getResults().get(i);
assertEquals((char) (i + ascii) + " Record ", r.getMetacard().getTitle());
}
// Sort all Textual DESCENDING
query.setSortBy(new ddf.catalog.filter.impl.SortByImpl(Metacard.TITLE, SortOrder.DESCENDING.name()));
sourceResponse = provider.query(new QueryRequestImpl(query));
assertEquals(list.size(), sourceResponse.getResults().size());
int asciiE = 69;
for (int i = (list.size() - 1); i >= 0; i--) {
Result r = sourceResponse.getResults().get(i);
assertEquals((char) (asciiE - i) + " Record ", r.getMetacard().getTitle());
}
}
use of ddf.catalog.operation.impl.QueryImpl in project ddf by codice.
the class SolrProviderTest method queryXpathWithPhrase.
private SourceResponse queryXpathWithPhrase(String xpath, String searchPhrase, boolean isCaseSensitive) throws UnsupportedQueryException {
Filter filter;
if (isCaseSensitive) {
filter = filterBuilder.xpath(xpath).is().like().caseSensitiveText(searchPhrase);
} else {
filter = filterBuilder.xpath(xpath).is().like().text(searchPhrase);
}
SourceResponse sourceResponse = provider.query(new QueryRequestImpl(new QueryImpl(filter)));
return sourceResponse;
}
use of ddf.catalog.operation.impl.QueryImpl in project ddf by codice.
the class SolrProviderTest method testSpatialQueryWithCounterClockwiseRectangle.
@Test
public void testSpatialQueryWithCounterClockwiseRectangle() throws Exception {
deleteAllIn(provider);
MetacardImpl metacard = new MockMetacard(Library.getFlagstaffRecord());
metacard.setLocation(FLAGSTAFF_AIRPORT_POINT_WKT);
List<Metacard> list = Arrays.asList((Metacard) metacard);
/** CREATE **/
create(list);
/** POSITIVE **/
Filter filter = filterBuilder.attribute(Metacard.GEOGRAPHY).intersecting().wkt(COUNTERCLOCKWISE_ARIZONA_RECTANGLE_WKT);
SourceResponse sourceResponse = provider.query(new QueryRequestImpl(new QueryImpl(filter)));
assertEquals("Failed to find Flagstaff record.", 1, sourceResponse.getResults().size());
for (Result r : sourceResponse.getResults()) {
assertTrue("Wrong record, Flagstaff keyword was not found.", ALL_RESULTS != r.getMetacard().getMetadata().indexOf(FLAGSTAFF_QUERY_PHRASE));
}
}
Aggregations