Search in sources :

Example 1 with MatchAllQuery

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

the class StartStopTest method termTestBuilder.

@Test
@Order(3)
public void termTestBuilder() throws Exception {
    Search s = new Search(FACET_TEST_INDEX);
    s.addQuery(new TermQuery("id").addTerms("1", "2", "3", "4"));
    SearchResult searchResult = zuliaWorkPool.search(s);
    Assertions.assertEquals(4, searchResult.getTotalHits());
    s = new Search(FACET_TEST_INDEX);
    s.addQuery(new TermQuery("id").addTerms(Arrays.asList("1", "2", "3", "4")));
    s.addQuery(new FilterQuery("testBool:true"));
    searchResult = zuliaWorkPool.search(s);
    Assertions.assertEquals(4, searchResult.getTotalHits());
    s = new Search(FACET_TEST_INDEX);
    s.addQuery(new TermQuery("id").addTerm("1").addTerm("2").addTerm("3").addTerm("4"));
    s.addQuery(new FilterQuery("country:US"));
    searchResult = zuliaWorkPool.search(s);
    Assertions.assertEquals(2, searchResult.getTotalHits());
    s = new Search(FACET_TEST_INDEX);
    s.addQuery(new TermQuery("id").addTerm("1").addTerm("2").addTerm("3").addTerm("4").exclude());
    s.addQuery(new FilterQuery("country:US"));
    searchResult = zuliaWorkPool.search(s);
    Assertions.assertEquals(28, searchResult.getTotalHits());
    s = new Search(FACET_TEST_INDEX);
    s.addQuery(new TermQuery("id").addTerm("1").addTerm("2").addTerm("3").addTerm("4").exclude());
    s.addQuery(new FilterQuery("country:US").exclude());
    // need to use match all because all other queries are negated
    s.addQuery(new MatchAllQuery());
    searchResult = zuliaWorkPool.search(s);
    Assertions.assertEquals(28, searchResult.getTotalHits());
}
Also used : TermQuery(io.zulia.client.command.builder.TermQuery) Search(io.zulia.client.command.builder.Search) FilterQuery(io.zulia.client.command.builder.FilterQuery) SearchResult(io.zulia.client.result.SearchResult) MatchAllQuery(io.zulia.client.command.builder.MatchAllQuery) Order(org.junit.jupiter.api.Order) TestMethodOrder(org.junit.jupiter.api.TestMethodOrder) Test(org.junit.jupiter.api.Test)

Example 2 with MatchAllQuery

use of io.zulia.client.command.builder.MatchAllQuery 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 3 with MatchAllQuery

use of io.zulia.client.command.builder.MatchAllQuery 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)3 MatchAllQuery (io.zulia.client.command.builder.MatchAllQuery)3 Search (io.zulia.client.command.builder.Search)3 SearchResult (io.zulia.client.result.SearchResult)3 Order (org.junit.jupiter.api.Order)3 Test (org.junit.jupiter.api.Test)3 TestMethodOrder (org.junit.jupiter.api.TestMethodOrder)3 NumericStat (io.zulia.client.command.builder.NumericStat)2 StatFacet (io.zulia.client.command.builder.StatFacet)2 FacetStats (io.zulia.message.ZuliaQuery.FacetStats)2 AssertionFailedError (org.opentest4j.AssertionFailedError)2 TermQuery (io.zulia.client.command.builder.TermQuery)1