Search in sources :

Example 36 with QueryRequestImpl

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

the class CatalogMetricsTest method catalogFuzzyQueryMetric.

@Test
public void catalogFuzzyQueryMetric() throws Exception {
    Filter fuzzyFilter = filterBuilder.attribute(Metacard.ANY_TEXT).like().fuzzyText("fuzzy");
    QueryRequest query = new QueryRequestImpl(new QueryImpl(fuzzyFilter));
    underTest.process(query);
    assertThat(underTest.fuzzyQueries.getCount(), is(1L));
}
Also used : QueryImpl(ddf.catalog.operation.impl.QueryImpl) QueryRequest(ddf.catalog.operation.QueryRequest) Filter(org.opengis.filter.Filter) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) Test(org.junit.Test)

Example 37 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 38 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 39 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 40 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)

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