Skip to content

Commit

Permalink
Merge branch 'facet_merge' of git://github.com/javasoze/bobo
Browse files Browse the repository at this point in the history
Conflicts:
	bobo-browse/src/com/browseengine/bobo/facets/CombinedFacetAccessible.java
	bobo-browse/src/com/browseengine/bobo/facets/data/TermIntList.java
	bobo-browse/src/com/browseengine/bobo/facets/impl/CombinedFacetIterator.java
  • Loading branch information
xiaoyanggu committed Apr 27, 2010
2 parents 7403438 + 01bbc6f commit 2e5ff60
Show file tree
Hide file tree
Showing 17 changed files with 559 additions and 361 deletions.
22 changes: 6 additions & 16 deletions bobo-browse/src/com/browseengine/bobo/api/FacetIterator.java
Expand Up @@ -9,33 +9,23 @@
* @author nnarkhed
*
*/
public interface FacetIterator extends Iterator<String>{
public abstract class FacetIterator implements Iterator<Comparable>{

/**
* Returns the facet name of the current facet in the iteration
* @return the facet name of the current facet
* @throws NoSuchElementException if the iteration has no more facets
*/
String getFacet();

/**
* Returns the facet count of the current facet in the iteration
* @return the facet count of the current facet
* @throws NoSuchElementException if the iteration has no more facets
*/
int getFacetCount();
public int count;
public Comparable facet;

/**
* Moves the iteration to the next facet
* @return the next facet value
*/
String next();
public abstract Comparable next();

/**
* Moves the iteration to the next facet whose hitcount >= minHits. returns null if there is no facet whose hitcount >= minHits.
* Hence while using this method, it is useless to use hasNext() with it.
* After the next() method returns null, calling it repeatedly would result in undefined behavior
* @return The next facet value. It returns null if there is no facet whose hitcount >= minHits.
*/
String next(int minHits);
public abstract Comparable next(int minHits);
public abstract String format(Object val);
}
@@ -0,0 +1,9 @@
package com.browseengine.bobo.api;

public abstract class IntFacetIterator extends FacetIterator
{
public int facet;
public abstract int nextInt();
public abstract int nextInt(int minHits);
public abstract String format(int val);
}
Expand Up @@ -13,6 +13,7 @@
import com.browseengine.bobo.api.FacetAccessible;
import com.browseengine.bobo.api.FacetIterator;
import com.browseengine.bobo.api.FacetSpec;
import com.browseengine.bobo.api.IntFacetIterator;
import com.browseengine.bobo.api.FacetSpec.FacetSortSpec;
import com.browseengine.bobo.facets.impl.CombinedFacetIterator;
import com.browseengine.bobo.facets.impl.CombinedIntFacetIterator;
Expand Down Expand Up @@ -69,17 +70,15 @@ public List<BrowseFacet> getFacets()
LinkedList<BrowseFacet> list = new LinkedList<BrowseFacet>();

int cnt = 0;
String facet = null;
Comparable facet = null;
FacetIterator iter = (FacetIterator)this.iterator();
int count = 0;
Comparator<BrowseFacet> comparator;
if (FacetSortSpec.OrderValueAsc.equals(_fspec.getOrderBy()))
{
while((facet = iter.next(minHits)) != null)
{
// find the next facet whose combined hit count obeys minHits
count = iter.getFacetCount();
list.add(new BrowseFacet(facet, count));
list.add(new BrowseFacet(String.valueOf(facet), iter.count));
if(++cnt >= maxCnt) break;
}
}
Expand All @@ -105,25 +104,20 @@ public int compare(BrowseFacet f1, BrowseFacet f2)
int qsize = 0;
while( (qsize < maxCnt) && ((facet = iter.next(minHits)) != null) )
{
count = iter.getFacetCount();
queue.add(new BrowseFacet(facet, count));
queue.add(new BrowseFacet(String.valueOf(facet), iter.count));
qsize++;
}
if(facet != null)
{
BrowseFacet rootFacet = (BrowseFacet)queue.top();
minHits = rootFacet.getHitCount() + 1;
// facet count less than top of min heap, it will never be added
while(((facet = iter.next(minHits)) != null))
{
// check with the top of min heap
count = iter.getFacetCount();
// if facet count less than top of min heap, it should never be added
if(count > rootFacet.getHitCount())
{
rootFacet.setValue(facet);
rootFacet.setHitCount(count);
rootFacet = (BrowseFacet) queue.updateTop();
minHits = rootFacet.getHitCount() + 1;
}
rootFacet.setValue(String.valueOf(facet));
rootFacet.setHitCount(iter.count);
rootFacet = (BrowseFacet) queue.updateTop();
minHits = rootFacet.getHitCount() + 1;
}
}
// at this point, queue contains top maxCnt facets that have hitcount >= minHits
Expand All @@ -137,7 +131,7 @@ public int compare(BrowseFacet f1, BrowseFacet f2)
{
// no maxCnt specified. So fetch all facets according to minHits and sort them later
while((facet = iter.next(minHits)) != null)
list.add(new BrowseFacet(facet, iter.getFacetCount()));
list.add(new BrowseFacet(String.valueOf(facet), iter.count));
Collections.sort(list, comparator);
}
}
Expand All @@ -151,21 +145,17 @@ public int compare(BrowseFacet f1, BrowseFacet f2)
int qsize = 0;
while( (qsize < maxCnt) && ((facet = iter.next(minHits)) != null) )
{
count = iter.getFacetCount();
queue.add(new BrowseFacet(facet, count));
queue.add(new BrowseFacet(String.valueOf(facet), iter.count));
qsize++;
}
if(facet != null)
{
while((facet = iter.next(minHits)) != null)
{
// check with the top of min heap
// if facet count less than top of min heap, it should never be added
browseFacet.setHitCount(count);
browseFacet.setValue(facet);
BrowseFacet ejectedFacet = (BrowseFacet)queue.insertWithOverflow(browseFacet);
if(ejectedFacet != browseFacet)
browseFacet = ejectedFacet;
browseFacet.setHitCount(iter.count);
browseFacet.setValue(String.valueOf(facet));
browseFacet = (BrowseFacet)queue.insertWithOverflow(browseFacet);
}
}
// remove from queue and add to the list
Expand All @@ -176,7 +166,7 @@ public int compare(BrowseFacet f1, BrowseFacet f2)
{
// order by custom but no max count supplied
while((facet = iter.next(minHits)) != null)
list.add(new BrowseFacet(facet, iter.getFacetCount()));
list.add(new BrowseFacet(String.valueOf(facet), iter.count));
Collections.sort(list, comparator);
}
}
Expand Down Expand Up @@ -222,17 +212,17 @@ public FacetIterator iterator() {
if(iter != null)
iterList.add(iter);
}
if (iterList.get(0) instanceof DefaultIntFacetIterator)
if (iterList.get(0) instanceof IntFacetIterator)
{
ArrayList<DefaultIntFacetIterator> il = new ArrayList<DefaultIntFacetIterator>();
ArrayList<IntFacetIterator> il = new ArrayList<IntFacetIterator>();
for (FacetAccessible facetAccessor : _list)
{
iter = (FacetIterator) facetAccessor.iterator();
if(iter != null)
il.add((DefaultIntFacetIterator) iter);
il.add((IntFacetIterator) iter);
}
return new CombinedIntFacetIterator(il, _fspec.getMinHitCount());
}
return new CombinedFacetIterator(iterList, _fspec.getMinHitCount());
return new CombinedFacetIterator(iterList);
}
}
Expand Up @@ -88,8 +88,8 @@ public final void remove() {

@Override
protected List<?> buildPrimitiveList(int capacity) {
_type = Integer.class;
return capacity>0 ? new IntArrayList(capacity) : new IntArrayList();
_type = Integer.class;
return capacity>0 ? new IntArrayList(capacity) : new IntArrayList();
}

@Override
Expand Down Expand Up @@ -166,6 +166,10 @@ public String format(final Integer o) {
return _simpleFormatter.get().format(o);
}

public String format(final int o) {
return _simpleFormatter.get().format(o);
}

@Override
public boolean containsWithType(Integer val)
{
Expand Down
Expand Up @@ -54,7 +54,12 @@ public void add(int index, String element)

public boolean addAll(Collection<? extends String> c)
{
throw new IllegalStateException("not supported");
boolean ret = true;
for(String s: c)
{
ret &= add(s);
}
return ret;
}

public boolean addAll(int index, Collection<? extends String> c)
Expand Down

0 comments on commit 2e5ff60

Please sign in to comment.