Skip to content
This repository has been archived by the owner on Sep 19, 2023. It is now read-only.

Commit

Permalink
DATASOLR-209 - GroupOptions Interface Polishment
Browse files Browse the repository at this point in the history
renamed field groupCount to totalCount;
renamed getGroupRows to getLimit;
removed Group prefix from methods with exception of groupBy*, groupMain
and groupFacet;
introduced validation of rows and cachePercent parameters.
  • Loading branch information
franciscospaeth committed Oct 23, 2014
1 parent ff7f968 commit c489008
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -164,15 +164,15 @@ private void processGroupOptions(SolrQuery solrQuery, Query query) {
solrQuery.add(GroupParams.GROUP_CACHE_PERCENTAGE, String.valueOf(groupOptions.getCachePercent()));
}

if (groupOptions.getGroupRows() != null && groupOptions.getGroupRows() >= 0) {
solrQuery.set(GroupParams.GROUP_LIMIT, groupOptions.getGroupRows());
if (groupOptions.getLimit() != null && groupOptions.getLimit() >= 0) {
solrQuery.set(GroupParams.GROUP_LIMIT, groupOptions.getLimit());
}

if (groupOptions.getGroupOffset() != null && groupOptions.getGroupOffset() >= 0) {
solrQuery.set(GroupParams.GROUP_OFFSET, groupOptions.getGroupOffset());
if (groupOptions.getOffset() != null && groupOptions.getOffset() >= 0) {
solrQuery.set(GroupParams.GROUP_OFFSET, groupOptions.getOffset());
}

solrQuery.set(GroupParams.GROUP_TOTAL_COUNT, groupOptions.isGroupTotalCount());
solrQuery.set(GroupParams.GROUP_TOTAL_COUNT, groupOptions.isTotalCount());
solrQuery.set(GroupParams.GROUP_FACET, groupOptions.isGroupFacets());
solrQuery.set(GroupParams.GROUP_TRUNCATE, groupOptions.isTruncateFacets());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ static <T> Map<Object, GroupResult<T>> convertGroupQueryResponseToGroupResultMap

SolrDocumentList documentList = group.getResult();
List<T> beans = solrTemplate.convertSolrDocumentListToBeans(documentList, clazz);
Page<T> page = new PageImpl<T>(beans, query.getGroupOptions().getGroupPageRequest(), documentList.getNumFound());
Page<T> page = new PageImpl<T>(beans, query.getGroupOptions().getPageRequest(), documentList.getNumFound());
groupEntries.add(new SimpleGroupEntry<T>(group.getGroupValue(), page));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public class GroupOptions {

private boolean truncateFacets = false;
private boolean groupFacets = false;
private boolean groupCount = false;
private boolean totalCount = false;
private boolean groupMain = false;
private int cachePercent = DEFAULT_CACHE_PERCENT;

Expand Down Expand Up @@ -135,23 +135,23 @@ public List<Query> getGroupByQueries() {
* @param offset
* @return
*/
public GroupOptions setGroupOffset(Integer offset) {
public GroupOptions setOffset(Integer offset) {

this.offset = offset;
this.offset = offset == null ? null : Math.max(0, offset);
return this;
}

/**
* @return initial offset of each group
*/
public Integer getGroupOffset() {
public Integer getOffset() {
return offset;
}

/**
* @return the number of rows to return for each group.
*/
public Integer getGroupRows() {
public Integer getLimit() {
return limit;
}

Expand All @@ -161,7 +161,7 @@ public Integer getGroupRows() {
* @param limit
* @return
*/
public GroupOptions setGroupLimit(Integer limit) {
public GroupOptions setLimit(Integer limit) {

this.limit = limit;
return this;
Expand Down Expand Up @@ -201,17 +201,17 @@ public Sort getSort() {
* @param groupCount
* @return
*/
public GroupOptions setGroupTotalCount(boolean groupCount) {
public GroupOptions setTotalCount(boolean groupCount) {

this.groupCount = groupCount;
this.totalCount = groupCount;
return this;
}

/**
* @return whether the group count should be included in the response.
*/
public boolean isGroupTotalCount() {
return groupCount;
public boolean isTotalCount() {
return totalCount;
}

/**
Expand All @@ -222,7 +222,7 @@ public boolean isGroupTotalCount() {
*/
public GroupOptions setCachePercent(int cachePercent) {

this.cachePercent = cachePercent;
this.cachePercent = Math.max(0, Math.min(100, cachePercent));
return this;
}

Expand Down Expand Up @@ -255,7 +255,7 @@ public boolean isTruncateFacets() {
/**
* Defines whether field facet shall be computed in grouped fashion.
*
* @param truncateFacets
* @param groupFacets
* @return
*/
public GroupOptions setGroupFacets(boolean groupFacets) {
Expand Down Expand Up @@ -290,16 +290,16 @@ public boolean isGroupMain() {
return groupMain;
}

public Pageable getGroupPageRequest() {
public Pageable getPageRequest() {

if (this.limit == null && this.offset == null) {
return null;
}

int rows = this.limit != null ? this.limit : DEFAULT_GROUP_LIMIT;
int limit = this.limit != null ? this.limit : DEFAULT_GROUP_LIMIT;
int offset = this.offset != null ? this.offset : 0;

return new SolrPageRequest(rows != 0 ? offset / rows : 0, rows, this.sort);
return new SolrPageRequest(limit != 0 ? offset / limit : 0, limit, this.sort);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -1027,13 +1027,13 @@ public void testConstructGroupQueryWithAllPossibleParameters() {
SimpleQuery query = new SimpleQuery();
query.addCriteria(new SimpleStringCriteria("*:*"));
query.setGroupOptions(groupOptions);
groupOptions.setGroupOffset(1);
groupOptions.setGroupLimit(2);
groupOptions.setOffset(1);
groupOptions.setLimit(2);
groupOptions.addGroupByField("field_1");
groupOptions.addGroupByFunction(MaxFunction.max("field_1", "field_2"));
groupOptions.addGroupByQuery(new SimpleQuery("*:*"));
groupOptions.addSort(new Sort(Sort.Direction.DESC, "field_3"));
groupOptions.setGroupTotalCount(true);
groupOptions.setTotalCount(true);

SolrQuery solrQuery = queryParser.constructSolrQuery(query);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -813,7 +813,7 @@ public void testRegularGroupQuery() {
groupOptions.addGroupByFunction(f);
groupOptions.addGroupByQuery(q1);
groupOptions.addGroupByQuery(q2);
groupOptions.setGroupLimit(2);
groupOptions.setLimit(2);

// asserts result page
GroupPage<ExampleSolrBean> groupResultPage = solrTemplate.queryForGroupPage(groupQuery, ExampleSolrBean.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ public void testConvertGroupQueryResponseToGroupResultList() {
Mockito.when(groupCommand1.getNGroups()).thenReturn(2);

GroupOptions groupOptions = new GroupOptions();
groupOptions.setGroupLimit(1);
groupOptions.setLimit(1);

Mockito.when(query.getPageRequest()).thenReturn(new PageRequest(0, 1));
Mockito.when(query.getGroupOptions()).thenReturn(groupOptions);
Expand Down Expand Up @@ -503,7 +503,7 @@ public void testConvertGroupQueryResponseToGroupResultListWhenNoCountOfGroups()
Mockito.when(groupCommand1.getNGroups()).thenReturn(null);

GroupOptions groupOptions = new GroupOptions();
groupOptions.setGroupLimit(1);
groupOptions.setLimit(1);

Mockito.when(query.getPageRequest()).thenReturn(new PageRequest(0, 1));
Mockito.when(query.getGroupOptions()).thenReturn(groupOptions);
Expand Down

0 comments on commit c489008

Please sign in to comment.