Created
February 17, 2015 16:08
-
-
Save fbricon/66b4b317f90ba6b99772 to your computer and use it in GitHub Desktop.
Query http://dcp.jboss.org/ with groovy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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