Search in sources :

Example 56 with QueryRequestImpl

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

Example 57 with QueryRequestImpl

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

Example 58 with QueryRequestImpl

use of ddf.catalog.operation.impl.QueryRequestImpl in project ddf by codice.

the class SolrProviderTest method testSortedPointRadiusWithComplexQuery.

@Test
public void testSortedPointRadiusWithComplexQuery() throws Exception {
    deleteAllIn(provider);
    MetacardImpl metacard1 = new MockMetacard(Library.getFlagstaffRecord());
    MetacardImpl metacard2 = new MockMetacard(Library.getTampaRecord());
    MetacardImpl metacard3 = new MockMetacard(Library.getShowLowRecord());
    // Add in the geometry
    metacard1.setLocation(FLAGSTAFF_AIRPORT_POINT_WKT);
    metacard2.setLocation(TAMPA_AIRPORT_POINT_WKT);
    metacard3.setLocation(SHOW_LOW_AIRPORT_POINT_WKT);
    // Add in a content type
    metacard1.setAttribute(Metacard.CONTENT_TYPE, "product");
    List<Metacard> list = Arrays.asList((Metacard) metacard1, metacard2, metacard3);
    /** CREATE **/
    create(list);
    // create a filter that has spatial and content type criteria
    Filter contentFilter = filterBuilder.attribute(Metacard.CONTENT_TYPE).is().text("product");
    Filter spatialFilter = filterBuilder.attribute(Metacard.GEOGRAPHY).intersecting().wkt(FLAGSTAFF_AIRPORT_POINT_WKT);
    Filter finalFilter = filterBuilder.allOf(filterBuilder.attribute(Metacard.ANY_TEXT).like().text("flagstaff"), filterBuilder.allOf(contentFilter, spatialFilter));
    // sort by distance
    QueryImpl query = new QueryImpl(finalFilter);
    SortBy sortby = new ddf.catalog.filter.impl.SortByImpl(Result.DISTANCE, org.opengis.filter.sort.SortOrder.DESCENDING);
    query.setSortBy(sortby);
    SourceResponse sourceResponse = provider.query(new QueryRequestImpl(query));
    assertEquals(1, sourceResponse.getResults().size());
}
Also used : Metacard(ddf.catalog.data.Metacard) QueryImpl(ddf.catalog.operation.impl.QueryImpl) SourceResponse(ddf.catalog.operation.SourceResponse) Filter(org.opengis.filter.Filter) SortByImpl(org.geotools.filter.SortByImpl) SortBy(org.opengis.filter.sort.SortBy) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Test(org.junit.Test)

Example 59 with QueryRequestImpl

use of ddf.catalog.operation.impl.QueryRequestImpl in project ddf by codice.

the class SolrProviderTest method testSpatialCreateAndUpdateWithClockwiseRectangle.

@Test
public void testSpatialCreateAndUpdateWithClockwiseRectangle() throws Exception {
    deleteAllIn(provider);
    /** CREATE **/
    MockMetacard metacard = new MockMetacard(Library.getFlagstaffRecord());
    metacard.setLocation(CLOCKWISE_ARIZONA_RECTANGLE_WKT);
    CreateResponse createResponse = create(Arrays.asList((Metacard) metacard));
    assertEquals(1, createResponse.getCreatedMetacards().size());
    Filter filter = filterBuilder.attribute(Metacard.GEOGRAPHY).intersecting().wkt(FLAGSTAFF_AIRPORT_POINT_WKT);
    SourceResponse sourceResponse = provider.query(new QueryRequestImpl(new QueryImpl(filter)));
    assertEquals("Failed to find correct record.", 1, sourceResponse.getResults().size());
    /** UPDATE **/
    MockMetacard updatedMetacard = new MockMetacard(Library.getTampaRecord());
    updatedMetacard.setLocation(CLOCKWISE_ARIZONA_RECTANGLE_WKT);
    String[] ids = { metacard.getId() };
    UpdateResponse updateResponse = update(ids, Arrays.asList((Metacard) updatedMetacard));
    assertEquals(1, updateResponse.getUpdatedMetacards().size());
    filter = filterBuilder.attribute(Metacard.GEOGRAPHY).intersecting().wkt(FLAGSTAFF_AIRPORT_POINT_WKT);
    sourceResponse = provider.query(new QueryRequestImpl(new QueryImpl(filter)));
    assertEquals("Failed to find correct record.", 1, sourceResponse.getResults().size());
}
Also used : UpdateResponse(ddf.catalog.operation.UpdateResponse) Metacard(ddf.catalog.data.Metacard) QueryImpl(ddf.catalog.operation.impl.QueryImpl) SourceResponse(ddf.catalog.operation.SourceResponse) Filter(org.opengis.filter.Filter) CreateResponse(ddf.catalog.operation.CreateResponse) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Example 60 with QueryRequestImpl

use of ddf.catalog.operation.impl.QueryRequestImpl in project ddf by codice.

the class SolrProviderTest method assertNotFilter.

private void assertNotFilter(Filter filter) throws UnsupportedQueryException {
    SourceResponse sourceResponse = provider.query(new QueryRequestImpl(new QueryImpl(filter)));
    assertEquals("Found a metacard and should not have.", 0, sourceResponse.getResults().size());
}
Also used : QueryImpl(ddf.catalog.operation.impl.QueryImpl) SourceResponse(ddf.catalog.operation.SourceResponse) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl)

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