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


Java Index.getSchema方法代码示例

本文整理汇总了Java中com.google.appengine.api.search.Index.getSchema方法的典型用法代码示例。如果您正苦于以下问题:Java Index.getSchema方法的具体用法?Java Index.getSchema怎么用?Java Index.getSchema使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.google.appengine.api.search.Index的用法示例。


在下文中一共展示了Index.getSchema方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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 doc = Document.newBuilder()
      .setId("theOnlyCar")
      .addField(Field.newBuilder().setName("maker").setText("Toyota"))
      .addField(Field.newBuilder().setName("price").setNumber(300000))
      .addField(Field.newBuilder().setName("color").setText("lightblue"))
      .addField(Field.newBuilder().setName("model").setText("Prius"))
      .build();
  try {
    Utils.indexADocument(SEARCH_INDEX, doc);
  } catch (InterruptedException e) {
    // ignore
  }
  // [START list_schema]
  GetResponse<Index> response = SearchServiceFactory.getSearchService().getIndexes(
      GetIndexesRequest.newBuilder().setSchemaFetched(true).build());

  // List out elements of each Schema
  for (Index index : response) {
    Schema schema = index.getSchema();
    for (String fieldName : schema.getFieldNames()) {
      List<FieldType> typesForField = schema.getFieldTypes(fieldName);
      // Just printing out the field names and types
      for (FieldType type : typesForField) {
        out.println(index.getName() + ":" + fieldName + ":" + type.name());
      }
    }
  }
  // [END list_schema]
}
 
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:34,代码来源:SchemaServlet.java

示例2: doGet

import com.google.appengine.api.search.Index; //导入方法依赖的package包/类
@Override
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
  PrintWriter out = resp.getWriter();
  Document doc =
      Document.newBuilder()
          .setId("theOnlyCar")
          .addField(Field.newBuilder().setName("maker").setText("Toyota"))
          .addField(Field.newBuilder().setName("price").setNumber(300000))
          .addField(Field.newBuilder().setName("color").setText("lightblue"))
          .addField(Field.newBuilder().setName("model").setText("Prius"))
          .build();
  try {
    Utils.indexADocument(SEARCH_INDEX, doc);
  } catch (InterruptedException e) {
    // ignore
  }
  // [START list_schema]
  GetResponse<Index> response =
      SearchServiceFactory.getSearchService()
          .getIndexes(GetIndexesRequest.newBuilder().setSchemaFetched(true).build());

  // List out elements of each Schema
  for (Index index : response) {
    Schema schema = index.getSchema();
    for (String fieldName : schema.getFieldNames()) {
      List<FieldType> typesForField = schema.getFieldTypes(fieldName);
      // Just printing out the field names and types
      for (FieldType type : typesForField) {
        out.println(index.getName() + ":" + fieldName + ":" + type.name());
      }
    }
  }
  // [END list_schema]
}
 
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:35,代码来源:SchemaServlet.java


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