Skip to content

Commit

Permalink
Merge pull request Azure#124 from navalev/feature/canSuggestWithDateT…
Browse files Browse the repository at this point in the history
…imeInStaticModel

Feature/can suggest with date time in static model
  • Loading branch information
itye-msft authored Oct 7, 2019
2 parents 3886bae + 99498f3 commit b01ea23
Show file tree
Hide file tree
Showing 4 changed files with 121 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,12 @@
import com.azure.search.data.SearchIndexAsyncClient;
import com.azure.search.data.generated.models.SuggestParameters;
import com.azure.search.data.generated.models.SuggestResult;

import com.azure.search.test.environment.models.Author;
import com.azure.search.test.environment.models.Book;
import org.junit.Assert;
import reactor.test.StepVerifier;

import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.stream.Collectors;

import static com.azure.search.data.customization.SearchTestBase.HOTELS_DATA_JSON;
Expand All @@ -23,6 +20,7 @@
public class SuggestAsyncTests extends SuggestTestBase {

private SearchIndexAsyncClient client;
private static final String BOOKS_INDEX_NAME = "books";

@Override
protected void initializeClient() {
Expand Down Expand Up @@ -104,7 +102,30 @@ public void canSuggestStaticallyTypedDocuments() {
}

@Override
public void canSuggestWithDateTimeInStaticModel() {
public void canSuggestWithDateTimeInStaticModel() throws Exception {

Author tolkien = new Author();
tolkien.firstName("J.R.R.");
tolkien.lastName("Tolkien");
Book doc1 = new Book();
doc1.ISBN("123");
doc1.title("Lord of the Rings");
doc1.author(tolkien);

Book doc2 = new Book();
doc2.ISBN("456");
doc2.title("War and Peace");
doc2.publishDate(DATE_FORMAT.parse("2015-08-18T00:00:00Z"));
uploadDocuments(client, BOOKS_INDEX_NAME, Arrays.asList(doc1, doc2));

SuggestParameters suggestParams = new SuggestParameters();
suggestParams.select(Arrays.asList("ISBN", "Title", "PublishDate"));
PagedFlux<SuggestResult> suggestResult = client.suggest("War", "sg", suggestParams, null);

StepVerifier
.create(suggestResult.byPage())
.assertNext(this::verifyCanSuggestWithDateTimeInStaticModel)
.verifyComplete();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,14 @@
import com.azure.search.data.SearchIndexClient;
import com.azure.search.data.generated.models.SuggestParameters;
import com.azure.search.data.generated.models.SuggestResult;
import com.azure.search.test.environment.models.Author;
import com.azure.search.test.environment.models.Book;
import org.junit.Assert;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;

import java.util.Arrays;
import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.stream.Collectors;

import static com.azure.search.data.customization.SearchTestBase.HOTELS_DATA_JSON;
Expand Down Expand Up @@ -107,7 +104,28 @@ public void canSuggestStaticallyTypedDocuments() {
}

@Override
public void canSuggestWithDateTimeInStaticModel() {
public void canSuggestWithDateTimeInStaticModel() throws Exception {
Author tolkien = new Author();
tolkien.firstName("J.R.R.");
tolkien.lastName("Tolkien");
Book doc1 = new Book();
doc1.ISBN("123");
doc1.title("Lord of the Rings");
doc1.author(tolkien);

Book doc2 = new Book();
doc2.ISBN("456");
doc2.title("War and Peace");
doc2.publishDate(DATE_FORMAT.parse("2015-08-18T00:00:00Z"));
uploadDocuments(client, BOOKS_INDEX_NAME, Arrays.asList(doc1, doc2));

SuggestParameters suggestParams = new SuggestParameters();
suggestParams.select(Arrays.asList("ISBN", "Title", "PublishDate"));
PagedIterable<SuggestResult> suggestResult = client.suggest("War", "sg", suggestParams, null);
Iterator<PagedResponse<SuggestResult>> iterator = suggestResult.iterableByPage().iterator();

//assert
verifyCanSuggestWithDateTimeInStaticModel(iterator.next());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@
import com.azure.search.data.common.jsonwrapper.jacksonwrapper.JacksonDeserializer;
import com.azure.search.data.generated.models.SuggestResult;
import com.azure.search.test.environment.models.Hotel;
import com.azure.search.test.environment.setup.SearchIndexService;
import io.netty.handler.codec.http.HttpResponseStatus;
import org.junit.Assert;
import org.junit.Test;

import java.io.IOException;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
Expand All @@ -26,11 +28,22 @@
public abstract class SuggestTestBase extends SearchIndexClientTestBase {
protected JsonApi jsonApi = JsonWrapper.newInstance(JacksonDeserializer.class);
static final String BOOKS_INDEX_JSON = "BooksIndexData.json";
protected static final String BOOKS_INDEX_NAME = "books";

@Override
protected void beforeTest() {
super.beforeTest();
initializeClient();
if (!interceptorManager.isPlaybackMode()) {
// In RECORDING mode (only), create a new index:
SearchIndexService searchIndexService = new SearchIndexService(
BOOKS_INDEX_JSON, searchServiceName, apiKey);
try {
searchIndexService.initialize();
} catch (IOException e) {
Assert.fail("Unable to create books index: " + e.getMessage());
}
}
}

protected abstract void initializeClient();
Expand Down Expand Up @@ -111,6 +124,14 @@ protected void verifyTopDocumentSuggest(PagedResponse<SuggestResult> suggestResu
Assert.assertEquals(Arrays.asList("1", "10", "2"), resultIds);
}

protected void verifyCanSuggestWithDateTimeInStaticModel(PagedResponse<SuggestResult> suggestResultPagedResponse) {
List<SuggestResult> books = suggestResultPagedResponse.value();
List<Document> docs = suggestResultPagedResponse.value().stream().map(h -> h.additionalProperties()).collect(Collectors.toList());

Assert.assertEquals(1, docs.size());
Assert.assertEquals("War and Peace", books.get(0).text());
}

@Test
public abstract void canSuggestDynamicDocuments() throws Exception;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,50 @@
{
"networkCallRecords" : [ ],
"networkCallRecords" : [ {
"Method" : "POST",
"Uri" : "https://azs-sdk8e205043e11b.search.windows.net/indexes('books')/docs/search.index?api-version=2019-05-06",
"Headers" : {
"Content-Type" : "application/json; charset=utf-8"
},
"Response" : {
"Pragma" : "no-cache",
"retry-after" : "0",
"request-id" : "dcb56ffb-13b3-47a8-b9de-b9393f550e47",
"StatusCode" : "200",
"Date" : "Sun, 06 Oct 2019 10:46:30 GMT",
"Strict-Transport-Security" : "max-age=15724800; includeSubDomains",
"Cache-Control" : "no-cache",
"elapsed-time" : "119",
"OData-Version" : "4.0",
"Expires" : "-1",
"Content-Length" : "293",
"Body" : "{\"@odata.context\":\"https://azs-sdk8e205043e11b.search.windows.net/indexes('books')/$metadata#Collection(Microsoft.Azure.Search.V2019_05_06.IndexResult)\",\"value\":[{\"key\":\"123\",\"status\":true,\"errorMessage\":null,\"statusCode\":201},{\"key\":\"456\",\"status\":true,\"errorMessage\":null,\"statusCode\":201}]}",
"Preference-Applied" : "odata.include-annotations=\"*\"",
"Content-Type" : "application/json; odata.metadata=minimal"
},
"Exception" : null
}, {
"Method" : "POST",
"Uri" : "https://azs-sdk8e205043e11b.search.windows.net/indexes('books')/docs/search.post.suggest?api-version=2019-05-06",
"Headers" : {
"Content-Type" : "application/json; charset=utf-8"
},
"Response" : {
"Pragma" : "no-cache",
"retry-after" : "0",
"request-id" : "bfcc6f1b-5843-4758-a6d0-c4c96080fd8e",
"StatusCode" : "200",
"Date" : "Sun, 06 Oct 2019 10:46:36 GMT",
"Strict-Transport-Security" : "max-age=15724800; includeSubDomains",
"Cache-Control" : "no-cache",
"elapsed-time" : "24",
"OData-Version" : "4.0",
"Expires" : "-1",
"Content-Length" : "219",
"Body" : "{\"@odata.context\":\"https://azs-sdk8e205043e11b.search.windows.net/indexes('books')/$metadata#docs(*)\",\"value\":[{\"@search.text\":\"War and Peace\",\"ISBN\":\"456\",\"Title\":\"War and Peace\",\"PublishDate\":\"2015-08-18T00:00:00Z\"}]}",
"Preference-Applied" : "odata.include-annotations=\"*\"",
"Content-Type" : "application/json; odata.metadata=minimal"
},
"Exception" : null
} ],
"variables" : [ ]
}

0 comments on commit b01ea23

Please sign in to comment.