use of io.zulia.client.command.builder.Search in project zuliasearch by zuliaio.
the class StartStopTest method reindex.
@Test
@Order(4)
public void reindex() throws Exception {
ClientIndexConfig indexConfig = new ClientIndexConfig();
indexConfig.addDefaultSearchField("title");
indexConfig.addFieldConfig(FieldConfigBuilder.create("id", FieldType.STRING).indexAs(DefaultAnalyzers.LC_KEYWORD).sort());
indexConfig.addFieldConfig(FieldConfigBuilder.create("title", FieldType.STRING).indexAs(DefaultAnalyzers.STANDARD).sort());
indexConfig.addFieldConfig(FieldConfigBuilder.create("issn", FieldType.STRING).indexAs(DefaultAnalyzers.LC_KEYWORD).facet().sort());
indexConfig.addFieldConfig(FieldConfigBuilder.create("eissn", FieldType.STRING).indexAs(DefaultAnalyzers.LC_KEYWORD).facet());
indexConfig.addFieldConfig(FieldConfigBuilder.create("uid", FieldType.STRING).indexAs(DefaultAnalyzers.LC_KEYWORD));
indexConfig.addFieldConfig(FieldConfigBuilder.create("an", FieldType.NUMERIC_INT).index().displayName("Accession Number").sort());
indexConfig.addFieldConfig(FieldConfigBuilder.create("country", FieldType.STRING).indexAs(DefaultAnalyzers.LC_KEYWORD).facet().sort());
indexConfig.addFieldConfig(FieldConfigBuilder.create("date", FieldType.DATE).index().facetAs(DateHandling.DATE_YYYY_MM_DD).description("The very special data").sort());
indexConfig.addFieldConfig(FieldConfigBuilder.create("testList", FieldType.STRING).index());
indexConfig.setIndexName(FACET_TEST_INDEX);
indexConfig.setNumberOfShards(1);
zuliaWorkPool.createIndex(indexConfig);
zuliaWorkPool.reindex(new Reindex(FACET_TEST_INDEX));
Search search = new Search(FACET_TEST_INDEX).addCountFacet(new CountFacet("eissn"));
SearchResult searchResult = zuliaWorkPool.search(search);
List<FacetCount> eissnCounts = searchResult.getFacetCounts("eissn");
Assertions.assertEquals(eissns.length, eissnCounts.size());
for (FacetCount eissnCount : eissnCounts) {
Assertions.assertEquals(COUNT_PER_ISSN, eissnCount.getCount());
}
}
use of io.zulia.client.command.builder.Search 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() + ">");
}
}
}
use of io.zulia.client.command.builder.Search in project zuliasearch by zuliaio.
the class HierarchicalFacetTest method facetTest.
@Test
@Order(3)
public void facetTest() throws Exception {
Search search = new Search(FACET_TEST_INDEX);
search.addCountFacet(new CountFacet("path"));
search.addCountFacet(new CountFacet("date"));
SearchResult queryResult = zuliaWorkPool.search(search);
List<FacetCount> paths = queryResult.getFacetCounts("path");
for (FacetCount path : paths) {
if (path.getFacet().equals("1")) {
Assertions.assertEquals(30, path.getCount());
} else if (path.getFacet().equals("a")) {
Assertions.assertEquals(20, path.getCount());
} else if (path.getFacet().equals("2")) {
Assertions.assertEquals(10, path.getCount());
} else if (path.getFacet().equals("3")) {
Assertions.assertEquals(10, path.getCount());
} else if (path.getFacet().equals("4")) {
Assertions.assertEquals(10, path.getCount());
} else if (path.getFacet().equals("one")) {
Assertions.assertEquals(10, path.getCount());
} else {
throw new AssertionFailedError("Unexpect path <" + path.getFacet() + ">");
}
}
paths = queryResult.getFacetCounts("date");
for (FacetCount path : paths) {
if (path.getFacet().equals("2012")) {
Assertions.assertEquals(45, path.getCount());
} else if (path.getFacet().equals("2013")) {
Assertions.assertEquals(36, path.getCount());
} else if (path.getFacet().equals("2014")) {
Assertions.assertEquals(9, path.getCount());
} else {
throw new AssertionFailedError("Unexpect path <" + path.getFacet() + ">");
}
}
search = new Search(FACET_TEST_INDEX);
search.addCountFacet(new CountFacet("path", "1"));
search.addCountFacet(new CountFacet("path", "2"));
queryResult = zuliaWorkPool.search(search);
paths = queryResult.getFacetCountsForPath("path", "1");
for (FacetCount path : paths) {
if (path.getFacet().equals("2")) {
Assertions.assertEquals(10, path.getCount());
} else if (path.getFacet().equals("3")) {
Assertions.assertEquals(10, path.getCount());
} else {
throw new AssertionFailedError("Unexpect path <" + path.getFacet() + ">");
}
}
paths = queryResult.getFacetCountsForPath("path", "2");
for (FacetCount path : paths) {
if (path.getFacet().equals("3")) {
Assertions.assertEquals(10, path.getCount());
} else {
throw new AssertionFailedError("Unexpect path <" + path.getFacet() + ">");
}
}
search = new Search(FACET_TEST_INDEX);
search.addCountFacet(new CountFacet("path", "one", "two"));
queryResult = zuliaWorkPool.search(search);
paths = queryResult.getFacetCountsForPath("path", "one", "two");
for (FacetCount path : paths) {
if (path.getFacet().equals("three")) {
Assertions.assertEquals(10, path.getCount());
} else {
throw new AssertionFailedError("Unexpect path <" + path.getFacet() + ">");
}
}
search = new Search(FACET_TEST_INDEX);
search.addCountFacet(new CountFacet("path2"));
Search finalSearch = search;
Assertions.assertThrows(Exception.class, () -> zuliaWorkPool.search(finalSearch), "path2 is not defined as a facetable field");
}
use of io.zulia.client.command.builder.Search in project zuliasearch by zuliaio.
the class HierarchicalFacetTest method confirm.
@Test
@Order(6)
public void confirm() throws Exception {
Search search = new Search(FACET_TEST_INDEX);
String pathField = "path2";
search.addCountFacet(new CountFacet(pathField));
search.addCountFacet(new CountFacet("date"));
SearchResult queryResult = zuliaWorkPool.search(search);
List<FacetCount> paths = queryResult.getFacetCounts(pathField);
for (FacetCount path : paths) {
if (path.getFacet().equals("1")) {
Assertions.assertEquals(30, path.getCount());
} else if (path.getFacet().equals("a")) {
Assertions.assertEquals(20, path.getCount());
} else if (path.getFacet().equals("2")) {
Assertions.assertEquals(10, path.getCount());
} else if (path.getFacet().equals("3")) {
Assertions.assertEquals(10, path.getCount());
} else if (path.getFacet().equals("4")) {
Assertions.assertEquals(10, path.getCount());
} else if (path.getFacet().equals("one")) {
Assertions.assertEquals(10, path.getCount());
} else {
throw new AssertionFailedError("Unexpect path <" + path.getFacet() + ">");
}
}
paths = queryResult.getFacetCounts("date");
for (FacetCount path : paths) {
if (path.getFacet().equals("2012")) {
Assertions.assertEquals(45, path.getCount());
} else if (path.getFacet().equals("2013")) {
Assertions.assertEquals(36, path.getCount());
} else if (path.getFacet().equals("2014")) {
Assertions.assertEquals(9, path.getCount());
} else {
throw new AssertionFailedError("Unexpect path <" + path.getFacet() + ">");
}
}
search = new Search(FACET_TEST_INDEX);
search.addCountFacet(new CountFacet(pathField, "1"));
queryResult = zuliaWorkPool.search(search);
paths = queryResult.getFacetCountsForPath(pathField, "1");
for (FacetCount path : paths) {
if (path.getFacet().equals("2")) {
Assertions.assertEquals(10, path.getCount());
} else if (path.getFacet().equals("3")) {
Assertions.assertEquals(10, path.getCount());
} else {
throw new AssertionFailedError("Unexpect path <" + path.getFacet() + ">");
}
}
search = new Search(FACET_TEST_INDEX);
search.addCountFacet(new CountFacet(pathField, "one", "two"));
queryResult = zuliaWorkPool.search(search);
paths = queryResult.getFacetCountsForPath(pathField, "one", "two");
for (FacetCount path : paths) {
if (path.getFacet().equals("three")) {
Assertions.assertEquals(10, path.getCount());
} else {
throw new AssertionFailedError("Unexpect path <" + path.getFacet() + ">");
}
}
}
use of io.zulia.client.command.builder.Search in project zuliasearch by zuliaio.
the class SortTest method dateSort.
@Test
@Order(8)
public void dateSort() throws Exception {
SearchResult searchResult;
Search search = new Search(INDEX_NAME).setAmount(10);
String field = "added";
// 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(Date.from(LocalDate.of(1951, Month.DECEMBER, 20).atStartOfDay(ZoneId.of("UTC")).toInstant()), searchResult.getFirstDocument().get(field));
search.clearSort();
// default missing first
search.addSort(new Sort(field).descending());
searchResult = zuliaWorkPool.search(search);
Assertions.assertEquals(Date.from(LocalDate.of(2020, Month.JANUARY, 31).atStartOfDay(ZoneId.of("UTC")).toInstant()), searchResult.getFirstDocument().get(field));
search.clearSort();
search.addSort(new Sort(field).descending().missingFirst());
searchResult = zuliaWorkPool.search(search);
Assertions.assertEquals(Date.from(LocalDate.of(2020, Month.JANUARY, 31).atStartOfDay(ZoneId.of("UTC")).toInstant()), searchResult.getFirstDocument().get(field));
search.clearSort();
search.addSort(new Sort(field).descending().missingLast());
searchResult = zuliaWorkPool.search(search);
Assertions.assertNull(searchResult.getFirstDocument().get(field));
}
Aggregations