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