use of ddf.catalog.operation.impl.QueryRequestImpl in project ddf by codice.
the class SolrProviderTest method testQueryMissingSortFieldTemporal.
/**
* Testing if the temporal search does not fail when no schema field can be found and/or there
* is no data in the index
*
* @throws IngestException
* @throws UnsupportedQueryException
*/
@Test
public void testQueryMissingSortFieldTemporal() throws IngestException, UnsupportedQueryException {
/*
* I have tested this with an empty schema and without an empty schema - both pass, but
* there is no regression test for the empty schema scenario TODO there should probably be
* an automated test that creates a fresh cache, that would be a better test
*/
deleteAllIn(provider);
Filter txtFilter = filterBuilder.attribute("id").like().text("*");
QueryImpl query = new QueryImpl(txtFilter);
query.setSortBy(new ddf.catalog.filter.impl.SortByImpl(Result.TEMPORAL, SortOrder.ASCENDING));
SourceResponse response = provider.query(new QueryRequestImpl(query));
assertEquals(0, response.getResults().size());
}
use of ddf.catalog.operation.impl.QueryRequestImpl in project ddf by codice.
the class SolrProviderTest method testSorting.
@Test
public void testSorting() throws Exception {
deleteAllIn(provider);
List<Metacard> list = new ArrayList<Metacard>();
DateTime now = new DateTime();
for (int i = 0; i < 5; i++) {
MockMetacard m = new MockMetacard(Library.getFlagstaffRecord());
m.setEffectiveDate(now.minus(5L * i).toDate());
m.setTitle("Record " + i);
list.add(m);
}
create(list);
Filter filter = null;
QueryImpl query = null;
SourceResponse sourceResponse = null;
// Sort all TEMPORAL DESC
filter = filterBuilder.attribute(Metacard.EFFECTIVE).before().date(now.plusMillis(1).toDate());
query = new QueryImpl(filter);
query.setSortBy(new ddf.catalog.filter.impl.SortByImpl(Metacard.EFFECTIVE, SortOrder.DESCENDING.name()));
sourceResponse = provider.query(new QueryRequestImpl(query));
assertEquals(list.size(), sourceResponse.getResults().size());
for (int i = 0; i < list.size(); i++) {
Result r = sourceResponse.getResults().get(i);
assertEquals("Record " + i, r.getMetacard().getTitle());
}
// Sort all TEMPORAL ASC
query.setSortBy(new ddf.catalog.filter.impl.SortByImpl(Metacard.EFFECTIVE, SortOrder.ASCENDING.name()));
sourceResponse = provider.query(new QueryRequestImpl(query));
assertEquals(list.size(), sourceResponse.getResults().size());
int index = 0;
for (int i = (list.size() - 1); i >= 0; i--) {
Result r = sourceResponse.getResults().get(index);
assertEquals("Record " + i, r.getMetacard().getTitle());
index++;
}
// Sort all Relevancy score DESC
filter = filterBuilder.attribute(Metacard.METADATA).like().text(FLAGSTAFF_QUERY_PHRASE);
query = new QueryImpl(filter);
query.setSortBy(new ddf.catalog.filter.impl.SortByImpl(Result.RELEVANCE, SortOrder.DESCENDING.name()));
sourceResponse = provider.query(new QueryRequestImpl(query));
assertEquals(list.size(), sourceResponse.getResults().size());
double currentScore = Integer.MAX_VALUE;
for (Result r : sourceResponse.getResults()) {
assertThat(currentScore, greaterThanOrEqualTo(r.getRelevanceScore()));
currentScore = r.getRelevanceScore();
}
// Sort all Relevancy score DESC
filter = filterBuilder.attribute(Metacard.METADATA).like().text(FLAGSTAFF_QUERY_PHRASE);
query = new QueryImpl(filter);
query.setSortBy(new ddf.catalog.filter.impl.SortByImpl(Result.RELEVANCE, SortOrder.ASCENDING.name()));
sourceResponse = provider.query(new QueryRequestImpl(query));
assertEquals(list.size(), sourceResponse.getResults().size());
currentScore = 0;
for (Result r : sourceResponse.getResults()) {
assertThat(currentScore, lessThanOrEqualTo(r.getRelevanceScore()));
currentScore = r.getRelevanceScore();
}
}
use of ddf.catalog.operation.impl.QueryRequestImpl 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.QueryRequestImpl 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.QueryRequestImpl 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());
}
}
Aggregations