Search in sources :

Example 6 with FilterQuery

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

the class StatTest method confirm.

@Test
@Order(6)
public void confirm() throws Exception {
    Search search = new Search(STAT_TEST_INDEX);
    search.addQuery(new FilterQuery("title:boring").exclude());
    search.addQuery(new MatchAllQuery());
    search.addStat(new NumericStat("authorCount"));
    SearchResult searchResult = zuliaWorkPool.search(search);
    FacetStats authorCountStats = searchResult.getNumericFieldStat("authorCount");
    Assertions.assertEquals(2, authorCountStats.getMin().getLongValue());
    Assertions.assertEquals(5, authorCountStats.getMax().getLongValue());
    Assertions.assertEquals(20L * repeatCount, authorCountStats.getSum().getLongValue());
    Assertions.assertEquals(6L * repeatCount, authorCountStats.getDocCount());
    Assertions.assertEquals(6L * repeatCount, authorCountStats.getValueCount());
    search.clearStat();
    search.addStat(new StatFacet("authorCount", "normalFacet"));
    searchResult = zuliaWorkPool.search(search);
    List<FacetStats> authorCountByNormalFacet = searchResult.getFacetFieldStat("authorCount", "normalFacet");
    for (FacetStats facetStats : authorCountByNormalFacet) {
        if (facetStats.getFacet().equals("foo")) {
            Assertions.assertEquals(2L, facetStats.getMin().getLongValue());
            Assertions.assertEquals(4L, facetStats.getMax().getLongValue());
            Assertions.assertEquals(9L * repeatCount, facetStats.getSum().getLongValue());
            Assertions.assertEquals(3L * repeatCount, facetStats.getDocCount());
            Assertions.assertEquals(3L * repeatCount, facetStats.getAllDocCount());
            Assertions.assertEquals(3L * repeatCount, facetStats.getValueCount());
        } else if (facetStats.getFacet().equals("bar")) {
            Assertions.assertEquals(2L, facetStats.getMin().getLongValue());
            Assertions.assertEquals(5L, facetStats.getMax().getLongValue());
            Assertions.assertEquals(7L * repeatCount, facetStats.getSum().getLongValue());
            Assertions.assertEquals(2L * repeatCount, facetStats.getDocCount());
            Assertions.assertEquals(2L * repeatCount, facetStats.getAllDocCount());
            Assertions.assertEquals(2L * repeatCount, facetStats.getValueCount());
        } else {
            throw new AssertionFailedError("Unexpected facet <" + facetStats.getFacet() + ">");
        }
    }
    search.clearStat();
    search.addStat(new StatFacet("authorCount", "pathFacet"));
    searchResult = zuliaWorkPool.search(search);
    List<FacetStats> ratingByPathFacet = searchResult.getFacetFieldStat("authorCount", "pathFacet");
    for (FacetStats facetStats : ratingByPathFacet) {
        if (facetStats.getFacet().equals("top1")) {
            Assertions.assertEquals(2L, facetStats.getMin().getLongValue());
            Assertions.assertEquals(4L, facetStats.getMax().getLongValue());
            Assertions.assertEquals(9L * repeatCount, facetStats.getSum().getLongValue());
            Assertions.assertEquals(3L * repeatCount, facetStats.getDocCount());
            Assertions.assertEquals(3L * repeatCount, facetStats.getAllDocCount());
            Assertions.assertEquals(3L * repeatCount, facetStats.getValueCount());
        } else if (facetStats.getFacet().equals("top2")) {
            Assertions.assertEquals(2L, facetStats.getMin().getLongValue());
            Assertions.assertEquals(2L, facetStats.getMax().getLongValue());
            Assertions.assertEquals(2L * repeatCount, facetStats.getSum().getLongValue());
            Assertions.assertEquals(repeatCount, facetStats.getDocCount());
            Assertions.assertEquals(repeatCount, facetStats.getAllDocCount());
            Assertions.assertEquals(repeatCount, facetStats.getValueCount());
        } else if (facetStats.getFacet().equals("top3")) {
            Assertions.assertEquals(4L, facetStats.getMin().getLongValue());
            Assertions.assertEquals(5L, facetStats.getMax().getLongValue());
            Assertions.assertEquals(9L * repeatCount, facetStats.getSum().getLongValue());
            Assertions.assertEquals(2L * repeatCount, facetStats.getDocCount());
            Assertions.assertEquals(2L * repeatCount, facetStats.getAllDocCount());
            Assertions.assertEquals(2L * repeatCount, facetStats.getValueCount());
        } else {
            throw new AssertionFailedError("Unexpected facet <" + facetStats.getFacet() + ">");
        }
    }
}
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)

Aggregations

FilterQuery (io.zulia.client.command.builder.FilterQuery)6 Search (io.zulia.client.command.builder.Search)6 SearchResult (io.zulia.client.result.SearchResult)6 Order (org.junit.jupiter.api.Order)5 Test (org.junit.jupiter.api.Test)5 TestMethodOrder (org.junit.jupiter.api.TestMethodOrder)5 MatchAllQuery (io.zulia.client.command.builder.MatchAllQuery)3 CountFacet (io.zulia.client.command.builder.CountFacet)2 NumericStat (io.zulia.client.command.builder.NumericStat)2 Sort (io.zulia.client.command.builder.Sort)2 StatFacet (io.zulia.client.command.builder.StatFacet)2 FacetStats (io.zulia.message.ZuliaQuery.FacetStats)2 Document (org.bson.Document)2 AssertionFailedError (org.opentest4j.AssertionFailedError)2 JCommander (com.beust.jcommander.JCommander)1 ParameterException (com.beust.jcommander.ParameterException)1 ClearIndex (io.zulia.client.command.ClearIndex)1 DeleteIndex (io.zulia.client.command.DeleteIndex)1 GetIndexes (io.zulia.client.command.GetIndexes)1 GetNodes (io.zulia.client.command.GetNodes)1