当前位置: 首页>>代码示例>>Java>>正文


Java Index.get方法代码示例

本文整理汇总了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());
}
 
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:27,代码来源:IndexServlet.java

示例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");
}
 
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:17,代码来源:UtilsTest.java

示例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");
}
 
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:18,代码来源:UtilsTest.java

示例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());
}
 
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:29,代码来源:IndexServlet.java


注:本文中的com.google.appengine.api.search.Index.get方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。