Permalink
Browse files

Sort with runtime facet handler.

  • Loading branch information...
1 parent 88fc6a5 commit f684676223a681170521ba831cfd499d79addc0e Zhuochuan Huang committed Dec 17, 2012
@@ -54,6 +54,7 @@
import com.browseengine.bobo.search.BoboSearcher2;
import com.browseengine.bobo.search.FacetHitCollector;
import com.browseengine.bobo.sort.SortCollector;
+import com.browseengine.bobo.sort.SortCollectorImpl;
/**
* This class implements the browsing functionality.
@@ -231,28 +232,36 @@ public void browse(BrowseRequest req,
}
RuntimeFacetHandlerFactory<FacetHandlerInitializerParam,?> factory = (RuntimeFacetHandlerFactory<FacetHandlerInitializerParam, ?>) _runtimeFacetHandlerFactoryMap.get(facetName);
- try
+ try
+ {
+ FacetHandlerInitializerParam data = req.getFacethandlerData(facetName);
+ if (data == null)
+ data = FacetHandlerInitializerParam.EMPTY_PARAM;
+ if (data != FacetHandlerInitializerParam.EMPTY_PARAM || !factory.isLoadLazily())
{
-
- FacetHandlerInitializerParam data = req.getFacethandlerData(facetName);
- if (data == null)
- data = FacetHandlerInitializerParam.EMPTY_PARAM;
- if (data != FacetHandlerInitializerParam.EMPTY_PARAM || !factory.isLoadLazily())
+ RuntimeFacetHandler<?> facetHandler = factory.get(data);
+ if (facetHandler != null)
{
- RuntimeFacetHandler<?> facetHandler = factory.get(data);
- if (facetHandler != null)
- {
- _runtimeFacetHandlers.add(facetHandler); // add to a list so we close them after search
- this.setFacetHandler(facetHandler);
- }
+ _runtimeFacetHandlers.add(facetHandler); // add to a list so we close them after search
+ this.setFacetHandler(facetHandler);
}
}
- catch (IOException e)
- {
- throw new BrowseException("error trying to set FacetHandler : " + facetName+":"+e.getMessage(),e);
- }
+ }
+ catch (IOException e)
+ {
+ throw new BrowseException("error trying to set FacetHandler : " + facetName+":"+e.getMessage(),e);
+ }
}
// done initialize all RuntimeFacetHandlers with data supplied by user at run-time.
+
+ if (collector instanceof SortCollectorImpl)
+ {
+ SortCollectorImpl sc = (SortCollectorImpl)collector;
+ if (sc.getCompSource() == null)
+ {
+ sc.setComparatorSource(this, sc.getSortFields());
+ }
+ }
Set<String> fields = getFacetNames();
@@ -23,7 +23,6 @@
import java.util.Arrays;
import java.util.LinkedList;
import java.util.Locale;
-import java.util.Map;
import java.util.Set;
import javax.management.MBeanServer;
@@ -38,7 +37,6 @@
import com.browseengine.bobo.api.BoboCustomSortField;
import com.browseengine.bobo.api.BoboIndexReader;
-import com.browseengine.bobo.api.BoboSubBrowser;
import com.browseengine.bobo.api.Browsable;
import com.browseengine.bobo.api.BrowseHit;
import com.browseengine.bobo.api.FacetAccessible;
@@ -133,7 +131,13 @@ public CollectorContext(BoboIndexReader reader, int base, DocComparator comparat
protected Collector _collector = null;
protected final SortField[] _sortFields;
- protected final boolean _fetchStoredFields;
+
+ public SortField[] getSortFields()
+ {
+ return _sortFields;
+ }
+
+ protected final boolean _fetchStoredFields;
protected boolean _closed = false;
protected SortCollector(SortField[] sortFields,boolean fetchStoredFields){
@@ -189,7 +193,7 @@ private static DocComparatorSource getNonFacetComparatorSource(SortField sf){
}
}
- private static DocComparatorSource getComparatorSource(Browsable browser,SortField sf){
+ public static DocComparatorSource getComparatorSource(Browsable browser,SortField sf){
DocComparatorSource compSource = null;
if (SortField.FIELD_DOC.equals(sf)){
compSource = new DocIdDocComparatorSource();
@@ -225,7 +229,7 @@ else if (sf instanceof BoboCustomSortField){
return compSource;
}
- private static SortField convert(Browsable browser,SortField sort){
+ public static SortField convert(Browsable browser,SortField sort){
String field =sort.getField();
FacetHandler<?> facetHandler = browser.getFacetHandler(field);
if (facetHandler!=null){
@@ -237,6 +241,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){
boolean doScoring=forceScoring;
if (sort == null || sort.length==0){
@@ -249,27 +254,14 @@ public static SortCollector buildSortCollector(Browsable browser,Query q,SortFie
sort = new SortField[]{SortField.FIELD_DOC};
}
- Set<String> facetNames = browser.getFacetNames();
for (SortField sf : sort){
if (sf.getType() == SortField.SCORE) {
doScoring= true;
break;
}
}
- DocComparatorSource compSource;
- if (sort.length==1){
- SortField sf = convert(browser,sort[0]);
- compSource = getComparatorSource(browser,sf);
- }
- else{
- DocComparatorSource[] compSources = new DocComparatorSource[sort.length];
- for (int i = 0; i<sort.length;++i){
- compSources[i]=getComparatorSource(browser,convert(browser,sort[i]));
- }
- compSource = new MultiDocIdComparatorSource(compSources);
- }
- return new SortCollectorImpl(compSource, sort, browser, offset, count, doScoring, fetchStoredFields, termVectorsToFetch,groupBy, maxPerGroup, collectDocIdCache);
+ return new SortCollectorImpl(null, sort, browser, offset, count, doScoring, fetchStoredFields, termVectorsToFetch,groupBy, maxPerGroup, collectDocIdCache);
}
public SortCollector setCollector(Collector collector){
@@ -540,4 +540,27 @@ public int getTotalGroups(){
}
return hits;
}
+
+ public void setComparatorSource(Browsable browser, SortField[] sort)
+ {
+ if (sort.length == 1)
+ {
+ SortField sf = convert(browser,sort[0]);
+ _compSource = getComparatorSource(browser,sf);
+ }
+ else
+ {
+ DocComparatorSource[] compSources = new DocComparatorSource[sort.length];
+ for (int i = 0; i < sort.length; ++ i)
+ {
+ compSources[i] = getComparatorSource(browser,convert(browser,sort[i]));
+ }
+ _compSource = new MultiDocIdComparatorSource(compSources);
+ }
+ }
+
+ public DocComparatorSource getCompSource()
+ {
+ return _compSource;
+ }
}

1 comment on commit f684676

hyan commented on f684676 Dec 18, 2012

It looks fine to me. The main change is to move setComparatorSource after put runtimefacethanler available to getFacetHandler().

Please sign in to comment.