Search in sources :

Example 6 with SearchResult

use of io.zulia.client.result.SearchResult in project zuliasearch by zuliaio.

the class StartStopTest method lengthTestBuilder.

@Test
@Order(3)
public void lengthTestBuilder() throws Exception {
    Search s = new Search(FACET_TEST_INDEX);
    SearchResult searchResult = zuliaWorkPool.search(s);
    long total = searchResult.getTotalHits();
    s = new Search(FACET_TEST_INDEX).addQuery(new FilterQuery("|country|:2"));
    searchResult = zuliaWorkPool.search(s);
    Assertions.assertEquals(total / 2, searchResult.getTotalHits());
    s = new Search(FACET_TEST_INDEX).addQuery(new FilterQuery("|country|:[0 TO 1]"));
    searchResult = zuliaWorkPool.search(s);
    Assertions.assertEquals(0, searchResult.getTotalHits());
    s = new Search(FACET_TEST_INDEX).addQuery(new FilterQuery("|||testList|||:3"));
    searchResult = zuliaWorkPool.search(s);
    Assertions.assertEquals(total / 2, searchResult.getTotalHits());
    s = new Search(FACET_TEST_INDEX).addQuery(new FilterQuery("|||testList|||:[2 TO 3]"));
    searchResult = zuliaWorkPool.search(s);
    Assertions.assertEquals(total, searchResult.getTotalHits());
    s = new Search(FACET_TEST_INDEX).setAmount((int) total / 2).addSort(new Sort("|country|"));
    searchResult = zuliaWorkPool.search(s);
    for (Document document : searchResult.getDocuments()) {
        Assertions.assertEquals(document.getString("country"), "US");
    }
    s = new Search(FACET_TEST_INDEX).setAmount((int) total / 2).addSort(new Sort("|country|").descending());
    searchResult = zuliaWorkPool.search(s);
    for (Document document : searchResult.getDocuments()) {
        Assertions.assertEquals(document.getString("country"), "France");
    }
}
Also used : Search(io.zulia.client.command.builder.Search) FilterQuery(io.zulia.client.command.builder.FilterQuery) 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 7 with SearchResult

use of io.zulia.client.result.SearchResult in project zuliasearch by zuliaio.

the class StatTest method statTest.

@Test
@Order(3)
public void statTest() throws Exception {
    Search search = new Search(STAT_TEST_INDEX);
    search.addStat(new NumericStat("rating"));
    search.addQuery(new FilterQuery("title:boring").exclude());
    search.addQuery(new MatchAllQuery());
    SearchResult searchResult = zuliaWorkPool.search(search);
    System.out.println("Hits: " + searchResult.getTotalHits());
    FacetStats ratingStat = searchResult.getNumericFieldStat("rating");
    Assertions.assertEquals(0.5, ratingStat.getMin().getDoubleValue(), 0.001);
    Assertions.assertEquals(3.5, ratingStat.getMax().getDoubleValue(), 0.001);
    Assertions.assertEquals(10.5 * repeatCount, ratingStat.getSum().getDoubleValue(), 0.001);
    Assertions.assertEquals(4L * repeatCount, ratingStat.getDocCount());
    Assertions.assertEquals(6L * repeatCount, ratingStat.getAllDocCount());
    Assertions.assertEquals(5L * repeatCount, ratingStat.getValueCount());
    search.clearStat();
    search.addStat(new StatFacet("rating", "normalFacet"));
    searchResult = zuliaWorkPool.search(search);
    List<FacetStats> ratingByFacet = searchResult.getFacetFieldStat("rating", "normalFacet");
    for (FacetStats facetStats : ratingByFacet) {
        if (facetStats.getFacet().equals("foo")) {
            Assertions.assertEquals(1, facetStats.getMin().getDoubleValue(), 0.001);
            Assertions.assertEquals(3.5, facetStats.getMax().getDoubleValue(), 0.001);
            Assertions.assertEquals(7L * repeatCount, facetStats.getSum().getDoubleValue(), 0.001);
            Assertions.assertEquals(2L * repeatCount, facetStats.getDocCount());
            Assertions.assertEquals(3L * repeatCount, facetStats.getAllDocCount());
            Assertions.assertEquals(3L * repeatCount, facetStats.getValueCount());
        } else if (facetStats.getFacet().equals("bar")) {
            Assertions.assertEquals(0.5, facetStats.getMin().getDoubleValue(), 0.001);
            Assertions.assertEquals(3.0, facetStats.getMax().getDoubleValue(), 0.001);
            Assertions.assertEquals(3.5 * repeatCount, facetStats.getSum().getDoubleValue(), 0.001);
            Assertions.assertEquals(2L * repeatCount, facetStats.getDocCount());
            Assertions.assertEquals(2L * repeatCount, facetStats.getAllDocCount());
            Assertions.assertEquals(2L * repeatCount, facetStats.getValueCount());
        } else {
            throw new AssertionFailedError("Unexpect facet <" + facetStats.getFacet() + ">");
        }
    }
    search.clearStat();
    search.addStat(new StatFacet("rating", "pathFacet"));
    searchResult = zuliaWorkPool.search(search);
    List<FacetStats> ratingByPathFacet = searchResult.getFacetFieldStat("rating", "pathFacet");
    for (FacetStats facetStats : ratingByPathFacet) {
        if (facetStats.getFacet().equals("top1")) {
            Assertions.assertEquals(1, facetStats.getMin().getDoubleValue(), 0.001);
            Assertions.assertEquals(3.5, facetStats.getMax().getDoubleValue(), 0.001);
            Assertions.assertEquals(7L * repeatCount, facetStats.getSum().getDoubleValue(), 0.001);
            Assertions.assertEquals(2L * repeatCount, facetStats.getDocCount());
            Assertions.assertEquals(3L * repeatCount, facetStats.getAllDocCount());
            Assertions.assertEquals(3L * repeatCount, facetStats.getValueCount());
        } else if (facetStats.getFacet().equals("top2")) {
            Assertions.assertEquals(0.5, facetStats.getMin().getDoubleValue(), 0.001);
            Assertions.assertEquals(0.5, facetStats.getMax().getDoubleValue(), 0.001);
            Assertions.assertEquals(0.5 * repeatCount, facetStats.getSum().getDoubleValue(), 0.001);
            Assertions.assertEquals(repeatCount, facetStats.getDocCount());
            Assertions.assertEquals(repeatCount, facetStats.getAllDocCount());
            Assertions.assertEquals(repeatCount, facetStats.getValueCount());
        } else if (facetStats.getFacet().equals("top3")) {
            Assertions.assertEquals(3.0, facetStats.getMin().getDoubleValue(), 0.001);
            Assertions.assertEquals(3.0, facetStats.getMax().getDoubleValue(), 0.001);
            Assertions.assertEquals(3.0 * repeatCount, facetStats.getSum().getDoubleValue(), 0.001);
            Assertions.assertEquals(repeatCount, facetStats.getDocCount());
            Assertions.assertEquals(repeatCount, facetStats.getValueCount());
        } else {
            throw new AssertionFailedError("Unexpect facet <" + facetStats.getFacet() + ">");
        }
    }
    search = new Search(STAT_TEST_INDEX);
    search.addStat(new StatFacet("authorCount", "pathFacet"));
    Search finalSearch = search;
    Assertions.assertThrows(Exception.class, () -> zuliaWorkPool.search(finalSearch), "Expecting: Search: Numeric field <authorCount> must be indexed as a SORTABLE numeric field");
}
Also used : Search(io.zulia.client.command.builder.Search) NumericStat(io.zulia.client.command.builder.NumericStat) FilterQuery(io.zulia.client.command.builder.FilterQuery) SearchResult(io.zulia.client.result.SearchResult) AssertionFailedError(org.opentest4j.AssertionFailedError) StatFacet(io.zulia.client.command.builder.StatFacet) MatchAllQuery(io.zulia.client.command.builder.MatchAllQuery) FacetStats(io.zulia.message.ZuliaQuery.FacetStats) TestMethodOrder(org.junit.jupiter.api.TestMethodOrder) Order(org.junit.jupiter.api.Order) Test(org.junit.jupiter.api.Test)

Example 8 with SearchResult

use of io.zulia.client.result.SearchResult in project zuliasearch by zuliaio.

the class AliasTest method confirm.

@Test
@Order(6)
public void confirm() throws Exception {
    Search search = new Search(ALIAS_TEST_INDEX);
    SearchResult searchResult = zuliaWorkPool.search(search);
    Assertions.assertEquals(repeatCount * 2 * uniqueDocs, searchResult.getTotalHits());
    search = new Search("someAlias");
    searchResult = zuliaWorkPool.search(search);
    Assertions.assertEquals(repeatCount * 2 * uniqueDocs, searchResult.getTotalHits());
    Assertions.assertThrows(Exception.class, () -> zuliaWorkPool.search(new Search("someAlias2")), "fail with index does not exist");
    zuliaWorkPool.createIndexAlias("someAlias2", ALIAS_TEST_INDEX);
    search = new Search("someAlias2");
    searchResult = zuliaWorkPool.search(search);
    Assertions.assertEquals(repeatCount * 2 * uniqueDocs, searchResult.getTotalHits());
    zuliaWorkPool.deleteIndexAlias("someAlias");
    Assertions.assertThrows(Exception.class, () -> zuliaWorkPool.search(new Search("someAlias")), "fail with index does not exist");
    zuliaWorkPool.createIndexAlias("someAlias2", ALIAS_TEST_INDEX);
    search = new Search("someAlias2");
    searchResult = zuliaWorkPool.search(search);
    Assertions.assertEquals(repeatCount * 2 * uniqueDocs, searchResult.getTotalHits());
    zuliaWorkPool.deleteIndexAlias("someAlias2");
    Assertions.assertThrows(Exception.class, () -> zuliaWorkPool.search(new Search("someAlias")), "fail with index does not exist");
}
Also used : Search(io.zulia.client.command.builder.Search) SearchResult(io.zulia.client.result.SearchResult) Order(org.junit.jupiter.api.Order) TestMethodOrder(org.junit.jupiter.api.TestMethodOrder) Test(org.junit.jupiter.api.Test)

Example 9 with SearchResult

use of io.zulia.client.result.SearchResult in project zuliasearch by zuliaio.

the class AliasTest method aliasSearchTest.

@Test
@Order(3)
public void aliasSearchTest() throws Exception {
    Search search = new Search(ALIAS_TEST_INDEX);
    SearchResult searchResult = zuliaWorkPool.search(search);
    Assertions.assertEquals(repeatCount * 2 * uniqueDocs, searchResult.getTotalHits());
    search = new Search("someAlias");
    searchResult = zuliaWorkPool.search(search);
    Assertions.assertEquals(repeatCount * 2 * uniqueDocs, searchResult.getTotalHits());
    search = new Search(ALIAS_TEST_INDEX);
    search.addQuery(new ScoredQuery("rating:[4.0 TO *]"));
    searchResult = zuliaWorkPool.search(search);
    Assertions.assertEquals(repeatCount * 2 * 3, searchResult.getTotalHits());
    search = new Search("someAlias");
    search.addQuery(new ScoredQuery("rating:[4.0 TO *]"));
    searchResult = zuliaWorkPool.search(search);
    Assertions.assertEquals(repeatCount * 2 * 3, searchResult.getTotalHits());
    GetNumberOfDocsResult numberOfDocs = zuliaWorkPool.getNumberOfDocs("someAlias");
    Assertions.assertEquals(repeatCount * 2 * uniqueDocs, numberOfDocs.getNumberOfDocs());
    GetFieldsResult getFields = zuliaWorkPool.getFields("someAlias");
    Assertions.assertEquals(3, getFields.getFieldNames().size());
    GetTermsResult getTermsResult = zuliaWorkPool.execute(new GetTerms("someAlias", "title"));
    Assertions.assertEquals(6, getTermsResult.getTerms().size());
    GetIndexesResult indexes = zuliaWorkPool.getIndexes();
    Assertions.assertEquals(1, indexes.getIndexNames().size());
    GetNodesResult nodes = zuliaWorkPool.getNodes();
    Assertions.assertEquals(1, nodes.getIndexAliases().size());
    FetchResult fetch = zuliaWorkPool.fetch(new Fetch("1", "someAlias"));
    Assertions.assertEquals("1", fetch.getDocument().getString("id"));
    GetIndexConfigResult indexConfig = zuliaWorkPool.getIndexConfig("someAlias");
    Assertions.assertEquals(indexConfig.getIndexConfig().getIndexName(), ALIAS_TEST_INDEX);
}
Also used : Fetch(io.zulia.client.command.Fetch) ScoredQuery(io.zulia.client.command.builder.ScoredQuery) GetNodesResult(io.zulia.client.result.GetNodesResult) FetchResult(io.zulia.client.result.FetchResult) GetIndexConfigResult(io.zulia.client.result.GetIndexConfigResult) Search(io.zulia.client.command.builder.Search) GetIndexesResult(io.zulia.client.result.GetIndexesResult) GetNumberOfDocsResult(io.zulia.client.result.GetNumberOfDocsResult) SearchResult(io.zulia.client.result.SearchResult) GetFieldsResult(io.zulia.client.result.GetFieldsResult) GetTerms(io.zulia.client.command.GetTerms) GetTermsResult(io.zulia.client.result.GetTermsResult) Order(org.junit.jupiter.api.Order) TestMethodOrder(org.junit.jupiter.api.TestMethodOrder) Test(org.junit.jupiter.api.Test)

Example 10 with SearchResult

use of io.zulia.client.result.SearchResult in project zuliasearch by zuliaio.

the class SortTest method ratingDoubleSort.

@Test
@Order(6)
public void ratingDoubleSort() throws Exception {
    SearchResult searchResult;
    Search search = new Search(INDEX_NAME).setAmount(10);
    String field = "ratingDouble";
    // default ascending missing first
    search.addSort(new Sort(field));
    searchResult = zuliaWorkPool.search(search);
    Assertions.assertNull(searchResult.getFirstDocument().get(field));
    search.clearSort();
    // default missing first
    search.addSort(new Sort(field).ascending());
    searchResult = zuliaWorkPool.search(search);
    Assertions.assertNull(searchResult.getFirstDocument().get(field));
    search.clearSort();
    search.addSort(new Sort(field).ascending().missingFirst());
    searchResult = zuliaWorkPool.search(search);
    Assertions.assertNull(searchResult.getFirstDocument().get(field));
    search.clearSort();
    search.addSort(new Sort(field).ascending().missingLast());
    searchResult = zuliaWorkPool.search(search);
    Assertions.assertEquals(1.1d, (double) searchResult.getFirstDocument().get(field), 0.001d);
    search.clearSort();
    // default missing first
    search.addSort(new Sort(field).descending());
    searchResult = zuliaWorkPool.search(search);
    Assertions.assertEquals(Float.MAX_VALUE + 1000000d, (double) searchResult.getFirstDocument().get(field), 0.001d);
    search.clearSort();
    search.addSort(new Sort(field).descending().missingFirst());
    searchResult = zuliaWorkPool.search(search);
    Assertions.assertEquals(Float.MAX_VALUE + 1000000d, (double) searchResult.getFirstDocument().get(field), 0.001d);
    search.clearSort();
    search.addSort(new Sort(field).descending().missingLast());
    searchResult = zuliaWorkPool.search(search);
    Assertions.assertNull(searchResult.getFirstDocument().get(field));
}
Also used : Search(io.zulia.client.command.builder.Search) Sort(io.zulia.client.command.builder.Sort) SearchResult(io.zulia.client.result.SearchResult) Order(org.junit.jupiter.api.Order) TestMethodOrder(org.junit.jupiter.api.TestMethodOrder) Test(org.junit.jupiter.api.Test)

Aggregations

SearchResult (io.zulia.client.result.SearchResult)26 Search (io.zulia.client.command.builder.Search)24 Order (org.junit.jupiter.api.Order)22 Test (org.junit.jupiter.api.Test)22 TestMethodOrder (org.junit.jupiter.api.TestMethodOrder)22 Sort (io.zulia.client.command.builder.Sort)14 FilterQuery (io.zulia.client.command.builder.FilterQuery)6 CountFacet (io.zulia.client.command.builder.CountFacet)5 ScoredQuery (io.zulia.client.command.builder.ScoredQuery)4 Reindex (io.zulia.client.command.Reindex)3 MatchAllQuery (io.zulia.client.command.builder.MatchAllQuery)3 ClientIndexConfig (io.zulia.client.config.ClientIndexConfig)3 FacetCount (io.zulia.message.ZuliaQuery.FacetCount)3 Document (org.bson.Document)3 AssertionFailedError (org.opentest4j.AssertionFailedError)3 NumericStat (io.zulia.client.command.builder.NumericStat)2 StatFacet (io.zulia.client.command.builder.StatFacet)2 GetFieldsResult (io.zulia.client.result.GetFieldsResult)2 GetIndexesResult (io.zulia.client.result.GetIndexesResult)2 GetNodesResult (io.zulia.client.result.GetNodesResult)2