use of io.zulia.client.command.Store in project zuliasearch by zuliaio.
the class SortTest method indexingTest.
@Test
@Order(1)
public void indexingTest() throws Exception {
ClientIndexConfig indexConfig = new ClientIndexConfig();
indexConfig.addDefaultSearchField("title");
indexConfig.addFieldConfig(FieldConfigBuilder.create("id", FieldType.STRING).indexAs(DefaultAnalyzers.LC_KEYWORD).sort());
indexConfig.addFieldConfig(FieldConfigBuilder.create("title", FieldType.STRING).indexAs(DefaultAnalyzers.STANDARD).sort());
indexConfig.addFieldConfig(FieldConfigBuilder.create("stars", FieldType.NUMERIC_INT).index().sort());
indexConfig.addFieldConfig(FieldConfigBuilder.create("starsLong", FieldType.NUMERIC_LONG).index().sort());
indexConfig.addFieldConfig(FieldConfigBuilder.create("rating", FieldType.NUMERIC_FLOAT).index().sort());
indexConfig.addFieldConfig(FieldConfigBuilder.create("ratingDouble", FieldType.NUMERIC_FLOAT).index().sort());
indexConfig.addFieldConfig(FieldConfigBuilder.create("special", FieldType.BOOL).index().sort());
indexConfig.addFieldConfig(FieldConfigBuilder.create("added", FieldType.DATE).index().sort());
indexConfig.setIndexName(INDEX_NAME);
indexConfig.setNumberOfShards(1);
// force some commits
indexConfig.setShardCommitInterval(20);
zuliaWorkPool.createIndex(indexConfig);
for (int id = 0; id < 200; id++) {
String title = "some title";
String otherTitle = "blah";
Integer stars = 1;
Long starsLong = 1L;
Float rating = 5.0f;
Double ratingDouble = 5.0d;
Boolean special = false;
Date added = null;
if (id == 5) {
title = null;
otherTitle = "Blah";
stars = 4;
starsLong = 4L;
rating = 1.2f;
ratingDouble = 1.1d;
added = Date.from(LocalDate.of(2014, Month.OCTOBER, 4).atStartOfDay(ZoneId.of("UTC")).toInstant());
}
if (id == 6) {
title = null;
otherTitle = "Blāh";
stars = 4;
starsLong = 4L;
rating = 1.2f;
ratingDouble = 1.1d;
added = Date.from(LocalDate.of(2014, Month.OCTOBER, 6).atStartOfDay(ZoneId.of("UTC")).toInstant());
}
if (id == 10) {
title = null;
otherTitle = "out of ideas";
stars = 4;
starsLong = 4L;
rating = 1.1f;
ratingDouble = 1.1d;
added = Date.from(LocalDate.of(2014, Month.OCTOBER, 4).atStartOfDay(ZoneId.of("UTC")).toInstant());
}
if (id == 20) {
title = "other title";
otherTitle = "still more blah";
stars = 3;
starsLong = 3L;
rating = null;
ratingDouble = null;
special = null;
added = Date.from(LocalDate.of(2015, Month.APRIL, 1).atStartOfDay(ZoneId.of("UTC")).toInstant());
}
if (id == 30) {
title = "a special title";
otherTitle = "primary colors";
stars = null;
starsLong = null;
rating = 4.7f;
ratingDouble = 4.7d;
special = true;
added = Date.from(LocalDate.of(2020, Month.JANUARY, 31).atStartOfDay(ZoneId.of("UTC")).toInstant());
}
if (id == 40) {
title = "oh so special secret title";
otherTitle = "secondary colors";
starsLong = Integer.MAX_VALUE + 100000L;
rating = 4.7f;
ratingDouble = Float.MAX_VALUE + 1000000d;
special = true;
added = Date.from(LocalDate.of(1951, Month.DECEMBER, 20).atStartOfDay(ZoneId.of("UTC")).toInstant());
}
String uniqueId = "" + id;
Document mongoDocument = new Document();
mongoDocument.put("id", uniqueId);
mongoDocument.put("title", title);
// used to test adding a sortable field
mongoDocument.put("otherTitle", otherTitle);
mongoDocument.put("stars", stars);
mongoDocument.put("starsLong", starsLong);
mongoDocument.put("rating", rating);
mongoDocument.put("ratingDouble", ratingDouble);
mongoDocument.put("special", special);
mongoDocument.put("added", added);
zuliaWorkPool.store(new Store(uniqueId, INDEX_NAME, ResultDocBuilder.from(mongoDocument)));
}
}
Aggregations