Search in sources :

Example 1 with SearchResult

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);
}
Also used : QueryResponse(io.zulia.message.ZuliaServiceOuterClass.QueryResponse) ZuliaServiceGrpc(io.zulia.message.ZuliaServiceGrpc) SearchResult(io.zulia.client.result.SearchResult)

Example 2 with SearchResult

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));
}
Also used : Search(io.zulia.client.command.builder.Search) Sort(io.zulia.client.command.builder.Sort) SearchResult(io.zulia.client.result.SearchResult) Order(org.junit.jupiter.api.Order) TestMethodOrder(org.junit.jupiter.api.TestMethodOrder) Test(org.junit.jupiter.api.Test)

Example 3 with SearchResult

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());
}
Also used : TermQuery(io.zulia.client.command.builder.TermQuery) Search(io.zulia.client.command.builder.Search) FilterQuery(io.zulia.client.command.builder.FilterQuery) SearchResult(io.zulia.client.result.SearchResult) MatchAllQuery(io.zulia.client.command.builder.MatchAllQuery) Order(org.junit.jupiter.api.Order) TestMethodOrder(org.junit.jupiter.api.TestMethodOrder) Test(org.junit.jupiter.api.Test)

Example 4 with SearchResult

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);
}
Also used : ScoredQuery(io.zulia.client.command.builder.ScoredQuery) Search(io.zulia.client.command.builder.Search) ZuliaQuery(io.zulia.message.ZuliaQuery) Sort(io.zulia.client.command.builder.Sort) SearchResult(io.zulia.client.result.SearchResult) Order(org.junit.jupiter.api.Order) TestMethodOrder(org.junit.jupiter.api.TestMethodOrder) Test(org.junit.jupiter.api.Test)

Example 5 with SearchResult

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());
}
Also used : Search(io.zulia.client.command.builder.Search) FilterQuery(io.zulia.client.command.builder.FilterQuery) SearchResult(io.zulia.client.result.SearchResult) FacetCount(io.zulia.message.ZuliaQuery.FacetCount) CountFacet(io.zulia.client.command.builder.CountFacet) Order(org.junit.jupiter.api.Order) TestMethodOrder(org.junit.jupiter.api.TestMethodOrder) Test(org.junit.jupiter.api.Test)

Aggregations

SearchResult (io.zulia.client.result.SearchResult)26 Search (io.zulia.client.command.builder.Search)24 Order (org.junit.jupiter.api.Order)22 Test (org.junit.jupiter.api.Test)22 TestMethodOrder (org.junit.jupiter.api.TestMethodOrder)22 Sort (io.zulia.client.command.builder.Sort)14 FilterQuery (io.zulia.client.command.builder.FilterQuery)6 CountFacet (io.zulia.client.command.builder.CountFacet)5 ScoredQuery (io.zulia.client.command.builder.ScoredQuery)4 Reindex (io.zulia.client.command.Reindex)3 MatchAllQuery (io.zulia.client.command.builder.MatchAllQuery)3 ClientIndexConfig (io.zulia.client.config.ClientIndexConfig)3 FacetCount (io.zulia.message.ZuliaQuery.FacetCount)3 Document (org.bson.Document)3 AssertionFailedError (org.opentest4j.AssertionFailedError)3 NumericStat (io.zulia.client.command.builder.NumericStat)2 StatFacet (io.zulia.client.command.builder.StatFacet)2 GetFieldsResult (io.zulia.client.result.GetFieldsResult)2 GetIndexesResult (io.zulia.client.result.GetIndexesResult)2 GetNodesResult (io.zulia.client.result.GetNodesResult)2