Search in sources :

Example 1 with Schema

use of com.google.appengine.api.search.Schema 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]
}
Also used : Schema(com.google.appengine.api.search.Schema) Index(com.google.appengine.api.search.Index) Document(com.google.appengine.api.search.Document) PrintWriter(java.io.PrintWriter) FieldType(com.google.appengine.api.search.Field.FieldType)

Aggregations

Document (com.google.appengine.api.search.Document)1 FieldType (com.google.appengine.api.search.Field.FieldType)1 Index (com.google.appengine.api.search.Index)1 Schema (com.google.appengine.api.search.Schema)1 PrintWriter (java.io.PrintWriter)1