use of io.zulia.client.result.SearchResult in project zuliasearch by zuliaio.
the class Search method execute.
@Override
public SearchResult execute(ZuliaConnection zuliaConnection) {
ZuliaServiceGrpc.ZuliaServiceBlockingStub service = zuliaConnection.getService();
QueryResponse queryResponse = service.query(getRequest());
return new SearchResult(queryResponse);
}
use of io.zulia.client.result.SearchResult in project zuliasearch by zuliaio.
the class SortTest method boolSort.
@Test
@Order(7)
public void boolSort() throws Exception {
SearchResult searchResult;
Search search = new Search(INDEX_NAME).setAmount(10);
String field = "special";
// 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(false, searchResult.getFirstDocument().get(field));
search.clearSort();
// default missing first
search.addSort(new Sort(field).descending());
searchResult = zuliaWorkPool.search(search);
Assertions.assertEquals(true, searchResult.getFirstDocument().get(field));
search.clearSort();
search.addSort(new Sort(field).descending().missingFirst());
searchResult = zuliaWorkPool.search(search);
Assertions.assertEquals(true, searchResult.getFirstDocument().get(field));
search.clearSort();
search.addSort(new Sort(field).descending().missingLast());
searchResult = zuliaWorkPool.search(search);
Assertions.assertNull(searchResult.getFirstDocument().get(field));
}
use of io.zulia.client.result.SearchResult 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.result.SearchResult in project zuliasearch by zuliaio.
the class StartStopTest method sortScoreBuilder.
@Test
@Order(3)
public void sortScoreBuilder() throws Exception {
Search search = new Search(FACET_TEST_INDEX).setAmount(10);
search.addQuery(new ScoredQuery("issn:\"1234-1234\" OR country:US"));
search.addSort(new Sort(ZuliaConstants.SCORE_FIELD).ascending());
SearchResult searchResult = zuliaWorkPool.search(search);
double lowScore = -1;
double highScore = -1;
for (ZuliaQuery.ScoredResult result : searchResult.getResults()) {
Assertions.assertTrue(result.getScore() > 0);
if (lowScore < 0 || result.getScore() < lowScore) {
lowScore = result.getScore();
}
}
search.clearSort();
search.addSort(new Sort(ZuliaConstants.SCORE_FIELD).descending());
searchResult = zuliaWorkPool.search(search);
for (ZuliaQuery.ScoredResult result : searchResult.getResults()) {
Assertions.assertTrue(result.getScore() > 0);
if (highScore < 0 || result.getScore() > highScore) {
highScore = result.getScore();
}
}
Assertions.assertTrue(highScore > lowScore);
}
use of io.zulia.client.result.SearchResult in project zuliasearch by zuliaio.
the class StartStopTest method boolTestBuilder.
@Test
@Order(3)
public void boolTestBuilder() throws Exception {
Search s = new Search(FACET_TEST_INDEX).addQuery(new FilterQuery("testBool:true"));
SearchResult searchResult = zuliaWorkPool.search(s);
Assertions.assertEquals(6, searchResult.getTotalHits());
s = new Search(FACET_TEST_INDEX).addQuery(new FilterQuery("testBool:1"));
searchResult = zuliaWorkPool.search(s);
Assertions.assertEquals(6, searchResult.getTotalHits());
s = new Search(FACET_TEST_INDEX).addQuery(new FilterQuery("testBool:True"));
searchResult = zuliaWorkPool.search(s);
Assertions.assertEquals(6, searchResult.getTotalHits());
s = new Search(FACET_TEST_INDEX).addQuery(new FilterQuery("testBool:y"));
searchResult = zuliaWorkPool.search(s);
Assertions.assertEquals(6, searchResult.getTotalHits());
s = new Search(FACET_TEST_INDEX).addQuery(new FilterQuery("testBool:yes"));
searchResult = zuliaWorkPool.search(s);
Assertions.assertEquals(6, searchResult.getTotalHits());
s = new Search(FACET_TEST_INDEX).addQuery(new FilterQuery("testBool:false"));
searchResult = zuliaWorkPool.search(s);
Assertions.assertEquals(4, searchResult.getTotalHits());
s = new Search(FACET_TEST_INDEX).addQuery(new FilterQuery("testBool:0"));
searchResult = zuliaWorkPool.search(s);
Assertions.assertEquals(4, searchResult.getTotalHits());
s = new Search(FACET_TEST_INDEX).addQuery(new FilterQuery("testBool:no"));
searchResult = zuliaWorkPool.search(s);
Assertions.assertEquals(4, searchResult.getTotalHits());
s = new Search(FACET_TEST_INDEX).addQuery(new FilterQuery("testBool:f"));
searchResult = zuliaWorkPool.search(s);
Assertions.assertEquals(4, searchResult.getTotalHits());
s = new Search(FACET_TEST_INDEX).addQuery(new FilterQuery("testBool:fake"));
searchResult = zuliaWorkPool.search(s);
Assertions.assertEquals(0, searchResult.getTotalHits());
s = new Search(FACET_TEST_INDEX).addQuery(new FilterQuery("testBool:*"));
searchResult = zuliaWorkPool.search(s);
Assertions.assertEquals(10, searchResult.getTotalHits());
s = new Search(FACET_TEST_INDEX).addCountFacet(new CountFacet("testBool"));
searchResult = zuliaWorkPool.search(s);
List<FacetCount> facetCounts = searchResult.getFacetCounts("testBool");
Assertions.assertEquals(2, facetCounts.size());
Assertions.assertEquals(6, facetCounts.get(0).getCount());
Assertions.assertEquals("True", facetCounts.get(0).getFacet());
Assertions.assertEquals(4, facetCounts.get(1).getCount());
Assertions.assertEquals("False", facetCounts.get(1).getFacet());
}
Aggregations