Search in sources :

Example 1 with LikeFilterImpl

use of org.geotools.filter.LikeFilterImpl in project ddf by codice.

the class TwitterFilterVisitor method visit.

/**
     * PropertyIsLike filter maps to a Contextual search criteria.
     */
@Override
public Object visit(PropertyIsLike filter, Object data) {
    LOGGER.trace("ENTERING: PropertyIsLike filter");
    if (currentNest != NestedTypes.NOT) {
        LikeFilterImpl likeFilter = (LikeFilterImpl) filter;
        AttributeExpressionImpl expression = (AttributeExpressionImpl) likeFilter.getExpression();
        String selectors = expression.getPropertyName();
        LOGGER.debug("selectors = {}", selectors);
        String searchPhrase = likeFilter.getLiteral();
        LOGGER.debug("searchPhrase = [{}]", searchPhrase);
        if (contextualSearch != null) {
            contextualSearch.setSearchPhrase(contextualSearch.getSearchPhrase() + " " + currentNest.toString() + " " + searchPhrase);
        } else {
            contextualSearch = new ContextualSearch(selectors, searchPhrase, likeFilter.isMatchingCase());
        }
    }
    LOGGER.trace("EXITING: PropertyIsLike filter");
    return super.visit(filter, data);
}
Also used : LikeFilterImpl(org.geotools.filter.LikeFilterImpl) AttributeExpressionImpl(org.geotools.filter.AttributeExpressionImpl)

Example 2 with LikeFilterImpl

use of org.geotools.filter.LikeFilterImpl in project ddf by codice.

the class OpenSearchQueryTest method testContextualFilterPhraseOnly.

@Test
public void testContextualFilterPhraseOnly() throws Exception {
    String searchTerm = "cat";
    String selector = null;
    OpenSearchQuery query = new OpenSearchQuery(null, 0, 10, "relevance", "desc", 30000, FILTER_BUILDER);
    query.addContextualFilter(searchTerm, selector);
    Filter filter = query.getFilter();
    // String filterXml = getFilterAsXml( filter );
    VerificationVisitor verificationVisitor = new VerificationVisitor();
    filter.accept(verificationVisitor, null);
    HashMap<String, FilterStatus> map = (HashMap<String, FilterStatus>) verificationVisitor.getMap();
    printFilterStatusMap(map);
    List<Filter> filters = getFilters(map, LikeFilterImpl.class.getName());
    assertEquals(1, filters.size());
    LikeFilterImpl likeFilter = (LikeFilterImpl) filters.get(0);
    String extractedSearchTerm = likeFilter.getLiteral();
    LOGGER.debug("extractedSearchTerm = [{}]", extractedSearchTerm);
    assertEquals(searchTerm, extractedSearchTerm);
}
Also used : LikeFilterImpl(org.geotools.filter.LikeFilterImpl) TemporalFilter(ddf.catalog.impl.filter.TemporalFilter) BBoxSpatialFilter(org.codice.ddf.opensearch.query.filter.BBoxSpatialFilter) PolygonSpatialFilter(org.codice.ddf.opensearch.query.filter.PolygonSpatialFilter) Filter(org.opengis.filter.Filter) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 3 with LikeFilterImpl

use of org.geotools.filter.LikeFilterImpl in project ddf by codice.

the class OpenSearchQueryTest method verifyContextualFilter.

// private Document getDocument( String xml ) throws Exception
// {
// DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
// factory.setNamespaceAware( true );
// DocumentBuilder builder = factory.newDocumentBuilder();
// StringReader reader = new StringReader( xml );
// InputSource inputSource = new InputSource( reader );
// Document doc = builder.parse( inputSource );
// reader.close();
//
// return doc;
// }
// private String getFilterAsXml( Filter filter ) throws Exception
// {
// FilterTransformer transform = new FilterTransformer();
// transform.setIndentation( 2 );
// String filterXml = transform.transform( filter );
// LOGGER.debug( filterXml );
//
// return filterXml;
// }
private void verifyContextualFilter(Filter filter, String expectedPropertyName, String expectedSearchTerm) throws Exception {
    LikeFilterImpl likeFilter = (LikeFilterImpl) filter;
    AttributeExpressionImpl expression = (AttributeExpressionImpl) likeFilter.getExpression();
    LOGGER.debug("propertyName = {}", expression.getPropertyName());
    assertEquals(expectedPropertyName, expression.getPropertyName());
    String extractedSearchTerm = likeFilter.getLiteral();
    LOGGER.debug("extractedSearchTerm = [{}]", extractedSearchTerm);
    assertEquals(expectedSearchTerm, extractedSearchTerm);
}
Also used : LikeFilterImpl(org.geotools.filter.LikeFilterImpl) AttributeExpressionImpl(org.geotools.filter.AttributeExpressionImpl)

Example 4 with LikeFilterImpl

use of org.geotools.filter.LikeFilterImpl in project ddf by codice.

the class OpenSearchQueryTest method verifyLikeFilter.

private void verifyLikeFilter(Filter filter, String expectedPropertyName, String expectedValue) {
    assertTrue(filter instanceof LikeFilterImpl);
    LikeFilterImpl likeFilter = (LikeFilterImpl) filter;
    AttributeExpressionImpl expression = (AttributeExpressionImpl) likeFilter.getExpression();
    LOGGER.debug("propertyName = {}", expression.getPropertyName());
    assertEquals(expectedPropertyName, expression.getPropertyName());
    String pattern = likeFilter.getLiteral();
    LOGGER.debug("value to search for = {}", pattern);
    assertEquals(expectedValue, pattern);
}
Also used : LikeFilterImpl(org.geotools.filter.LikeFilterImpl) AttributeExpressionImpl(org.geotools.filter.AttributeExpressionImpl)

Example 5 with LikeFilterImpl

use of org.geotools.filter.LikeFilterImpl in project ddf by codice.

the class OpenSearchFilterVisitor method visit.

/**
     * PropertyIsLike filter maps to a Contextual search criteria.
     */
@Override
public Object visit(PropertyIsLike filter, Object data) {
    LOGGER.trace("ENTERING: PropertyIsLike filter");
    if (currentNest != NestedTypes.NOT) {
        LikeFilterImpl likeFilter = (LikeFilterImpl) filter;
        AttributeExpressionImpl expression = (AttributeExpressionImpl) likeFilter.getExpression();
        String selectors = expression.getPropertyName();
        LOGGER.debug("selectors = {}", selectors);
        String searchPhrase = likeFilter.getLiteral();
        LOGGER.debug("searchPhrase = [{}]", searchPhrase);
        if (contextualSearch != null) {
            contextualSearch.setSearchPhrase(contextualSearch.getSearchPhrase() + " " + currentNest.toString() + " " + searchPhrase);
        } else {
            contextualSearch = new ContextualSearch(selectors, searchPhrase, likeFilter.isMatchingCase());
        }
    }
    LOGGER.trace("EXITING: PropertyIsLike filter");
    return super.visit(filter, data);
}
Also used : LikeFilterImpl(org.geotools.filter.LikeFilterImpl) AttributeExpressionImpl(org.geotools.filter.AttributeExpressionImpl)

Aggregations

LikeFilterImpl (org.geotools.filter.LikeFilterImpl)6 AttributeExpressionImpl (org.geotools.filter.AttributeExpressionImpl)5 FuzzyFunction (ddf.catalog.impl.filter.FuzzyFunction)1 TemporalFilter (ddf.catalog.impl.filter.TemporalFilter)1 ContentTypePredicate (ddf.catalog.pubsub.predicate.ContentTypePredicate)1 ContextualPredicate (ddf.catalog.pubsub.predicate.ContextualPredicate)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 BBoxSpatialFilter (org.codice.ddf.opensearch.query.filter.BBoxSpatialFilter)1 PolygonSpatialFilter (org.codice.ddf.opensearch.query.filter.PolygonSpatialFilter)1 Test (org.junit.Test)1 Filter (org.opengis.filter.Filter)1 Expression (org.opengis.filter.expression.Expression)1 PropertyName (org.opengis.filter.expression.PropertyName)1