use of com.google.appengine.api.search.IndexSpec in project java-docs-samples by GoogleCloudPlatform.
the class DeleteServlet method getIndex.
private Index getIndex() {
IndexSpec indexSpec = IndexSpec.newBuilder().setName(SEARCH_INDEX).build();
Index index = SearchServiceFactory.getSearchService().getIndex(indexSpec);
return index;
}
use of com.google.appengine.api.search.IndexSpec in project java-docs-samples by GoogleCloudPlatform.
the class IndexServlet method doGet.
@Override
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
PrintWriter out = resp.getWriter();
Document document = Document.newBuilder().setId("AZ125").addField(Field.newBuilder().setName("myField").setText("myValue")).build();
try {
Utils.indexADocument(INDEX, document);
} catch (InterruptedException e) {
out.println("Interrupted");
return;
}
out.println("Indexed a new document.");
// [START get_document]
IndexSpec indexSpec = IndexSpec.newBuilder().setName(INDEX).build();
Index index = SearchServiceFactory.getSearchService().getIndex(indexSpec);
// Fetch a single document by its doc_id
Document doc = index.get("AZ125");
// Fetch a range of documents by their doc_ids
GetResponse<Document> docs = index.getRange(GetRequest.newBuilder().setStartId("AZ125").setLimit(100).build());
// [END get_document]
out.println("myField: " + docs.getResults().get(0).getOnlyField("myField").getText());
}
use of com.google.appengine.api.search.IndexSpec in project java-docs-samples by GoogleCloudPlatform.
the class SearchOptionServlet method getIndex.
private Index getIndex() {
IndexSpec indexSpec = IndexSpec.newBuilder().setName(SEARCH_INDEX).build();
Index index = SearchServiceFactory.getSearchService().getIndex(indexSpec);
return index;
}
use of com.google.appengine.api.search.IndexSpec in project java-docs-samples by GoogleCloudPlatform.
the class SearchServlet method getIndex.
private Index getIndex() {
IndexSpec indexSpec = IndexSpec.newBuilder().setName(SEARCH_INDEX).build();
Index index = SearchServiceFactory.getSearchService().getIndex(indexSpec);
return index;
}
use of com.google.appengine.api.search.IndexSpec in project java-docs-samples by GoogleCloudPlatform.
the class UtilsTest method indexADocument_successfullyInvoked.
@Test
public void indexADocument_successfullyInvoked() throws Exception {
String id = "test";
Document doc = Document.newBuilder().setId(id).addField(Field.newBuilder().setName("f").setText("v")).build();
Utils.indexADocument(INDEX, doc);
// get the document by id
IndexSpec indexSpec = IndexSpec.newBuilder().setName(INDEX).build();
Index index = SearchServiceFactory.getSearchService().getIndex(indexSpec);
Document fetched = index.get(id);
assertThat(fetched.getOnlyField("f").getText()).named("A value of the fetched document").isEqualTo("v");
}
Aggregations