Search in sources :

Example 16 with QueryRequestImpl

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

the class CatalogMetricsTest method catalogResultCountMetric.

@Test
public void catalogResultCountMetric() throws Exception {
    QueryRequest query = new QueryRequestImpl(new QueryImpl(idFilter));
    QueryResponse response = new QueryResponseImpl(query, new ArrayList(), 50);
    underTest.process(response);
    assertThat(underTest.resultCount.getCount(), is(1L));
    assertThat(underTest.resultCount.getSnapshot().getMean(), is(50.0));
}
Also used : QueryImpl(ddf.catalog.operation.impl.QueryImpl) QueryResponseImpl(ddf.catalog.operation.impl.QueryResponseImpl) QueryRequest(ddf.catalog.operation.QueryRequest) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) QueryResponse(ddf.catalog.operation.QueryResponse) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 17 with QueryRequestImpl

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

the class CatalogMetricsTest method catalogFederatedQueryMetricForLocalQueries.

@Test
public void catalogFederatedQueryMetricForLocalQueries() throws Exception {
    QueryRequest query = new QueryRequestImpl(new QueryImpl(idFilter), Arrays.asList(""));
    underTest.process(query);
    query = new QueryRequestImpl(new QueryImpl(idFilter), Arrays.asList((String) null));
    underTest.process(query);
    System.setProperty(SystemInfo.SITE_NAME, "localSourceId");
    query = new QueryRequestImpl(new QueryImpl(idFilter), Arrays.asList("localSourceId"));
    underTest.process(query);
    assertThat(underTest.federatedQueries.getCount(), is(0L));
}
Also used : QueryImpl(ddf.catalog.operation.impl.QueryImpl) QueryRequest(ddf.catalog.operation.QueryRequest) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) Test(org.junit.Test)

Example 18 with QueryRequestImpl

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

the class SolrProviderTest method testQueryHasLuceneSpecialCharacters.

@Test
public void testQueryHasLuceneSpecialCharacters() throws Exception {
    deleteAllIn(provider);
    List<Metacard> list = Arrays.asList((Metacard) new MockMetacard(Library.getFlagstaffRecord()), new MockMetacard(Library.getTampaRecord()));
    create(list);
    // if + is escaped, this query will be an implicit OR otherwise both both terms would be
    // required
    Filter txtFilter = filterBuilder.attribute(Metacard.ANY_TEXT).like().text("+Flag?taff +" + TAMPA_QUERY_PHRASE);
    SourceResponse response = provider.query(new QueryRequestImpl(new QueryImpl(txtFilter)));
    assertEquals(1, response.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) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) Test(org.junit.Test)

Example 19 with QueryRequestImpl

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

the class SolrProviderTest method testXpathCompoundContextualQuery.

@Test
public void testXpathCompoundContextualQuery() throws Exception {
    ConfigurationStore.getInstance().setDisableTextPath(false);
    deleteAllIn(provider);
    String nonexistentXpath = "/this/xpath[does/not/@ex:exist]";
    MockMetacard tampa = new MockMetacard(Library.getTampaRecord());
    tampa.setTitle("Tampa");
    tampa.setLocation(TAMPA_AIRPORT_POINT_WKT);
    MockMetacard flagstaff = new MockMetacard(Library.getFlagstaffRecord());
    flagstaff.setLocation(FLAGSTAFF_AIRPORT_POINT_WKT);
    create(Arrays.asList((Metacard) tampa, flagstaff));
    /* XPath AND temporal AND spatial. */
    Filter filter = filterBuilder.allOf(filterBuilder.xpath("/rss/channel[item/link]").exists(), filterBuilder.attribute(Metacard.MODIFIED).before().date(new DateTime().plus(1).toDate()), filterBuilder.attribute(Metacard.GEOGRAPHY).intersecting().wkt(FLAGSTAFF_AIRPORT_POINT_WKT));
    SourceResponse sourceResponse = provider.query(new QueryRequestImpl(new QueryImpl(filter)));
    assertEquals("XPath AND temporal AND spatial", ONE_HIT, sourceResponse.getResults().size());
    /* temporal AND (Bad XPath OR XPath) */
    filter = filterBuilder.allOf(filterBuilder.attribute(Metacard.MODIFIED).before().date(new DateTime().plus(1).toDate()), filterBuilder.anyOf(filterBuilder.xpath(nonexistentXpath).exists(), filterBuilder.xpath("//channel/image/title").is().like().text(FLAGSTAFF_QUERY_PHRASE)));
    sourceResponse = provider.query(new QueryRequestImpl(new QueryImpl(filter)));
    assertEquals("temporal AND (Bad XPath OR XPath)", ONE_HIT, sourceResponse.getResults().size());
    /* Bad XPath OR (spatial AND XPath) */
    filter = filterBuilder.anyOf(filterBuilder.xpath(nonexistentXpath).is().like().text("any phrase"), filterBuilder.allOf(filterBuilder.attribute(Metacard.GEOGRAPHY).intersecting().wkt(TAMPA_AIRPORT_POINT_WKT), filterBuilder.xpath("/rss//item/enclosure/@url").exists()));
    sourceResponse = provider.query(new QueryRequestImpl(new QueryImpl(filter)));
    assertEquals("Bad XPath OR (spatial AND XPath)", ONE_HIT, sourceResponse.getResults().size());
    assertEquals("Tampa", sourceResponse.getResults().get(0).getMetacard().getTitle());
    /* spatial AND (Bad XPath OR Bad XPath) */
    filter = filterBuilder.allOf(filterBuilder.attribute(Metacard.GEOGRAPHY).intersecting().wkt(FLAGSTAFF_AIRPORT_POINT_WKT), filterBuilder.anyOf(filterBuilder.xpath(nonexistentXpath).exists(), filterBuilder.xpath("//also/does/not[@exist]").is().like().text(FLAGSTAFF_QUERY_PHRASE)));
    sourceResponse = provider.query(new QueryRequestImpl(new QueryImpl(filter)));
    assertEquals("spatial AND (Bad XPath OR Bad XPath)", 0, 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) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) Matchers.containsString(org.hamcrest.Matchers.containsString) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 20 with QueryRequestImpl

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

the class SolrProviderTest method testDeleteAlternativeAttribute.

/**
     * Testing if another attribute can be used to delete records other than {@link Metacard#ID}
     *
     * @throws IngestException
     * @throws UnsupportedQueryException
     */
@Test
public void testDeleteAlternativeAttribute() throws IngestException, UnsupportedQueryException {
    deleteAllIn(provider);
    MockMetacard metacard = new MockMetacard(Library.getFlagstaffRecord());
    CreateResponse createResponse = create(metacard);
    DeleteResponse deleteResponse = provider.delete(new DeleteRequest() {

        @Override
        public boolean hasProperties() {
            return false;
        }

        @Override
        public Serializable getPropertyValue(String name) {
            return null;
        }

        @Override
        public Set<String> getPropertyNames() {
            return null;
        }

        @Override
        public Map<String, Serializable> getProperties() {
            return null;
        }

        @Override
        public boolean containsPropertyName(String name) {
            return false;
        }

        @Override
        public List<? extends Serializable> getAttributeValues() {
            return Arrays.asList(MockMetacard.DEFAULT_TITLE);
        }

        @Override
        public String getAttributeName() {
            return Metacard.TITLE;
        }
    });
    Metacard deletedMetacard = deleteResponse.getDeletedMetacards().get(0);
    verifyDeletedRecord(metacard, createResponse, deleteResponse, deletedMetacard);
    // verify it is really not in SOLR
    Filter filter = filterBuilder.attribute(Metacard.TITLE).like().text(MockMetacard.DEFAULT_TITLE);
    QueryImpl query = new QueryImpl(filter);
    SourceResponse sourceResponse = provider.query(new QueryRequestImpl(query));
    List<Result> results = sourceResponse.getResults();
    assertEquals(0, results.size());
}
Also used : Serializable(java.io.Serializable) Set(java.util.Set) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) SourceResponse(ddf.catalog.operation.SourceResponse) CreateResponse(ddf.catalog.operation.CreateResponse) Matchers.containsString(org.hamcrest.Matchers.containsString) Result(ddf.catalog.data.Result) Metacard(ddf.catalog.data.Metacard) QueryImpl(ddf.catalog.operation.impl.QueryImpl) DeleteResponse(ddf.catalog.operation.DeleteResponse) Filter(org.opengis.filter.Filter) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) DeleteRequest(ddf.catalog.operation.DeleteRequest) Map(java.util.Map) 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