Search in sources :

Example 11 with ClientIndexConfig

use of io.zulia.client.config.ClientIndexConfig 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)

Example 12 with ClientIndexConfig

use of io.zulia.client.config.ClientIndexConfig in project zuliasearch by zuliaio.

the class ZuliaRestore method restore.

private static void restore(ZuliaWorkPool workPool, String dir, String index, String idField, Boolean drop, Integer threads, Boolean skipExistingFiles) throws Exception {
    String inputDir = dir + File.separator + index;
    String recordsFilename = inputDir + File.separator + index + ".json";
    String settingsFilename = inputDir + File.separator + index + "_settings.json";
    if (Files.exists(Paths.get(settingsFilename)) && Files.exists(Paths.get(recordsFilename))) {
        if (drop) {
            workPool.deleteIndex(index);
        }
        LOG.info("Creating index <" + index + ">");
        ZuliaIndex.IndexSettings.Builder indexSettingsBuilder = ZuliaIndex.IndexSettings.newBuilder();
        JsonFormat.parser().merge(Files.readString(Paths.get(settingsFilename), Charsets.UTF_8), indexSettingsBuilder);
        ClientIndexConfig indexConfig = new ClientIndexConfig();
        indexConfig.configure(indexSettingsBuilder.build());
        workPool.createIndex(indexConfig);
        LOG.info("Finished creating index <" + index + ">");
        AtomicInteger count = new AtomicInteger();
        LOG.info("Starting to index records for index <" + index + ">");
        ZuliaCmdUtil.index(inputDir, recordsFilename, idField, index, workPool, count, threads, skipExistingFiles);
        LOG.info("Finished indexing for index <" + index + "> with total records: " + count);
    } else {
        if (index.endsWith(".json")) {
            System.err.println("Please provide the path to the parent directory in --dir option.");
            System.exit(9);
        } else {
            System.err.println("Index <" + index + "> does not exist in the given dir <" + dir + ">, please provide the path to the parent directory in --dir option.");
            System.exit(9);
        }
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ClientIndexConfig(io.zulia.client.config.ClientIndexConfig)

Example 13 with ClientIndexConfig

use of io.zulia.client.config.ClientIndexConfig in project zuliasearch by zuliaio.

the class Mapper method createOrUpdateIndex.

public CreateIndex createOrUpdateIndex() {
    if (settings == null) {
        throw new RuntimeException("No Settings annotation for class <" + clazz.getSimpleName() + ">");
    }
    ClientIndexConfig indexConfig = new ClientIndexConfig();
    for (DefaultSearchFieldInfo<T> defaultSearchField : defaultSearchFields) {
        indexConfig.addDefaultSearchField(defaultSearchField.getFieldName());
    }
    indexConfig.setIndexName(settings.indexName());
    indexConfig.setNumberOfShards(settings.numberOfShards());
    indexConfig.setRequestFactor(settings.requestFactor());
    indexConfig.setMinShardRequest(settings.minSeqmentRequest());
    indexConfig.setIdleTimeWithoutCommit(settings.idleTimeWithoutCommit());
    indexConfig.setShardCommitInterval(settings.shardCommitInterval());
    indexConfig.setShardTolerance(settings.shardTolerance());
    indexConfig.setShardQueryCacheSize(settings.shardQueryCacheSize());
    indexConfig.setShardQueryCacheMaxAmount(settings.shardQueryCacheMaxAmount());
    for (FieldConfig fieldConfig : fieldConfigMapper.getFieldConfigs()) {
        indexConfig.addFieldConfig(fieldConfig);
    }
    return new CreateIndex(indexConfig);
}
Also used : CreateIndex(io.zulia.client.command.CreateIndex) FieldConfig(io.zulia.message.ZuliaIndex.FieldConfig) ClientIndexConfig(io.zulia.client.config.ClientIndexConfig)

Example 14 with ClientIndexConfig

use of io.zulia.client.config.ClientIndexConfig in project zuliasearch by zuliaio.

the class FileStorageTest method createIndex.

private void createIndex() throws Exception {
    ClientIndexConfig indexConfig = new ClientIndexConfig();
    indexConfig.setIndexName(TEST_INDEX);
    indexConfig.setNumberOfShards(1);
    indexConfig.setShardCommitInterval(64000);
    indexConfig.addAnalyzerSetting(ZuliaIndex.AnalyzerSettings.newBuilder().setName("text").addFilter(ZuliaIndex.AnalyzerSettings.Filter.CASE_PROTECTED_WORDS).addFilter(ZuliaIndex.AnalyzerSettings.Filter.LOWERCASE).addFilter(ZuliaIndex.AnalyzerSettings.Filter.ASCII_FOLDING).addFilter(ZuliaIndex.AnalyzerSettings.Filter.ENGLISH_POSSESSIVE).addFilter(ZuliaIndex.AnalyzerSettings.Filter.ENGLISH_MIN_STEM).addFilter(ZuliaIndex.AnalyzerSettings.Filter.BRITISH_US).build());
    indexConfig.addAnalyzerSetting(ZuliaIndex.AnalyzerSettings.newBuilder().setName("entity").addFilter(ZuliaIndex.AnalyzerSettings.Filter.LOWERCASE).addFilter(ZuliaIndex.AnalyzerSettings.Filter.ASCII_FOLDING).build());
    FieldConfigBuilder fieldConfigBuilder = FieldConfigBuilder.create("title", ZuliaIndex.FieldConfig.FieldType.STRING);
    fieldConfigBuilder.indexAs("text", "title");
    fieldConfigBuilder.displayName("Title");
    indexConfig.addFieldConfig(fieldConfigBuilder);
    FieldConfigBuilder fieldConfigBuilder2 = FieldConfigBuilder.create("abstract", ZuliaIndex.FieldConfig.FieldType.STRING);
    fieldConfigBuilder2.indexAs("text", "abstract");
    fieldConfigBuilder2.displayName("Abstract");
    indexConfig.addFieldConfig(fieldConfigBuilder2);
    FieldConfigBuilder fieldConfigBuilder3 = FieldConfigBuilder.create("id", ZuliaIndex.FieldConfig.FieldType.STRING);
    fieldConfigBuilder3.indexAs(DefaultAnalyzers.STANDARD, "id");
    fieldConfigBuilder3.displayName("ID");
    indexConfig.addFieldConfig(fieldConfigBuilder3);
    CreateIndex createOrUpdateIndex = new CreateIndex(indexConfig);
    zuliaWorkPool.createIndex(createOrUpdateIndex);
}
Also used : CreateIndex(io.zulia.client.command.CreateIndex) ClientIndexConfig(io.zulia.client.config.ClientIndexConfig) FieldConfigBuilder(io.zulia.fields.FieldConfigBuilder)

Aggregations

ClientIndexConfig (io.zulia.client.config.ClientIndexConfig)14 Order (org.junit.jupiter.api.Order)6 Test (org.junit.jupiter.api.Test)6 TestMethodOrder (org.junit.jupiter.api.TestMethodOrder)6 BeforeAll (org.junit.jupiter.api.BeforeAll)4 Search (io.zulia.client.command.builder.Search)3 SearchResult (io.zulia.client.result.SearchResult)3 CreateIndex (io.zulia.client.command.CreateIndex)2 Reindex (io.zulia.client.command.Reindex)2 Store (io.zulia.client.command.Store)2 Sort (io.zulia.client.command.builder.Sort)2 Document (org.bson.Document)2 CountFacet (io.zulia.client.command.builder.CountFacet)1 GetIndexConfigResult (io.zulia.client.result.GetIndexConfigResult)1 FieldConfigBuilder (io.zulia.fields.FieldConfigBuilder)1 FieldConfig (io.zulia.message.ZuliaIndex.FieldConfig)1 FacetCount (io.zulia.message.ZuliaQuery.FacetCount)1 ZuliaServiceBlockingStub (io.zulia.message.ZuliaServiceGrpc.ZuliaServiceBlockingStub)1 GetIndexSettingsResponse (io.zulia.message.ZuliaServiceOuterClass.GetIndexSettingsResponse)1 LocalDate (java.time.LocalDate)1