use of com.google.appengine.api.search.Field.FieldType in project java-docs-samples by GoogleCloudPlatform.
the class SchemaServlet method doGet.
@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]
}
Aggregations