use of com.ibm.cloud.cloudant.v1.model.PostSearchAnalyzeOptions in project cloudant-java-sdk by IBM.
the class Cloudant method postSearchAnalyze.
/**
* Query tokenization of sample text.
*
* Returns the results of analyzer tokenization of the provided sample text. This endpoint can be used for testing
* analyzer tokenization.
*
* @param postSearchAnalyzeOptions the {@link PostSearchAnalyzeOptions} containing the options for the call
* @return a {@link ServiceCall} with a result of type {@link SearchAnalyzeResult}
*/
public ServiceCall<SearchAnalyzeResult> postSearchAnalyze(PostSearchAnalyzeOptions postSearchAnalyzeOptions) {
com.ibm.cloud.sdk.core.util.Validator.notNull(postSearchAnalyzeOptions, "postSearchAnalyzeOptions cannot be null");
RequestBuilder builder = RequestBuilder.post(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/_search_analyze"));
Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("cloudant", "v1", "postSearchAnalyze");
for (Entry<String, String> header : sdkHeaders.entrySet()) {
builder.header(header.getKey(), header.getValue());
}
builder.header("Accept", "application/json");
final JsonObject contentJson = new JsonObject();
contentJson.addProperty("analyzer", postSearchAnalyzeOptions.analyzer());
contentJson.addProperty("text", postSearchAnalyzeOptions.text());
builder.bodyJson(contentJson);
ResponseConverter<SearchAnalyzeResult> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<SearchAnalyzeResult>() {
}.getType());
return createServiceCall(builder.build(), responseConverter);
}
use of com.ibm.cloud.cloudant.v1.model.PostSearchAnalyzeOptions in project cloudant-java-sdk by IBM.
the class PostSearchAnalyzeOptionsTest method testPostSearchAnalyzeOptions.
@Test
public void testPostSearchAnalyzeOptions() throws Throwable {
PostSearchAnalyzeOptions postSearchAnalyzeOptionsModel = new PostSearchAnalyzeOptions.Builder().analyzer("arabic").text("testString").build();
assertEquals(postSearchAnalyzeOptionsModel.analyzer(), "arabic");
assertEquals(postSearchAnalyzeOptionsModel.text(), "testString");
}
use of com.ibm.cloud.cloudant.v1.model.PostSearchAnalyzeOptions in project cloudant-java-sdk by IBM.
the class CloudantTest method testPostSearchAnalyzeWOptions.
@Test
public void testPostSearchAnalyzeWOptions() throws Throwable {
// Schedule some responses.
String mockResponseBody = "{\"tokens\": [\"tokens\"]}";
String postSearchAnalyzePath = "/_search_analyze";
server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
constructClientService();
// Construct an instance of the PostSearchAnalyzeOptions model
PostSearchAnalyzeOptions postSearchAnalyzeOptionsModel = new PostSearchAnalyzeOptions.Builder().analyzer("arabic").text("testString").build();
// Invoke operation with valid options model (positive test)
Response<SearchAnalyzeResult> response = cloudantService.postSearchAnalyze(postSearchAnalyzeOptionsModel).execute();
assertNotNull(response);
SearchAnalyzeResult responseObj = response.getResult();
assertNotNull(responseObj);
// Verify the contents of the request
RecordedRequest request = server.takeRequest();
assertNotNull(request);
assertEquals(request.getMethod(), "POST");
// Check query
Map<String, String> query = TestUtilities.parseQueryString(request);
assertNull(query);
// Check request path
String parsedPath = TestUtilities.parseReqPath(request);
assertEquals(parsedPath, postSearchAnalyzePath);
}
Aggregations