use of io.zulia.client.result.SearchResult in project zuliasearch by zuliaio.
the class StartStopTest method lengthTestBuilder.
@Test
@Order(3)
public void lengthTestBuilder() throws Exception {
Search s = new Search(FACET_TEST_INDEX);
SearchResult searchResult = zuliaWorkPool.search(s);
long total = searchResult.getTotalHits();
s = new Search(FACET_TEST_INDEX).addQuery(new FilterQuery("|country|:2"));
searchResult = zuliaWorkPool.search(s);
Assertions.assertEquals(total / 2, searchResult.getTotalHits());
s = new Search(FACET_TEST_INDEX).addQuery(new FilterQuery("|country|:[0 TO 1]"));
searchResult = zuliaWorkPool.search(s);
Assertions.assertEquals(0, searchResult.getTotalHits());
s = new Search(FACET_TEST_INDEX).addQuery(new FilterQuery("|||testList|||:3"));
searchResult = zuliaWorkPool.search(s);
Assertions.assertEquals(total / 2, searchResult.getTotalHits());
s = new Search(FACET_TEST_INDEX).addQuery(new FilterQuery("|||testList|||:[2 TO 3]"));
searchResult = zuliaWorkPool.search(s);
Assertions.assertEquals(total, searchResult.getTotalHits());
s = new Search(FACET_TEST_INDEX).setAmount((int) total / 2).addSort(new Sort("|country|"));
searchResult = zuliaWorkPool.search(s);
for (Document document : searchResult.getDocuments()) {
Assertions.assertEquals(document.getString("country"), "US");
}
s = new Search(FACET_TEST_INDEX).setAmount((int) total / 2).addSort(new Sort("|country|").descending());
searchResult = zuliaWorkPool.search(s);
for (Document document : searchResult.getDocuments()) {
Assertions.assertEquals(document.getString("country"), "France");
}
}
use of io.zulia.client.result.SearchResult 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.result.SearchResult in project zuliasearch by zuliaio.
the class AliasTest method confirm.
@Test
@Order(6)
public void confirm() throws Exception {
Search search = new Search(ALIAS_TEST_INDEX);
SearchResult searchResult = zuliaWorkPool.search(search);
Assertions.assertEquals(repeatCount * 2 * uniqueDocs, searchResult.getTotalHits());
search = new Search("someAlias");
searchResult = zuliaWorkPool.search(search);
Assertions.assertEquals(repeatCount * 2 * uniqueDocs, searchResult.getTotalHits());
Assertions.assertThrows(Exception.class, () -> zuliaWorkPool.search(new Search("someAlias2")), "fail with index does not exist");
zuliaWorkPool.createIndexAlias("someAlias2", ALIAS_TEST_INDEX);
search = new Search("someAlias2");
searchResult = zuliaWorkPool.search(search);
Assertions.assertEquals(repeatCount * 2 * uniqueDocs, searchResult.getTotalHits());
zuliaWorkPool.deleteIndexAlias("someAlias");
Assertions.assertThrows(Exception.class, () -> zuliaWorkPool.search(new Search("someAlias")), "fail with index does not exist");
zuliaWorkPool.createIndexAlias("someAlias2", ALIAS_TEST_INDEX);
search = new Search("someAlias2");
searchResult = zuliaWorkPool.search(search);
Assertions.assertEquals(repeatCount * 2 * uniqueDocs, searchResult.getTotalHits());
zuliaWorkPool.deleteIndexAlias("someAlias2");
Assertions.assertThrows(Exception.class, () -> zuliaWorkPool.search(new Search("someAlias")), "fail with index does not exist");
}
use of io.zulia.client.result.SearchResult in project zuliasearch by zuliaio.
the class AliasTest method aliasSearchTest.
@Test
@Order(3)
public void aliasSearchTest() throws Exception {
Search search = new Search(ALIAS_TEST_INDEX);
SearchResult searchResult = zuliaWorkPool.search(search);
Assertions.assertEquals(repeatCount * 2 * uniqueDocs, searchResult.getTotalHits());
search = new Search("someAlias");
searchResult = zuliaWorkPool.search(search);
Assertions.assertEquals(repeatCount * 2 * uniqueDocs, searchResult.getTotalHits());
search = new Search(ALIAS_TEST_INDEX);
search.addQuery(new ScoredQuery("rating:[4.0 TO *]"));
searchResult = zuliaWorkPool.search(search);
Assertions.assertEquals(repeatCount * 2 * 3, searchResult.getTotalHits());
search = new Search("someAlias");
search.addQuery(new ScoredQuery("rating:[4.0 TO *]"));
searchResult = zuliaWorkPool.search(search);
Assertions.assertEquals(repeatCount * 2 * 3, searchResult.getTotalHits());
GetNumberOfDocsResult numberOfDocs = zuliaWorkPool.getNumberOfDocs("someAlias");
Assertions.assertEquals(repeatCount * 2 * uniqueDocs, numberOfDocs.getNumberOfDocs());
GetFieldsResult getFields = zuliaWorkPool.getFields("someAlias");
Assertions.assertEquals(3, getFields.getFieldNames().size());
GetTermsResult getTermsResult = zuliaWorkPool.execute(new GetTerms("someAlias", "title"));
Assertions.assertEquals(6, getTermsResult.getTerms().size());
GetIndexesResult indexes = zuliaWorkPool.getIndexes();
Assertions.assertEquals(1, indexes.getIndexNames().size());
GetNodesResult nodes = zuliaWorkPool.getNodes();
Assertions.assertEquals(1, nodes.getIndexAliases().size());
FetchResult fetch = zuliaWorkPool.fetch(new Fetch("1", "someAlias"));
Assertions.assertEquals("1", fetch.getDocument().getString("id"));
GetIndexConfigResult indexConfig = zuliaWorkPool.getIndexConfig("someAlias");
Assertions.assertEquals(indexConfig.getIndexConfig().getIndexName(), ALIAS_TEST_INDEX);
}
use of io.zulia.client.result.SearchResult in project zuliasearch by zuliaio.
the class SortTest method ratingDoubleSort.
@Test
@Order(6)
public void ratingDoubleSort() throws Exception {
SearchResult searchResult;
Search search = new Search(INDEX_NAME).setAmount(10);
String field = "ratingDouble";
// 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(1.1d, (double) searchResult.getFirstDocument().get(field), 0.001d);
search.clearSort();
// default missing first
search.addSort(new Sort(field).descending());
searchResult = zuliaWorkPool.search(search);
Assertions.assertEquals(Float.MAX_VALUE + 1000000d, (double) searchResult.getFirstDocument().get(field), 0.001d);
search.clearSort();
search.addSort(new Sort(field).descending().missingFirst());
searchResult = zuliaWorkPool.search(search);
Assertions.assertEquals(Float.MAX_VALUE + 1000000d, (double) searchResult.getFirstDocument().get(field), 0.001d);
search.clearSort();
search.addSort(new Sort(field).descending().missingLast());
searchResult = zuliaWorkPool.search(search);
Assertions.assertNull(searchResult.getFirstDocument().get(field));
}
Aggregations