Search in sources :

Example 6 with Store

use of io.zulia.client.command.Store in project zuliasearch by zuliaio.

the class FileStorageTest method indexDocument.

private void indexDocument(Document document) throws Exception {
    Store store = new Store(document.getString("id"), TEST_INDEX);
    store.setResultDocument(new ResultDocBuilder().setDocument(document));
    zuliaWorkPool.store(store);
}
Also used : Store(io.zulia.client.command.Store) ResultDocBuilder(io.zulia.doc.ResultDocBuilder)

Example 7 with Store

use of io.zulia.client.command.Store 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 Store

use of io.zulia.client.command.Store in project zuliasearch by zuliaio.

the class StartStopTest method indexRecord.

private void indexRecord(int id, String issn, String eissn, int i) throws Exception {
    boolean half = (i % 2 == 0);
    boolean tenth = (i % 10 == 0);
    String uniqueId = uniqueIdPrefix + id;
    Document mongoDocument = new Document();
    mongoDocument.put("issn", issn);
    mongoDocument.put("eissn", eissn);
    mongoDocument.put("id", id);
    if (id != 0) {
        mongoDocument.put("an", id);
    }
    if (id == 0) {
        mongoDocument.put("testBool", true);
    } else if (id == 1) {
        mongoDocument.put("testBool", 1);
    } else if (id == 2) {
        mongoDocument.put("testBool", "Yes");
    } else if (id == 3) {
        mongoDocument.put("testBool", "true");
    } else if (id == 4) {
        mongoDocument.put("testBool", "Y");
    } else if (id == 5) {
        mongoDocument.put("testBool", "T");
    } else if (id == 6) {
        mongoDocument.put("testBool", false);
    } else if (id == 7) {
        mongoDocument.put("testBool", "False");
    } else if (id == 8) {
        mongoDocument.put("testBool", "F");
    } else if (id == 9) {
        mongoDocument.put("testBool", 0);
    }
    if (!issn.equals("3331-3333")) {
        if (half) {
            mongoDocument.put("title", "Facet Userguide");
        } else {
            mongoDocument.put("title", "Special Userguide");
        }
    }
    if (half) {
        // 1/2 of input
        mongoDocument.put("country", "US");
        mongoDocument.put("testList", Arrays.asList("one", "two"));
    } else {
        // 1/2 of input
        mongoDocument.put("country", "France");
        mongoDocument.put("testList", Arrays.asList("a", "b", "c"));
    }
    if (tenth) {
        // 1/10 of input
        Date d = Date.from(LocalDate.of(2014, Month.OCTOBER, 4).atStartOfDay(ZoneId.of("UTC")).toInstant());
        mongoDocument.put("date", d);
    } else if (half) {
        // 2/5 of input
        Date d = Date.from(LocalDate.of(2013, Month.SEPTEMBER, 4).atStartOfDay(ZoneId.of("UTC")).toInstant());
        mongoDocument.put("date", d);
    } else {
        // 1/2 of input
        Date d = Date.from(LocalDate.of(2012, 8, 4).atStartOfDay(ZoneId.of("UTC")).toInstant());
        mongoDocument.put("date", d);
    }
    Store s = new Store(uniqueId, FACET_TEST_INDEX);
    ResultDocBuilder resultDocumentBuilder = ResultDocBuilder.newBuilder().setDocument(mongoDocument);
    if (half) {
        resultDocumentBuilder.setMetadata(new Document("test", "someValue"));
    }
    s.setResultDocument(resultDocumentBuilder);
    zuliaWorkPool.store(s);
}
Also used : Store(io.zulia.client.command.Store) Document(org.bson.Document) Date(java.util.Date) LocalDate(java.time.LocalDate) ResultDocBuilder(io.zulia.doc.ResultDocBuilder)

Example 9 with Store

use of io.zulia.client.command.Store in project zuliasearch by zuliaio.

the class StatTest method indexRecord.

private void indexRecord(int id, String title, String pathFacet, String normalFacet, int authorCount, List<Double> rating) throws Exception {
    String uniqueId = "" + id;
    Document mongoDocument = new Document();
    mongoDocument.put("id", uniqueId);
    mongoDocument.put("title", title);
    mongoDocument.put("pathFacet", pathFacet);
    mongoDocument.put("normalFacet", normalFacet);
    mongoDocument.put("authorCount", authorCount);
    mongoDocument.put("rating", rating);
    Store s = new Store(uniqueId, STAT_TEST_INDEX);
    ResultDocBuilder resultDocumentBuilder = ResultDocBuilder.newBuilder().setDocument(mongoDocument);
    s.setResultDocument(resultDocumentBuilder);
    zuliaWorkPool.store(s);
}
Also used : Store(io.zulia.client.command.Store) Document(org.bson.Document) ResultDocBuilder(io.zulia.doc.ResultDocBuilder)

Example 10 with Store

use of io.zulia.client.command.Store in project zuliasearch by zuliaio.

the class HierarchicalFacetTest method indexRecord.

private void indexRecord(int id, String path, int i) throws Exception {
    boolean half = (i % 2 == 0);
    boolean tenth = (i % 10 == 0);
    String uniqueId = "mySpecialId-" + id;
    Document mongoDocument = new Document();
    mongoDocument.put("path", path);
    mongoDocument.put("path2", path);
    mongoDocument.put("normalFacet", path);
    mongoDocument.put("id", id);
    if (tenth) {
        // 1/10 of input
        Date d = Date.from(LocalDate.of(2014, Month.OCTOBER, 4).atStartOfDay(ZoneId.of("UTC")).toInstant());
        mongoDocument.put("date", d);
    } else if (half) {
        // 2/5 of input
        Date d = Date.from(LocalDate.of(2013, Month.SEPTEMBER, 4).atStartOfDay(ZoneId.of("UTC")).toInstant());
        mongoDocument.put("date", d);
        mongoDocument.put("normalFacetList", Arrays.asList("value1", "something"));
    } else {
        // 1/2 of input
        Date d = Date.from(LocalDate.of(2012, 8, 4).atStartOfDay(ZoneId.of("UTC")).toInstant());
        mongoDocument.put("date", d);
        mongoDocument.put("normalFacetList", Arrays.asList("value2", "something2"));
    }
    Store s = new Store(uniqueId, FACET_TEST_INDEX);
    ResultDocBuilder resultDocumentBuilder = ResultDocBuilder.newBuilder().setDocument(mongoDocument);
    s.setResultDocument(resultDocumentBuilder);
    zuliaWorkPool.store(s);
}
Also used : Store(io.zulia.client.command.Store) Document(org.bson.Document) Date(java.util.Date) LocalDate(java.time.LocalDate) ResultDocBuilder(io.zulia.doc.ResultDocBuilder)

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