Skip to content

Instantly share code, notes, and snippets.

@fbricon
Created February 17, 2015 16:08
Show Gist options
  • Save fbricon/66b4b317f90ba6b99772 to your computer and use it in GitHub Desktop.
Save fbricon/66b4b317f90ba6b99772 to your computer and use it in GitHub Desktop.
Query http://dcp.jboss.org/ with groovy
// this adds a "truncate(#)" method to String
// see http://www.vertigrated.com/blog/2009/11/how-to-add-a-truncateint-len-method-to-stringgstring-in-groovy/
String.metaClass.truncate = { len ->
if (delegate == null) {return''}
if (delegate.length() > len) {return delegate[0..(len - 2)] + "\u2026"}
return delegate
}
def query= "hibernate"
int size = 20
def searchUrl = "http://dcp.jboss.org/v1/rest/search?query=${query}&size=${size}".toURL()
def result = new groovy.json.JsonSlurper().parse searchUrl
result.hits.hits.each {
println "${it.fields.sys_url_view} : ${it.fields.sys_description.truncate(50)}"
}
"Found ${result.hits.total} hits"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment