if (searchDocs(index, "", 0).getNumberFound() == 0) {
List<Document> documents = new ArrayList<>();
Calendar cal = Calendar.getInstance();
DateFormat dfDate = new SimpleDateFormat("yyyy,M,d");
for (int i = 0; i < docCount; i++) {
Builder docBuilder = Document.newBuilder();
// two text field with different locale
docBuilder.addField(Field.newBuilder().setName("textfield").setText("text with num " + i));
Field field = Field.newBuilder().setName("textfield").setText("C'est la vie " + i).setLocale(Locale.FRENCH).build();
docBuilder.addField(field);
docBuilder.addField(Field.newBuilder().setName("numfield").setNumber(i));
String dateVal = "" + cal.get(Calendar.YEAR) + ",";
dateVal += cal.get(Calendar.MONTH) + ",";
int day = cal.get(Calendar.DATE) + i;
dateVal += day;
docBuilder.addField(Field.newBuilder().setName("datefield").setDate(dfDate.parse(dateVal)));
docBuilder.addField(Field.newBuilder().setName("htmlfield").setHTML("<B>html</B> " + i));
docBuilder.addField(Field.newBuilder().setName("atomfield").setAtom("atom" + i + ".com"));
GeoPoint geoPoint = new GeoPoint((double) i, (double) (100 + i));
docBuilder.addField(Field.newBuilder().setName("geofield").setGeoPoint(geoPoint));
// two field in same name and with different field type
docBuilder.addField(Field.newBuilder().setName("mixfield").setText("text and number mix field"));
docBuilder.addField(Field.newBuilder().setName("mixfield").setNumber(987));
docBuilder.setId("selfid" + i);
// only doc(id="selfid0") has "cn" locale, others have "en" locale
if (i == 0) {
docBuilder.setLocale(new Locale("cn"));
} else {
docBuilder.setLocale(new Locale("en"));
}
documents.add(docBuilder.build());
}
index.put(documents);
sync();
}
}