【发布时间】:2017-10-13 01:58:13
【问题描述】:
目前我正在创建一个需要调用 Azure 搜索 API 的应用程序。
这里是 API: https://serviceName.search.windows.net/indexes/global-index/docs/search?api-version=2016-09-01
这是我的 Java 代码:
@Override
public JSONObject global(SearchParametersDto searchInTableDto) {
JSONObject jsonOutput = new JSONObject();
ArrayList encodedURLList = new ArrayList < > ();
try {
String url = "https://" + searchInTableDto.getServiceName().toString() + ".search.windows.net/indexes/" +
searchInTableDto.getIndexName().toString() + "/docs/search?api-version=2016-09-01";
HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost(url);
post.setHeader("Content-Type", "application/json");
post.setHeader("api-key", searchInTableDto.getApiKey().toString());
String clientId = searchInTableDto.getClientId().toString();
String updatedClientId = " \"+" + clientId + "\" ";
JSONObject jsonInput = new JSONObject();
jsonInput.put("search", "(test||test||test||test||test||test||test)+ Contacts+Campaigns+Companies+Targets+Complanits+Claims+Activities+Opportunities+Completed Activities");
//jsonInput.put("top", 1000);
System.out.println(jsonInput);
post.setEntity(new StringEntity(jsonInput.toString(), ContentType.create("application/json")));
HttpResponse response = client.execute(post);
BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
StringBuffer resultOutput = new StringBuffer();
String line = "";
while ((line = rd.readLine()) != null) {
resultOutput.append(line);
}
JSONParser parser = new JSONParser();
jsonOutput = (JSONObject) parser.parse(resultOutput.toString());
org.json.simple.JSONArray valuesArray = (org.json.simple.JSONArray) jsonOutput.get("value");
//jsonOutput.put("searchResult", valuesArray);
System.out.println(valuesArray.size());
} catch (Exception e) {
e.printStackTrace();
String errorMessageAndClassWithMethod = getErrorContainingClassAndMethod();
throw new SpringAppRuntimeException(errorMessageAndClassWithMethod + e.toString());
}
return jsonOutput;
}
当我在 Azure 搜索中运行搜索查询时,我会获得下一个结果的链接,例如:"@odata.nextLink": "https://serviceName.search.windows.net/indexes('global-index')/docs?api-version=2015-02-28-Preview&search=%28test%7C%7Ctest%7C%7Ctest%7C%7Ctest%7C%7Ctest%7C%7Ctest%7C%7Ctest%29%2B%20Contacts%2BCampaigns%2BCompanies%2BTargets%2BComplanits%2BClaims%2BActivities%2BOpportunities%2BCompleted%20Activities&$skip=50"
但是,当我通过我的 Java 服务运行相同的查询时,我会得到下一个文档的以下链接:
"@odata.nextLink": "https://serviceName.search.windows.net/indexes('global-index')/docs/search.post.search?api-version=2016-09-01"
通过第二个链接,我无法获取下一个文档。为什么 JSON 对象中的链接与实际需要的链接不同?
还有一点, 当我通过我的代码设置“top”条件时,结果永远不会返回我下一个文档的链接。这可能是什么原因?
如何获得正确的链接以查看 JSON 输出中的下一个文档?
【问题讨论】:
标签: azure azure-cognitive-search