forked from LinkedInAttic/sensei
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Finished the AttributeFacetHandler Implemendtation, plus some minor
fixes, plus refactored and enhanced integration tests
- Loading branch information
vzhabiuk
committed
Jan 12, 2012
1 parent
f9829e3
commit 8d4080e
Showing
16 changed files
with
339 additions
and
15,245 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
sensei-core/src/main/java/com/sensei/facet/attribute/BitSetBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.sensei.facet.attribute; | ||
|
||
import org.apache.lucene.util.OpenBitSet; | ||
|
||
import com.browseengine.bobo.facets.data.FacetDataCache; | ||
|
||
public interface BitSetBuilder { | ||
OpenBitSet bitSet(FacetDataCache dataCache); | ||
} |
90 changes: 90 additions & 0 deletions
90
sensei-core/src/main/java/com/sensei/facet/attribute/BitSetFilter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package com.sensei.facet.attribute; | ||
|
||
import java.io.IOException; | ||
|
||
import org.apache.lucene.search.DocIdSetIterator; | ||
import org.apache.lucene.util.OpenBitSet; | ||
|
||
import com.browseengine.bobo.api.BoboIndexReader; | ||
import com.browseengine.bobo.docidset.EmptyDocIdSet; | ||
import com.browseengine.bobo.docidset.RandomAccessDocIdSet; | ||
import com.browseengine.bobo.facets.data.FacetDataCache; | ||
import com.browseengine.bobo.facets.data.MultiValueFacetDataCache; | ||
import com.browseengine.bobo.facets.filter.AdaptiveFacetFilter.FacetDataCacheBuilder; | ||
import com.browseengine.bobo.facets.filter.FacetOrFilter; | ||
import com.browseengine.bobo.facets.filter.MultiValueORFacetFilter; | ||
import com.browseengine.bobo.facets.filter.RandomAccessFilter; | ||
|
||
public class BitSetFilter extends RandomAccessFilter { | ||
private static final long serialVersionUID = 1L; | ||
|
||
protected final FacetDataCacheBuilder facetDataCacheBuilder; | ||
protected final BitSetBuilder bitSetBuilder; | ||
private volatile OpenBitSet bitSet; | ||
private volatile FacetDataCache lastCache; | ||
public BitSetFilter(BitSetBuilder bitSetBuilder, FacetDataCacheBuilder facetDataCacheBuilder) { | ||
this.bitSetBuilder = bitSetBuilder; | ||
this.facetDataCacheBuilder = facetDataCacheBuilder; | ||
} | ||
public OpenBitSet getBitSet( FacetDataCache dataCache) { | ||
|
||
if (lastCache == dataCache) { | ||
return bitSet; | ||
} | ||
bitSet = bitSetBuilder.bitSet(dataCache); | ||
lastCache = dataCache; | ||
return bitSet; | ||
} | ||
|
||
@Override | ||
public RandomAccessDocIdSet getRandomAccessDocIdSet(final BoboIndexReader reader) throws IOException { | ||
final FacetDataCache dataCache = facetDataCacheBuilder.build(reader); | ||
final OpenBitSet openBitSet = getBitSet(dataCache); | ||
long count = openBitSet.cardinality(); | ||
if (count == 0) { | ||
return EmptyDocIdSet.getInstance(); | ||
} else { | ||
final boolean multi = dataCache instanceof MultiValueFacetDataCache; | ||
final MultiValueFacetDataCache multiCache = multi ? (MultiValueFacetDataCache) dataCache : null; | ||
|
||
return new RandomAccessDocIdSet() { | ||
public DocIdSetIterator iterator() { | ||
|
||
if (multi) { | ||
return new MultiValueORFacetFilter.MultiValueOrFacetDocIdSetIterator(multiCache, openBitSet); | ||
} else { | ||
return new FacetOrFilter.FacetOrDocIdSetIterator(dataCache, openBitSet); | ||
|
||
} | ||
} | ||
public boolean get(int docId) { | ||
if (multi) { | ||
return multiCache._nestedArray.contains(docId, openBitSet); | ||
} else { | ||
return openBitSet.fastGet(dataCache.orderArray.get(docId)); | ||
} | ||
} | ||
}; | ||
} | ||
} | ||
|
||
@Override | ||
public double getFacetSelectivity(BoboIndexReader reader) { | ||
FacetDataCache dataCache = facetDataCacheBuilder.build(reader); | ||
final OpenBitSet openBitSet = getBitSet(dataCache); | ||
int[] frequencies = dataCache.freqs; | ||
double selectivity = 0; | ||
int accumFreq = 0; | ||
int index = openBitSet.nextSetBit(-1); | ||
while (index >= 0) { | ||
accumFreq += frequencies[index]; | ||
index = openBitSet.nextSetBit(index); | ||
} | ||
int total = reader.maxDoc(); | ||
selectivity = (double) accumFreq / (double) total; | ||
if (selectivity > 0.999) { | ||
selectivity = 1.0; | ||
} | ||
return selectivity; | ||
} | ||
} |
Oops, something went wrong.