本文整理汇总了Java中com.google.appengine.api.search.Index.get方法的典型用法代码示例。如果您正苦于以下问题:Java Index.get方法的具体用法?Java Index.get怎么用?Java Index.get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.appengine.api.search.Index
的用法示例。
在下文中一共展示了Index.get方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doGet
import com.google.appengine.api.search.Index; //导入方法依赖的package包/类
@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());
}
示例2: indexADocument_successfullyInvoked
import com.google.appengine.api.search.Index; //导入方法依赖的package包/类
@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");
}
示例3: indexADocument_successfullyInvoked
import com.google.appengine.api.search.Index; //导入方法依赖的package包/类
@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");
}
示例4: doGet
import com.google.appengine.api.search.Index; //导入方法依赖的package包/类
@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());
}