public JsonResultSet getSimilarImages ( String imageId , double threshold ) { JsonResultSet similar = new JsonResultSet ( ) ; PostMethod queryMethod = null ; String response = null ; try { Part [ ] parts = { new StringPart ( "id" , imageId ) , new StringPart ( "threshold" , String . valueOf ( threshold ) ) } ; queryMethod = new PostMethod ( webServiceHost + "/rest/visual/query_id/" + collectionName ) ; queryMethod . setRequestEntity ( new MultipartRequestEntity ( parts , queryMethod . getParams ( ) ) ) ; int code = httpClient . executeMethod ( queryMethod ) ; if ( code == 200 ) { InputStream inputStream = queryMethod . getResponseBodyAsStream ( ) ; StringWriter writer = new StringWriter ( ) ; IOUtils . copy ( inputStream , writer ) ; response = writer . toString ( ) ; queryMethod . releaseConnection ( ) ; similar = parseResponse ( response ) ; } else { _logger . error ( "Http returned code: " + code ) ; } } catch ( Exception e ) { _logger . error ( "Exception for ID: " + imageId , e ) ; response = null ; } finally { if ( queryMethod != null ) { queryMethod . releaseConnection ( ) ; } } return similar ; }
Get similar images for a specific media item