Search in sources :

Example 6 with ClientIndexConfig

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

the class GetIndexConfig method execute.

@Override
public GetIndexConfigResult execute(ZuliaConnection zuliaConnection) {
    ZuliaServiceBlockingStub service = zuliaConnection.getService();
    GetIndexSettingsResponse getIndexConfigResponse = service.getIndexSettings(getRequest());
    ClientIndexConfig indexConfig = new ClientIndexConfig();
    indexConfig.configure(getIndexConfigResponse.getIndexSettings());
    return new GetIndexConfigResult(indexConfig);
}
Also used : ZuliaServiceBlockingStub(io.zulia.message.ZuliaServiceGrpc.ZuliaServiceBlockingStub) GetIndexSettingsResponse(io.zulia.message.ZuliaServiceOuterClass.GetIndexSettingsResponse) GetIndexConfigResult(io.zulia.client.result.GetIndexConfigResult) ClientIndexConfig(io.zulia.client.config.ClientIndexConfig)

Example 7 with ClientIndexConfig

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

the class SortTest method multiIndexTest.

@Test
@Order(14)
public void multiIndexTest() throws Exception {
    ClientIndexConfig indexConfig = new ClientIndexConfig();
    indexConfig.addDefaultSearchField("magicNumber");
    indexConfig.addFieldConfig(FieldConfigBuilder.create("id", FieldType.NUMERIC_INT).sort());
    indexConfig.addFieldConfig(FieldConfigBuilder.create("magicNumber", FieldType.NUMERIC_INT).index().sort());
    indexConfig.setIndexName("anotherIndex");
    indexConfig.setNumberOfShards(1);
    // force some commits
    indexConfig.setShardCommitInterval(20);
    zuliaWorkPool.createIndex(indexConfig);
    indexConfig.setIndexName("anotherIndex2");
    zuliaWorkPool.createIndex(indexConfig);
    for (int id = 0; id < 200; id++) {
        int magicNumber = 7;
        if (id > 10) {
            magicNumber = -1;
        }
        Document mongoDocument = new Document().append("id", id).append("magicNumber", magicNumber);
        zuliaWorkPool.store(new Store(id + "", "anotherIndex", ResultDocBuilder.from(mongoDocument)));
    }
    for (int id = 0; id < 100; id++) {
        int magicNumber = (id % 10) + 5;
        Document mongoDocument = new Document().append("id", id).append("magicNumber", magicNumber);
        zuliaWorkPool.store(new Store(id + "", "anotherIndex2", ResultDocBuilder.from(mongoDocument)));
    }
    SearchResult searchResult;
    Search search = new Search("anotherIndex", "anotherIndex2").setAmount(1);
    search.addSort(new Sort("magicNumber"));
    searchResult = zuliaWorkPool.search(search);
    Assertions.assertEquals(-1, searchResult.getFirstDocument().get("magicNumber"));
    search.clearSort();
    search.addSort(new Sort("magicNumber").descending());
    searchResult = zuliaWorkPool.search(search);
    Assertions.assertEquals(14, searchResult.getFirstDocument().get("magicNumber"));
}
Also used : Search(io.zulia.client.command.builder.Search) ClientIndexConfig(io.zulia.client.config.ClientIndexConfig) Store(io.zulia.client.command.Store) Sort(io.zulia.client.command.builder.Sort) SearchResult(io.zulia.client.result.SearchResult) Document(org.bson.Document) Order(org.junit.jupiter.api.Order) TestMethodOrder(org.junit.jupiter.api.TestMethodOrder) Test(org.junit.jupiter.api.Test)

Example 8 with ClientIndexConfig

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

the class SortTest method reindexTest.

@Test
@Order(13)
public void reindexTest() throws Exception {
    ClientIndexConfig indexConfig = new ClientIndexConfig();
    indexConfig.addDefaultSearchField("title");
    indexConfig.addFieldConfig(FieldConfigBuilder.create("id", FieldType.STRING).indexAs(DefaultAnalyzers.LC_KEYWORD).sortAs(// change sort as to be theId instead of just id
    "theId"));
    indexConfig.addFieldConfig(FieldConfigBuilder.create("title", FieldType.STRING).indexAs(DefaultAnalyzers.STANDARD).sort());
    // no longer sortable
    indexConfig.addFieldConfig(FieldConfigBuilder.create("stars", FieldType.NUMERIC_INT).index());
    indexConfig.addFieldConfig(FieldConfigBuilder.create("starsLong", FieldType.NUMERIC_LONG).index().sort());
    // indexConfig.addFieldConfig(FieldConfigBuilder.create("rating", FieldType.NUMERIC_FLOAT).index().sort()); // no longer indexed or sortable
    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());
    // sort() adds standard string (case senstive sorting with a field name the same as the stored field
    // sortAs(LOWERCASE_FOLDING, "otherTitleFolding") add another sortable field with a lowercase and ascii folding filter applied to make case insensitive sort and fancy letter insensitive (gotta be a better term here)
    indexConfig.addFieldConfig(FieldConfigBuilder.create("otherTitle", FieldType.STRING).index().sort().sortAs(LOWERCASE_FOLDING, "otherTitleFolding"));
    indexConfig.setIndexName(INDEX_NAME);
    indexConfig.setNumberOfShards(1);
    // force some commits
    indexConfig.setShardCommitInterval(20);
    zuliaWorkPool.createIndex(indexConfig);
    zuliaWorkPool.reindex(new Reindex(INDEX_NAME));
    SearchResult searchResult;
    Search search = new Search(INDEX_NAME).setAmount(1);
    search.addSort(new Sort("otherTitle").ascending().missingLast());
    searchResult = zuliaWorkPool.search(search);
    Assertions.assertEquals("Blah", searchResult.getFirstDocument().get("otherTitle"));
    search.clearSort();
    search.addSort(new Sort("otherTitleFolding").ascending().missingLast());
    search.addSort(new Sort("starts").ascending().missingLast());
    searchResult = zuliaWorkPool.search(search);
    Assertions.assertEquals("blah", searchResult.getFirstDocument().get("otherTitle"));
    search.clearSort();
    search.addSort(new Sort("otherTitle").descending());
    searchResult = zuliaWorkPool.search(search);
    Assertions.assertEquals("still more blah", searchResult.getFirstDocument().get("otherTitle"));
    search.clearSort();
    // use the new sort as id field
    search.addSort(new Sort("theId").descending());
    searchResult = zuliaWorkPool.search(search);
    // sorting as string so this is 99 instead of 199
    Assertions.assertEquals("99", searchResult.getFirstDocument().get("id"));
}
Also used : Search(io.zulia.client.command.builder.Search) ClientIndexConfig(io.zulia.client.config.ClientIndexConfig) Sort(io.zulia.client.command.builder.Sort) SearchResult(io.zulia.client.result.SearchResult) Reindex(io.zulia.client.command.Reindex) Order(org.junit.jupiter.api.Order) TestMethodOrder(org.junit.jupiter.api.TestMethodOrder) Test(org.junit.jupiter.api.Test)

Example 9 with ClientIndexConfig

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

the class StartStopTest method reindex.

@Test
@Order(4)
public void reindex() 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("issn", FieldType.STRING).indexAs(DefaultAnalyzers.LC_KEYWORD).facet().sort());
    indexConfig.addFieldConfig(FieldConfigBuilder.create("eissn", FieldType.STRING).indexAs(DefaultAnalyzers.LC_KEYWORD).facet());
    indexConfig.addFieldConfig(FieldConfigBuilder.create("uid", FieldType.STRING).indexAs(DefaultAnalyzers.LC_KEYWORD));
    indexConfig.addFieldConfig(FieldConfigBuilder.create("an", FieldType.NUMERIC_INT).index().displayName("Accession Number").sort());
    indexConfig.addFieldConfig(FieldConfigBuilder.create("country", FieldType.STRING).indexAs(DefaultAnalyzers.LC_KEYWORD).facet().sort());
    indexConfig.addFieldConfig(FieldConfigBuilder.create("date", FieldType.DATE).index().facetAs(DateHandling.DATE_YYYY_MM_DD).description("The very special data").sort());
    indexConfig.addFieldConfig(FieldConfigBuilder.create("testList", FieldType.STRING).index());
    indexConfig.setIndexName(FACET_TEST_INDEX);
    indexConfig.setNumberOfShards(1);
    zuliaWorkPool.createIndex(indexConfig);
    zuliaWorkPool.reindex(new Reindex(FACET_TEST_INDEX));
    Search search = new Search(FACET_TEST_INDEX).addCountFacet(new CountFacet("eissn"));
    SearchResult searchResult = zuliaWorkPool.search(search);
    List<FacetCount> eissnCounts = searchResult.getFacetCounts("eissn");
    Assertions.assertEquals(eissns.length, eissnCounts.size());
    for (FacetCount eissnCount : eissnCounts) {
        Assertions.assertEquals(COUNT_PER_ISSN, eissnCount.getCount());
    }
}
Also used : Search(io.zulia.client.command.builder.Search) ClientIndexConfig(io.zulia.client.config.ClientIndexConfig) SearchResult(io.zulia.client.result.SearchResult) FacetCount(io.zulia.message.ZuliaQuery.FacetCount) Reindex(io.zulia.client.command.Reindex) CountFacet(io.zulia.client.command.builder.CountFacet) Order(org.junit.jupiter.api.Order) TestMethodOrder(org.junit.jupiter.api.TestMethodOrder) Test(org.junit.jupiter.api.Test)

Example 10 with ClientIndexConfig

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

the class HierarchicalFacetTest method initAll.

@BeforeAll
public static void initAll() throws Exception {
    TestHelper.createNodes(3);
    TestHelper.startNodes();
    Thread.sleep(2000);
    zuliaWorkPool = TestHelper.createClient();
    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("path", FieldType.STRING).indexAs(DefaultAnalyzers.LC_KEYWORD).facetHierarchical().sort());
    indexConfig.addFieldConfig(FieldConfigBuilder.create("date", FieldType.DATE).index().facetHierarchical().sort());
    indexConfig.addFieldConfig(FieldConfigBuilder.create("normalFacet", FieldType.STRING).indexAs(DefaultAnalyzers.LC_KEYWORD).facet().sort());
    indexConfig.addFieldConfig(FieldConfigBuilder.create("normalFacetList", FieldType.STRING).indexAs(DefaultAnalyzers.LC_KEYWORD).facet().sort());
    indexConfig.setIndexName(FACET_TEST_INDEX);
    indexConfig.setNumberOfShards(1);
    // force some commits
    indexConfig.setShardCommitInterval(20);
    zuliaWorkPool.createIndex(indexConfig);
}
Also used : ClientIndexConfig(io.zulia.client.config.ClientIndexConfig) BeforeAll(org.junit.jupiter.api.BeforeAll)

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