Permalink
Browse files

Make virtual facet loading more efficent.

  • Loading branch information...
1 parent 90c1623 commit c00ea4f4ec43ef7dd8e5c8c2483fa784a0298c3b @wonlay wonlay committed Oct 29, 2012
@@ -434,6 +434,14 @@ private void loadFacetHandlers(WorkArea workArea, Set<String> toBeRemoved) throw
loadFacetHandler(name, loaded, visited, workArea);
}
+ for (FacetHandler<?> handler : _facetHandlerMap.values())
+ {
+ if (handler != null)
+ {
+ handler.cleanup(this);
+ }
+ }
+
for(String name : toBeRemoved)
{
_facetHandlerMap.remove(name);
@@ -306,6 +306,15 @@ public String getFieldValue(BoboIndexReader reader,int id)
* @return a sort comparator
*/
abstract public DocComparatorSource getDocComparatorSource();
+
+ /**
+ * Do some necessary cleanup work after load
+ * @param reader
+ */
+ public void cleanup(BoboIndexReader reader)
+ {
+ // do nothing
+ }
@Override
public Object clone() throws CloneNotSupportedException
@@ -27,6 +27,11 @@ public boolean add(String o) {
}
@Override
+ public boolean addRaw(Object o) {
+ return ((CharArrayList)_innerList).add((char)(Character)o);
+ }
+
+ @Override
protected List<?> buildPrimitiveList(int capacity) {
_type = Character.class;
return capacity>0 ? new CharArrayList(capacity) : new CharArrayList();
@@ -43,6 +43,12 @@ public boolean add(String o)
return ((DoubleArrayList) _innerList).add(parse(o));
}
+ @Override
+ public boolean addRaw(Object o)
+ {
+ return ((DoubleArrayList) _innerList).add(((Number)o).doubleValue());
+ }
+
@Override
protected List<?> buildPrimitiveList(int capacity)
{
@@ -57,13 +57,19 @@ public TermFixedLengthLongArrayList(int width, int capacity)
@Override
public boolean add(String o)
{
- int i = 0;
- long cmp = 0;
-
if (_innerList.size() == 0 && o!=null) // the first value added is not null
withDummy = false;
- long[] item = parse(o);
+ return addRaw(parse(o));
+ }
+
+ @Override
+ public boolean addRaw(Object o)
+ {
+ int i = 0;
+ long cmp = 0;
+
+ long[] item = (long[])o;
for(i=0; i<width; ++i)
{
@@ -93,7 +99,7 @@ public boolean add(String o)
sanity[i] = item[i];
return true;
- }
+ }
@Override
protected List<?> buildPrimitiveList(int capacity)
@@ -43,6 +43,12 @@ public boolean add(String o)
return ((FloatArrayList) _innerList).add(parse(o));
}
+ @Override
+ public boolean addRaw(Object o)
+ {
+ return ((FloatArrayList) _innerList).add(((Number)o).floatValue());
+ }
+
@Override
protected List<?> buildPrimitiveList(int capacity)
{
@@ -50,6 +50,12 @@ public boolean add(String o)
return ((IntArrayList) _innerList).add(item);
}
+ @Override
+ public boolean addRaw(Object o)
+ {
+ return ((IntArrayList) _innerList).add(((Number)o).intValue());
+ }
+
@Override
protected List<?> buildPrimitiveList(int capacity)
{
@@ -49,6 +49,12 @@ public boolean add(String o)
return ((LongArrayList) _innerList).add(item);
}
+ @Override
+ public boolean addRaw(Object o)
+ {
+ return ((LongArrayList) _innerList).add(((Number)o).longValue());
+ }
+
@Override
protected List<?> buildPrimitiveList(int capacity)
{
@@ -49,6 +49,12 @@ public boolean add(String o)
return ((ShortArrayList) _innerList).add(item);
}
+ @Override
+ public boolean addRaw(Object o)
+ {
+ return ((ShortArrayList) _innerList).add(((Number)o).shortValue());
+ }
+
@Override
public void clear()
{
@@ -26,6 +26,12 @@ public boolean add(String o) {
}
@Override
+ public boolean addRaw(Object o)
+ {
+ return add((String)o);
+ }
+
+ @Override
protected List<?> buildPrimitiveList(int capacity) {
_type = String.class;
if (capacity<0)
@@ -51,6 +51,9 @@ protected TermValueList(int capacity)
*/
abstract public boolean add(String o);
+ // do not accept null values
+ abstract public boolean addRaw(Object o);
+
public void add(int index, String element)
{
throw new IllegalStateException("not supported");
@@ -8,6 +8,7 @@
import java.util.LinkedList;
import java.util.Map;
import java.util.Set;
+import java.util.SortedMap;
import java.util.TreeMap;
import org.apache.lucene.index.TermDocs;
@@ -48,7 +49,7 @@ public VirtualSimpleFacetHandler(String name,
public FacetDataCache load(BoboIndexReader reader) throws IOException
{
int doc = -1;
- TreeMap<Object, LinkedList<Integer>> dataMap = null;
+ SortedMap<Object, LinkedList<Integer>> dataMap = null;
LinkedList<Integer> docList = null;
int nullMinId = -1;
@@ -135,7 +136,6 @@ public int compare(Object big, Object small)
{
termDocs.close();
}
- _facetDataFetcher.cleanup(reader);
int maxDoc = reader.maxDoc();
int size = dataMap == null ? 1:(dataMap.size() + 1);
@@ -160,7 +160,7 @@ public int compare(Object big, Object small)
Integer docId;
for (Map.Entry<Object, LinkedList<Integer>> entry : dataMap.entrySet())
{
- list.add(list.format(entry.getKey()));
+ list.addRaw(entry.getKey());
docList = entry.getValue();
freqs[i] = docList.size();
minIDs[i] = docList.get(0);
@@ -179,4 +179,14 @@ public int compare(Object big, Object small)
maxIDs, TermCountSize.large);
return dataCache;
}
+
+ /**
+ * @see com.browseengine.bobo.facets.FacetHandler#cleanup
+ */
+ @Override
+ public void cleanup(BoboIndexReader reader)
+ {
+ System.out.println(">>> cleaning up for " + reader);
+ _facetDataFetcher.cleanup(reader);
+ }
}

0 comments on commit c00ea4f

Please sign in to comment.