Search in sources :

Example 11 with Store

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)));
    }
}
Also used : ClientIndexConfig(io.zulia.client.config.ClientIndexConfig) Store(io.zulia.client.command.Store) Document(org.bson.Document) Date(java.util.Date) LocalDate(java.time.LocalDate) Order(org.junit.jupiter.api.Order) TestMethodOrder(org.junit.jupiter.api.TestMethodOrder) Test(org.junit.jupiter.api.Test)

Aggregations

Store (io.zulia.client.command.Store)11 ResultDocBuilder (io.zulia.doc.ResultDocBuilder)7 Document (org.bson.Document)7 Date (java.util.Date)4 LocalDate (java.time.LocalDate)3 StoreLargeAssociated (io.zulia.client.command.StoreLargeAssociated)2 ClientIndexConfig (io.zulia.client.config.ClientIndexConfig)2 Order (org.junit.jupiter.api.Order)2 Test (org.junit.jupiter.api.Test)2 TestMethodOrder (org.junit.jupiter.api.TestMethodOrder)2 DeleteAssociated (io.zulia.client.command.DeleteAssociated)1 Search (io.zulia.client.command.builder.Search)1 Sort (io.zulia.client.command.builder.Sort)1 WorkPool (io.zulia.client.pool.WorkPool)1 ZuliaWorkPool (io.zulia.client.pool.ZuliaWorkPool)1 SearchResult (io.zulia.client.result.SearchResult)1 BufferedReader (java.io.BufferedReader)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 FileReader (java.io.FileReader)1