Skip to content

Commit

Permalink
API and collector changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
wonlay committed Feb 23, 2012
1 parent 9d32280 commit 5a63d65
Show file tree
Hide file tree
Showing 7 changed files with 156 additions and 87 deletions.
Expand Up @@ -390,7 +390,7 @@ public void browse(BrowseRequest req,
}
}

public SortCollector getSortCollector(SortField[] sort,Query q,int offset,int count,boolean fetchStoredFields,Set<String> termVectorsToFetch,boolean forceScoring,String groupBy, int maxPerGroup, boolean collectDocIdCache){
public SortCollector getSortCollector(SortField[] sort,Query q,int offset,int count,boolean fetchStoredFields,Set<String> termVectorsToFetch,boolean forceScoring,String[] groupBy, int maxPerGroup, boolean collectDocIdCache){
return SortCollector.buildSortCollector(this,q,sort, offset, count, forceScoring,fetchStoredFields, termVectorsToFetch,groupBy, maxPerGroup, collectDocIdCache);
}

Expand Down Expand Up @@ -443,7 +443,7 @@ public BrowseResult browse(BrowseRequest req) throws BrowseException
result.setHits(hits);
result.setNumHits(collector.getTotalHits());
result.setNumGroups(collector.getTotalGroups());
result.setGroupAccessible(collector.getGroupAccessible());
result.setGroupAccessibles(collector.getGroupAccessibles());
result.setSortCollector(collector);
result.setTotalDocs(_reader.numDocs());
result.addAll(facetCollectors);
Expand Down
Expand Up @@ -54,7 +54,7 @@ void browse(BrowseRequest req,

int numDocs();

SortCollector getSortCollector(SortField[] sort,Query q,int offset,int count,boolean fetchStoredFields,Set<String> termVectorsToFetch,boolean forceScoring, String groupBy, int maxPerGroup, boolean collectDocIdCache);
SortCollector getSortCollector(SortField[] sort,Query q,int offset,int count,boolean fetchStoredFields,Set<String> termVectorsToFetch,boolean forceScoring, String[] groupBy, int maxPerGroup, boolean collectDocIdCache);

Explanation explain(Query q, int docid) throws IOException;
}
Expand Up @@ -80,7 +80,8 @@ public final void setTid(long tid)
private boolean _fetchStoredFields;
private Filter _filter;
private boolean _showExplanation;
private String _groupBy;
private String _groupBy; // TODO: Leave here for backward compatible reason, will remove it later.
private String[] _groupByMulti;
private int _maxPerGroup;
private boolean _collectDocIdCache;
private Set<String> _termVectorsToFetch;
Expand Down Expand Up @@ -189,6 +190,7 @@ public BrowseRequest() {
_filter = null;
_fetchStoredFields = false;
_groupBy = null;
_groupByMulti = null;
_maxPerGroup = 0;
_collectDocIdCache = false;
}
Expand All @@ -207,12 +209,18 @@ public BrowseRequest setFetchStoredFields(boolean fetchStoredFields){
return this;
}

public String getGroupBy(){
return _groupBy;
public String[] getGroupBy(){
if (_groupByMulti == null && _groupBy != null)
_groupByMulti = new String[]{_groupBy};

return _groupByMulti;
}

public BrowseRequest setGroupBy(String groupBy){
_groupBy = groupBy;
public BrowseRequest setGroupBy(String[] groupBy){
_groupByMulti = groupBy;
if (_groupByMulti != null && _groupByMulti.length != 0)
_groupBy = _groupByMulti[0];

return this;
}

Expand Down
Expand Up @@ -68,7 +68,7 @@ public final void setTid(long tid)
private int numHits;
private int numGroups;
private int totalDocs;
private FacetAccessible _groupAccessible;
private FacetAccessible[] _groupAccessibles;
transient private SortCollector _sortCollector;
//private int totalGroups;
private Map<String,FacetAccessible> _facetMap;
Expand All @@ -83,7 +83,7 @@ public final void setTid(long tid)
public BrowseResult() {
super();
_facetMap=new HashMap<String,FacetAccessible>();
_groupAccessible = null;
_groupAccessibles = null;
_sortCollector = null;
numHits=0;
numGroups=0;
Expand All @@ -97,16 +97,16 @@ public BrowseResult() {
* Get the group accessible.
* @return the group accessible.
*/
public FacetAccessible getGroupAccessible() {
return _groupAccessible;
public FacetAccessible[] getGroupAccessibles() {
return _groupAccessibles;
}

/**
* Set the group accessible.
* @param groupAccessible the group accessible.
*/
public BrowseResult setGroupAccessible(FacetAccessible groupAccessible) {
_groupAccessible = groupAccessible;
public BrowseResult setGroupAccessibles(FacetAccessible[] groupAccessibles) {
_groupAccessibles = groupAccessibles;
return this;
}

Expand Down Expand Up @@ -315,8 +315,14 @@ public String toString(){

public void close()
{
if (_groupAccessible != null)
_groupAccessible.close();
if (_groupAccessibles != null)
{
for(FacetAccessible accessible : _groupAccessibles)
{
if (accessible != null)
accessible.close();
}
}
if (_sortCollector != null)
_sortCollector.close();
if (_facetMap == null) return;
Expand Down
Expand Up @@ -208,7 +208,7 @@ public BrowseResult browse(BrowseRequest req) throws BrowseException
result.setHits(hits);
result.setNumHits(collector.getTotalHits());
result.setNumGroups(collector.getTotalGroups());
result.setGroupAccessible(collector.getGroupAccessible());
result.setGroupAccessibles(collector.getGroupAccessibles());
result.setSortCollector(collector);
result.setTotalDocs(numDocs());
result.addAll(facetCollectors);
Expand Down Expand Up @@ -344,7 +344,7 @@ public void setFacetHandler(FacetHandler<?> facetHandler) throws IOException
}

public SortCollector getSortCollector(SortField[] sort, Query q,int offset, int count, boolean fetchStoredFields, Set<String> termVectorsToFetch,
boolean forceScoring, String groupBy, int maxPerGroup, boolean collectDocIdCache) {
boolean forceScoring, String[] groupBy, int maxPerGroup, boolean collectDocIdCache) {
if (_subBrowsers.length==1){
return _subBrowsers[0].getSortCollector(sort, q, offset, count, fetchStoredFields, termVectorsToFetch,forceScoring, groupBy, maxPerGroup, collectDocIdCache);
}
Expand Down
Expand Up @@ -103,7 +103,8 @@ public CollectorContext(BoboIndexReader reader, int base, DocComparator comparat
}
}

public FacetHandler<?> groupBy;
public FacetHandler<?> groupBy = null; // Point to the first element of groupByMulti to avoid array lookups.
public FacetHandler<?>[] groupByMulti = null;

public LinkedList<CollectorContext> contextList;
public LinkedList<int[]> docidarraylist;
Expand All @@ -125,7 +126,7 @@ protected SortCollector(SortField[] sortFields,boolean fetchStoredFields){

abstract public int getTotalHits();
abstract public int getTotalGroups();
abstract public FacetAccessible getGroupAccessible();
abstract public FacetAccessible[] getGroupAccessibles();

private static DocComparatorSource getNonFacetComparatorSource(SortField sf){
String fieldname = sf.getField();
Expand Down Expand Up @@ -217,7 +218,7 @@ private static SortField convert(Browsable browser,SortField sort){
return sort;
}
}
public static SortCollector buildSortCollector(Browsable browser,Query q,SortField[] sort,int offset,int count,boolean forceScoring,boolean fetchStoredFields, Set<String> termVectorsToFetch,String groupBy, int maxPerGroup, boolean collectDocIdCache){
public static SortCollector buildSortCollector(Browsable browser,Query q,SortField[] sort,int offset,int count,boolean forceScoring,boolean fetchStoredFields, Set<String> termVectorsToFetch,String[] groupBy, int maxPerGroup, boolean collectDocIdCache){
boolean doScoring=forceScoring;
if (sort == null || sort.length==0){
if (q!=null && !(q instanceof MatchAllDocsQuery)){
Expand Down

0 comments on commit 5a63d65

Please sign in to comment.