0

I am trying to perform a retrieveAndRank query using Java wrapper. I follow the online javadocs for Retrieve and Rank API. The example there for SearchAndRank is:

https://www.ibm.com/watson/developercloud/retrieve-and-rank/api/v1/#query_ranker

RetrieveAndRank service = new RetrieveAndRank();
service.setUsernameAndPassword("{username}","{password}");
HttpSolrClient solrClient = new HttpSolrClient;
solrClient = getSolrClient(service.getSolrUrl("scfaaf8903_02c1_4297_84c6_76b79537d849"), "{username}","{password}");
SolrQuery query = new SolrQuery("what is the basic mechanism of the transonic aileron buzz");
QueryResponse response = solrClient.query("example_collection", query);
Ranking ranking = service.rank("B2E325-rank-67", response);
System.out.println(ranking);

but RetrieveAndRank class has no such rank(String rankerId, QueryResponse response) method. Just one getting a file or an InputStream as arguments (browsing IBM’s source code I see it expects CSV content not a java QueryResponse there).

How should I pass QueryResponse to the rank method?

I am using solr-solrj-5.5.2.jar and java-sdk-3.2.0-jar-with-dependencies.jar libraries

icordoba
  • 1,834
  • 2
  • 33
  • 60

1 Answers1

1

You need to use the /fcselect query handler and send the ranker_id as a parameter.

The code below assumes you have a Solr collection with documents and you have trained a ranker, otherwise follow this tutorial.

 RetrieveAndRank service = new RetrieveAndRank();
 service.setUsernameAndPassword(USERNAME, PASSWORD);

 // create the solr client
 String solrUrl = service.getSolrUrl(SOLR_CLUSTER_ID);
 HttpClient client = createHttpClient(solrUrl, USERNAME, PASSWORD);
 HttpSolrClient solrClient = new HttpSolrClient(solrUrl, client);

 // build the query
 SolrQuery query = new SolrQuery("*:*");
 query.setRequestHandler("/fcselect");
 query.set("ranker_id", RANKER_ID);

 // execute the query
 QueryResponse response = solrClient.query(SOLR_COLLECTION_NAME, query);
 System.out.println("Found " + response.getResults().size() + " documents!");
 System.out.println(response);

Make sure you update the service credentials for RetrieveAndRank(USERNAME and PASSWORD), SOLR_CLUSTER_ID, SOLR_COLLECTION_NAME and RANKER_ID. The code for createHttpClient() can be found here.

German Attanasio
  • 22,217
  • 7
  • 47
  • 63