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());
}
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");
}
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() + ">");
}
}
}
Aggregations