use of ddf.catalog.data.Metacard 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.data.Metacard 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.data.Metacard in project ddf by codice.
the class SolrProviderTest method testContextualXmlAttributes.
/**
* Testing attributes are properly indexed.
*
* @throws Exception
*/
@Test
public void testContextualXmlAttributes() throws Exception {
deleteAllIn(provider);
List<Metacard> list = new ArrayList<Metacard>();
String soughtWord = "self";
MockMetacard metacard1 = new MockMetacard(Library.getFlagstaffRecord());
list.add(metacard1);
create(list);
queryAndVerifyCount(1, filterBuilder.attribute(Metacard.METADATA).is().like().text(soughtWord));
}
use of ddf.catalog.data.Metacard in project ddf by codice.
the class SolrProviderTest method testGetContentTypesVersionsAndNullVersions.
@Test
public void testGetContentTypesVersionsAndNullVersions() throws Exception {
deleteAllIn(provider);
MockMetacard metacard1 = new MockMetacard(Library.getFlagstaffRecord());
MockMetacard metacard2 = new MockMetacard(Library.getShowLowRecord());
MockMetacard metacard3 = new MockMetacard(Library.getTampaRecord());
metacard1.setContentTypeName(SAMPLE_CONTENT_TYPE_1);
metacard1.setContentTypeVersion(null);
metacard2.setContentTypeName(SAMPLE_CONTENT_TYPE_2);
metacard3.setContentTypeName(SAMPLE_CONTENT_TYPE_2);
metacard3.setContentTypeVersion(SAMPLE_CONTENT_VERSION_3);
List<Metacard> list = Arrays.asList((Metacard) metacard1, metacard2, metacard3);
create(list);
Set<ContentType> contentTypes = provider.getContentTypes();
assertEquals(3, contentTypes.size());
assertThat(contentTypes, hasItem((ContentType) new ContentTypeImpl(SAMPLE_CONTENT_TYPE_1, null)));
assertThat(contentTypes, hasItem((ContentType) new ContentTypeImpl(SAMPLE_CONTENT_TYPE_2, MockMetacard.DEFAULT_VERSION)));
assertThat(contentTypes, hasItem((ContentType) new ContentTypeImpl(SAMPLE_CONTENT_TYPE_2, SAMPLE_CONTENT_VERSION_3)));
}
use of ddf.catalog.data.Metacard 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());
}
Aggregations