Search in sources :

Example 51 with QueryRequestImpl

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

Example 52 with QueryRequestImpl

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();
    }
}
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 53 with QueryRequestImpl

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());
}
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 54 with QueryRequestImpl

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());
}
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)

Example 55 with QueryRequestImpl

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());
    }
}
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)

Aggregations

QueryRequestImpl (ddf.catalog.operation.impl.QueryRequestImpl)216 QueryImpl (ddf.catalog.operation.impl.QueryImpl)187 Test (org.junit.Test)142 Filter (org.opengis.filter.Filter)103 SourceResponse (ddf.catalog.operation.SourceResponse)100 QueryRequest (ddf.catalog.operation.QueryRequest)86 Metacard (ddf.catalog.data.Metacard)72 Result (ddf.catalog.data.Result)60 QueryResponse (ddf.catalog.operation.QueryResponse)46 ArrayList (java.util.ArrayList)46 UnsupportedQueryException (ddf.catalog.source.UnsupportedQueryException)32 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)29 Query (ddf.catalog.operation.Query)28 HashMap (java.util.HashMap)28 FederationException (ddf.catalog.federation.FederationException)27 Serializable (java.io.Serializable)27 Matchers.containsString (org.hamcrest.Matchers.containsString)22 Matchers.anyString (org.mockito.Matchers.anyString)20 SortByImpl (ddf.catalog.filter.impl.SortByImpl)19 SourceUnavailableException (ddf.catalog.source.SourceUnavailableException)18