Skip to content

Commit

Permalink
The upgrade is 99% finished
Browse files Browse the repository at this point in the history
  • Loading branch information
romanchyla committed Oct 5, 2016
1 parent 7ea5cb8 commit d76da1b
Show file tree
Hide file tree
Showing 12 changed files with 189 additions and 239 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public abstract class AbstractSecondOrderCollector implements Collector, LeafCol
private Integer lastPos = null;
protected float ensureCapacityRatio = 0.25f;
protected FinalValueType compactingType = FinalValueType.MAX_VALUE;
private LeafReaderContext context;
protected LeafReaderContext context;

public AbstractSecondOrderCollector() {
lock = new ReentrantLock();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,40 +7,55 @@
* Iterator which works with the knowledge of index segment boundaries.
* It returns un-based document ids.
*
* Internal bitset iterator works with bounded ranges. We remove/add
* bases before returning the results.
*
*/
public class BasedBitSetIterator extends BitSetIterator {
public class BasedBitSetIterator extends DocIdSetIterator {
private int base;
private int v;
private int doc = -1;
private int upperBound;
private BitSet bits;
private int length;
private long cost;

public BasedBitSetIterator(BitSet bits, long cost, int base) {
super(bits, cost);
public BasedBitSetIterator(BitSet bits, long cost, int base, int size) {
if (cost < 0) {
throw new IllegalArgumentException("cost must be >= 0, got " + cost);
}
this.bits = bits;
this.length = bits.length();
this.cost = cost;
this.base = base;
this.upperBound = base + size;
if (upperBound > length)
upperBound = length;
}

@Override
public int docID() {
v = super.docID();
if (v != NO_MORE_DOCS)
return v - base;
return v;
return doc;
}

@Override
public int nextDoc() {
v = super.nextDoc();
if (v != NO_MORE_DOCS)
return v - base;
return v;
return advance(doc + 1);
}

@Override
public int advance(int target) {
v = super.advance(target + base);
if (v != NO_MORE_DOCS)
return v - base;
return v;
if (target+base >= upperBound) {
return doc = NO_MORE_DOCS;
}
doc = bits.nextSetBit(target+base);
if (doc >= upperBound)
return doc = NO_MORE_DOCS;
return doc = doc - base;
}



}

@Override
public long cost() {
return cost;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ public Weight createWeight(IndexSearcher searcher, boolean needsScores) throws I
return new ConstantScoreWeight(this) {
@Override
public Scorer scorer(LeafReaderContext context) throws IOException {
return new ConstantScoreScorer(this, score(), new BasedBitSetIterator(docs, docs.approximateCardinality(), context.docBase));
return new ConstantScoreScorer(this, score(),
new BasedBitSetIterator(docs, docs.approximateCardinality(),
context.docBase, context.reader().maxDoc()));
}
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,7 @@ public SecondOrderCollectorCitedBy(SolrCacheWrapper cache) {


@Override
public boolean searcherInitialization(IndexSearcher searcher, Weight firstOrderWeight) throws IOException {
return super.searcherInitialization(searcher, firstOrderWeight);
}


@Override
public void setScorer(Scorer scorer) throws IOException {
this.scorer = scorer;

}

@Override
public void collect(int doc) throws IOException {
public void collect(int doc) throws IOException {
int[] v = cache.getLuceneDocIds(doc+docBase);
if (v == null) return;
float s = scorer.score();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,14 @@ public SecondOrderCollectorCites(SolrCacheWrapper cache, String[] referenceField
@SuppressWarnings("unchecked")
@Override
public boolean searcherInitialization(IndexSearcher searcher, Weight firstOrderWeight) throws IOException {
reader = searcher.getIndexReader();
return super.searcherInitialization(searcher, firstOrderWeight);
}


@Override
public void collect(int doc) throws IOException {
//if (reader.isDeleted(doc)) return;

Document document = reader.document(doc, fieldsToLoad);
Document document = this.context.reader().document(doc, fieldsToLoad);
float s = scorer.score();

for (String f: fieldsToLoad) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,6 @@ public SecondOrderCollectorCitesRAM(SolrCacheWrapper cache) {
}


@SuppressWarnings("unchecked")
@Override
public boolean searcherInitialization(IndexSearcher searcher, Weight firstOrderWeight) throws IOException {
return super.searcherInitialization(searcher, firstOrderWeight);
}


@Override
public void collect(int doc) throws IOException {
int[] citations = cache.getLuceneDocIds(doc+docBase);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.apache.lucene.index.NumericDocValues;
import org.apache.lucene.queryparser.classic.ParseException;
import org.apache.lucene.search.BitSetQuery;
import org.apache.lucene.search.DocIdSetIterator;
import org.apache.lucene.search.MatchNoDocsQuery;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.SolrCacheWrapper;
Expand Down Expand Up @@ -285,7 +286,7 @@ else if (c.isAssignableFrom(TrieIntField.class)) {

SolrCacheWrapper<SolrCache<Object,Integer>> cacheWrapper = super.getCache(fieldName);
if (cacheWrapper != null) { // we are lucky and we have a cache that can translate values for us
for (int i = bits.nextSetBit(0); i >= 0; i = bits.nextSetBit(i+1)) {
for (int i = bits.nextSetBit(0); i >= 0 && i < DocIdSetIterator.NO_MORE_DOCS; i = bits.nextSetBit(i+1)) {
if (fieldIsInt) {
int v = cacheWrapper.getLuceneDocId(0, i);
if (v == -1)
Expand Down Expand Up @@ -542,7 +543,7 @@ private byte[] unZip(byte[] data) throws IOException {

protected byte[] toByteArray(BitSet bitSet) {
byte[] bytes = new byte[(bitSet.length() + 7) / 8];
for ( int i = bitSet.nextSetBit(0); i >= 0 && i < Integer.MAX_VALUE; i = bitSet.nextSetBit(i+1) ) {
for ( int i = bitSet.nextSetBit(0); i >= 0 && i < DocIdSetIterator.NO_MORE_DOCS; i = bitSet.nextSetBit(i+1) ) {
bytes[i / 8] |= 128 >> (i % 8);
if (i+1 >= bitSet.length())
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -630,9 +630,8 @@ private void unInvertedTheDamnThing(
List<String> fields,
KVSetter setter) throws IOException {

LeafReader reader = searcher.getLeafReader();
IndexSchema schema = searcher.getCore().getLatestSchema();
List<LeafReaderContext> leaves = reader.getContext().leaves();
List<LeafReaderContext> leaves = searcher.getIndexReader().getContext().leaves();

Bits liveDocs;
LeafReader lr;
Expand All @@ -642,7 +641,6 @@ private void unInvertedTheDamnThing(
liveDocs = leave.reader().getLiveDocs();
lr = leave.reader();
FieldInfos fInfo = lr.getFieldInfos();

for (String field: fields) {

FieldInfo fi = fInfo.fieldInfo(field);
Expand Down Expand Up @@ -994,7 +992,7 @@ public void addReference(int sourceDocid, Object value) {
addReference(sourceDocid, (Integer) this.get(value));
}
else {
addReference(sourceDocid, -1);
//addReference(sourceDocid, -1);
}
}
public void addReference(int sourceDocid, Integer targetDocid) {
Expand All @@ -1007,7 +1005,7 @@ public void addCitation(int sourceDocid, Object value) {
addCitation(sourceDocid, (Integer) this.get(value));
}
else {
addCitation(sourceDocid, -1);
//addCitation(sourceDocid, -1);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,8 @@ private void verifySearch(int[] randomIds) throws IOException {
}

private Query[] buildQueries(String[] parts) throws UnsupportedEncodingException {
if (parts.length - 1 < 3)
return null;
int howMany = TestUtil.nextInt(random(), 2, parts.length-1); // how many initials
if (howMany < 2)
return null;
Expand Down
Loading

0 comments on commit d76da1b

Please sign in to comment.