Skip to content

Commit

Permalink
LPS-83506 portal-search-test-util: added searchCount test case for Fa…
Browse files Browse the repository at this point in the history
  • Loading branch information
wcao20170619 committed Aug 6, 2018
1 parent 7522ba6 commit 193a587
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ protected Hits doSearch(
}
}

protected long doSearchCount(SearchContext searchContext) {
return searchCount(searchContext);
}

protected abstract String getField();

protected Facet initFacet(Facet facet) {
Expand Down Expand Up @@ -131,6 +135,10 @@ public void search(QueryContributor queryContributor) {
_hits = doSearch(_searchContext, queryContributor);
}

public long searchCount() {
return doSearchCount(_searchContext);
}

public void setSearchContextAttribute(String name, Serializable value) {
_searchContext.setAttribute(name, value);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

import java.util.Arrays;

import org.junit.Assert;
import org.junit.Test;

/**
Expand Down Expand Up @@ -135,6 +136,26 @@ public void testMaxTermsZero() throws Exception {
});
}

@Test
public void testSearchCountSelection() throws Exception {
addDocuments(6, "one");
addDocuments(5, "two");
addDocuments(4, "three");
addDocuments(3, "four");
addDocuments(2, "five");

assertSearchFacet(
helper -> {
Facet facet = helper.addFacet(this::createFacet);

select(facet, "three", helper);

long count = helper.searchCount();

Assert.assertEquals(4, count);
});
}

@Test
public void testSelection() throws Exception {
addDocuments(6, "one");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,31 @@ protected Hits search(
return search(searchContext, _getQuery(queryContributor));
}

protected long searchCount(SearchContext searchContext) {
return searchCount(searchContext, getDefaultQuery());
}

protected long searchCount(SearchContext searchContext, Query query) {
try {
return _indexSearcher.searchCount(searchContext, query);
}
catch (SearchException se) {
Throwable t = se.getCause();

if (t instanceof RuntimeException) {
throw (RuntimeException)t;
}

throw new RuntimeException(se);
}
}

protected long searchCount(
SearchContext searchContext, QueryContributor queryContributor) {

return searchCount(searchContext, _getQuery(queryContributor));
}

protected void setPreBooleanFilter(Filter filter, Query query) {
BooleanFilter booleanFilter = new BooleanFilter();

Expand Down

0 comments on commit 193a587

Please sign in to comment.