Search in sources :

Example 1 with SearchAnalyzeResult

use of com.ibm.cloud.cloudant.v1.model.SearchAnalyzeResult 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);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) JsonObject(com.google.gson.JsonObject) SearchAnalyzeResult(com.ibm.cloud.cloudant.v1.model.SearchAnalyzeResult)

Example 2 with SearchAnalyzeResult

use of com.ibm.cloud.cloudant.v1.model.SearchAnalyzeResult in project cloudant-java-sdk by IBM.

the class SearchAnalyzeResultTest method testSearchAnalyzeResult.

@Test
public void testSearchAnalyzeResult() throws Throwable {
    SearchAnalyzeResult searchAnalyzeResultModel = new SearchAnalyzeResult();
    assertNull(searchAnalyzeResultModel.getTokens());
}
Also used : SearchAnalyzeResult(com.ibm.cloud.cloudant.v1.model.SearchAnalyzeResult) Test(org.testng.annotations.Test)

Example 3 with SearchAnalyzeResult

use of com.ibm.cloud.cloudant.v1.model.SearchAnalyzeResult 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);
}
Also used : PostSearchAnalyzeOptions(com.ibm.cloud.cloudant.v1.model.PostSearchAnalyzeOptions) RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) SearchAnalyzeResult(com.ibm.cloud.cloudant.v1.model.SearchAnalyzeResult) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

SearchAnalyzeResult (com.ibm.cloud.cloudant.v1.model.SearchAnalyzeResult)3 Test (org.testng.annotations.Test)2 JsonObject (com.google.gson.JsonObject)1 PostSearchAnalyzeOptions (com.ibm.cloud.cloudant.v1.model.PostSearchAnalyzeOptions)1 RequestBuilder (com.ibm.cloud.sdk.core.http.RequestBuilder)1 MockResponse (okhttp3.mockwebserver.MockResponse)1 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)1 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)1