String indexName = "test-doc-fields";
Index index = searchService.getIndex(IndexSpec.newBuilder().setName(indexName));
delDocs(index);
Builder docBuilder = Document.newBuilder();
Field field = Field.newBuilder().setName("textfield").setText("text field").build();
docBuilder.addField(field);
field = Field.newBuilder().setName("numberfield").setNumber(123).build();
docBuilder.addField(field);
Date now = new Date();
field = Field.newBuilder().setName("datefield").setDate(now).build();
docBuilder.addField(field);
field = Field.newBuilder().setName("htmlfield").setHTML("<html>html field</html>").build();
docBuilder.addField(field);
User currentUser = new User("prometheus-qa@appenginetest.com", "appenginetest.com");
field = Field.newBuilder().setName("atomfield").setAtom(currentUser.getAuthDomain()).build();
docBuilder.addField(field);
GeoPoint geoPoint = new GeoPoint((double) -10, 10.000001);
field = Field.newBuilder().setName("geofield").setGeoPoint(geoPoint).build();
docBuilder.addField(field);
index.put(docBuilder);
sync();
Results<ScoredDocument> result = searchDocs(index, "", 0);
assertEquals(1, result.getNumberReturned());
ScoredDocument doc = result.iterator().next();
Field retField = doc.getOnlyField("textfield");
assertEquals(FieldType.TEXT, retField.getType());
assertEquals("textfield", retField.getName());
assertEquals("text field", retField.getText());
retField = doc.getOnlyField("numberfield");
assertEquals(FieldType.NUMBER, retField.getType());
assertEquals(new Double("123"), retField.getNumber());
retField = doc.getOnlyField("datefield");
assertEquals(FieldType.DATE, retField.getType());
assertEquals(now, retField.getDate());
retField = doc.getOnlyField("htmlfield");
assertEquals(FieldType.HTML, retField.getType());
assertEquals("<html>html field</html>", retField.getHTML());
retField = doc.getOnlyField("atomfield");
assertEquals(FieldType.ATOM, retField.getType());
assertEquals(currentUser.getAuthDomain(), retField.getAtom());
retField = doc.getOnlyField("geofield");
assertEquals(FieldType.GEO_POINT, retField.getType());
assertEquals(-10, retField.getGeoPoint().getLatitude(), 0);
assertEquals(10.000001, retField.getGeoPoint().getLongitude(), 0.000000);
}