Search in sources :

Example 1 with TermQuery

use of io.zulia.client.command.builder.TermQuery 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)

Aggregations

FilterQuery (io.zulia.client.command.builder.FilterQuery)1 MatchAllQuery (io.zulia.client.command.builder.MatchAllQuery)1 Search (io.zulia.client.command.builder.Search)1 TermQuery (io.zulia.client.command.builder.TermQuery)1 SearchResult (io.zulia.client.result.SearchResult)1 Order (org.junit.jupiter.api.Order)1 Test (org.junit.jupiter.api.Test)1 TestMethodOrder (org.junit.jupiter.api.TestMethodOrder)1