use of io.zulia.client.result.SearchResult in project zuliasearch by zuliaio.
the class SortTest method reindexTest.
@Test
@Order(13)
public void reindexTest() throws Exception {
ClientIndexConfig indexConfig = new ClientIndexConfig();
indexConfig.addDefaultSearchField("title");
indexConfig.addFieldConfig(FieldConfigBuilder.create("id", FieldType.STRING).indexAs(DefaultAnalyzers.LC_KEYWORD).sortAs(// change sort as to be theId instead of just id
"theId"));
indexConfig.addFieldConfig(FieldConfigBuilder.create("title", FieldType.STRING).indexAs(DefaultAnalyzers.STANDARD).sort());
// no longer sortable
indexConfig.addFieldConfig(FieldConfigBuilder.create("stars", FieldType.NUMERIC_INT).index());
indexConfig.addFieldConfig(FieldConfigBuilder.create("starsLong", FieldType.NUMERIC_LONG).index().sort());
// indexConfig.addFieldConfig(FieldConfigBuilder.create("rating", FieldType.NUMERIC_FLOAT).index().sort()); // no longer indexed or sortable
indexConfig.addFieldConfig(FieldConfigBuilder.create("ratingDouble", FieldType.NUMERIC_FLOAT).index().sort());
indexConfig.addFieldConfig(FieldConfigBuilder.create("special", FieldType.BOOL).index().sort());
indexConfig.addFieldConfig(FieldConfigBuilder.create("added", FieldType.DATE).index().sort());
// sort() adds standard string (case senstive sorting with a field name the same as the stored field
// sortAs(LOWERCASE_FOLDING, "otherTitleFolding") add another sortable field with a lowercase and ascii folding filter applied to make case insensitive sort and fancy letter insensitive (gotta be a better term here)
indexConfig.addFieldConfig(FieldConfigBuilder.create("otherTitle", FieldType.STRING).index().sort().sortAs(LOWERCASE_FOLDING, "otherTitleFolding"));
indexConfig.setIndexName(INDEX_NAME);
indexConfig.setNumberOfShards(1);
// force some commits
indexConfig.setShardCommitInterval(20);
zuliaWorkPool.createIndex(indexConfig);
zuliaWorkPool.reindex(new Reindex(INDEX_NAME));
SearchResult searchResult;
Search search = new Search(INDEX_NAME).setAmount(1);
search.addSort(new Sort("otherTitle").ascending().missingLast());
searchResult = zuliaWorkPool.search(search);
Assertions.assertEquals("Blah", searchResult.getFirstDocument().get("otherTitle"));
search.clearSort();
search.addSort(new Sort("otherTitleFolding").ascending().missingLast());
search.addSort(new Sort("starts").ascending().missingLast());
searchResult = zuliaWorkPool.search(search);
Assertions.assertEquals("blah", searchResult.getFirstDocument().get("otherTitle"));
search.clearSort();
search.addSort(new Sort("otherTitle").descending());
searchResult = zuliaWorkPool.search(search);
Assertions.assertEquals("still more blah", searchResult.getFirstDocument().get("otherTitle"));
search.clearSort();
// use the new sort as id field
search.addSort(new Sort("theId").descending());
searchResult = zuliaWorkPool.search(search);
// sorting as string so this is 99 instead of 199
Assertions.assertEquals("99", searchResult.getFirstDocument().get("id"));
}
use of io.zulia.client.result.SearchResult 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.result.SearchResult 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.result.SearchResult 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.result.SearchResult 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() + ">");
}
}
}
Aggregations