Search in sources :

Example 81 with Metacard

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();
    }
}
Also used : SourceResponse(ddf.catalog.operation.SourceResponse) ArrayList(java.util.ArrayList) DateTime(org.joda.time.DateTime) Result(ddf.catalog.data.Result) Metacard(ddf.catalog.data.Metacard) QueryImpl(ddf.catalog.operation.impl.QueryImpl) Filter(org.opengis.filter.Filter) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) Test(org.junit.Test)

Example 82 with Metacard

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());
}
Also used : Metacard(ddf.catalog.data.Metacard) QueryImpl(ddf.catalog.operation.impl.QueryImpl) SourceResponse(ddf.catalog.operation.SourceResponse) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) MetacardImpl(ddf.catalog.data.impl.MetacardImpl)

Example 83 with Metacard

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));
}
Also used : Metacard(ddf.catalog.data.Metacard) ArrayList(java.util.ArrayList) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Example 84 with Metacard

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)));
}
Also used : ContentTypeImpl(ddf.catalog.data.impl.ContentTypeImpl) Metacard(ddf.catalog.data.Metacard) ContentType(ddf.catalog.data.ContentType) Test(org.junit.Test)

Example 85 with Metacard

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());
}
Also used : Metacard(ddf.catalog.data.Metacard) QueryImpl(ddf.catalog.operation.impl.QueryImpl) SourceResponse(ddf.catalog.operation.SourceResponse) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) Test(org.junit.Test)

Aggregations

Metacard (ddf.catalog.data.Metacard)746 Test (org.junit.Test)470 ArrayList (java.util.ArrayList)206 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)149 InputStream (java.io.InputStream)136 HashMap (java.util.HashMap)129 AttributeImpl (ddf.catalog.data.impl.AttributeImpl)115 Result (ddf.catalog.data.Result)109 Serializable (java.io.Serializable)100 QueryRequestImpl (ddf.catalog.operation.impl.QueryRequestImpl)90 QueryRequest (ddf.catalog.operation.QueryRequest)84 QueryImpl (ddf.catalog.operation.impl.QueryImpl)80 QueryResponse (ddf.catalog.operation.QueryResponse)78 SourceResponse (ddf.catalog.operation.SourceResponse)76 IOException (java.io.IOException)75 List (java.util.List)74 Map (java.util.Map)67 Filter (org.opengis.filter.Filter)67 CreateResponse (ddf.catalog.operation.CreateResponse)66 HashSet (java.util.HashSet)65