Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Sort with runtime facet handler.

  • Loading branch information...
commit f684676223a681170521ba831cfd499d79addc0e 1 parent 88fc6a5
Zhuochuan Huang authored
View
41 bobo-browse/src/main/java/com/browseengine/bobo/api/BoboSubBrowser.java
@@ -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();
View
30 bobo-browse/src/main/java/com/browseengine/bobo/sort/SortCollector.java
@@ -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,7 +254,6 @@ 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;
@@ -257,19 +261,7 @@ public static SortCollector buildSortCollector(Browsable browser,Query q,SortFie
}
}
- 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){
View
23 bobo-browse/src/main/java/com/browseengine/bobo/sort/SortCollectorImpl.java
@@ -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
Owner

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

Please sign in to comment.
Something went wrong with that request. Please try again.