下面列出了org.apache.lucene.index.AtomicReader#maxDoc ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private DocIdSet docIdSetToCache(DocIdSet docIdSet, AtomicReader reader, String segmentName, Directory directory)
throws IOException {
if (docIdSet == null) {
// this is better than returning null, as the nonnull result can be cached
return DocIdSet.EMPTY_DOCIDSET;
} else if (docIdSet.isCacheable()) {
return docIdSet;
} else {
final DocIdSetIterator it = docIdSet.iterator();
// null is allowed to be returned by iterator(),
// in this case we wrap with the empty set,
// which is cacheable.
if (it == null) {
return DocIdSet.EMPTY_DOCIDSET;
} else {
final IndexFileBitSet bits = new IndexFileBitSet(reader.maxDoc(), _id, segmentName, directory);
if (!bits.exists()) {
bits.create(it);
}
bits.load();
return bits;
}
}
}
@Override
protected Accountable createValue(final AtomicReader reader, CacheKey key, boolean setDocsWithField)
throws IOException {
int maxDoc = reader.maxDoc();
final int[][] matrix = new int[maxDoc][];
BinaryDocValues valuesIn = reader.getBinaryDocValues(key.field);
if (valuesIn == null) {
for (int i = 0; i < maxDoc; ++i) {
matrix[i] = new int[0];
}
return new IntList(matrix);
}
for (int i = 0; i < maxDoc; ++i) {
String str = valuesIn.get(i).utf8ToString();
if (StringUtils.isEmpty(str)) {
matrix[i] = new int[0];
continue;
}
JSONArray array = JSON.parseArray(str);
matrix[i] = new int[array.size()];
for (int j = 0; j < array.size(); ++j) {
matrix[i][j] = array.getInteger(j);
}
}
return new IntList(matrix);
}
@Override
protected Accountable createValue(final AtomicReader reader, CacheKey key, boolean setDocsWithField)
throws IOException {
int maxDoc = reader.maxDoc();
final long[][] matrix = new long[maxDoc][];
BinaryDocValues valuesIn = reader.getBinaryDocValues(key.field);
if (valuesIn == null) {
for (int i = 0; i < maxDoc; ++i) {
matrix[i] = new long[0];
}
return new LongList(matrix);
}
for (int i = 0; i < maxDoc; ++i) {
String str = valuesIn.get(i).utf8ToString();
if (StringUtils.isEmpty(str)) {
matrix[i] = new long[0];
continue;
}
JSONArray array = JSON.parseArray(str);
matrix[i] = new long[array.size()];
for (int j = 0; j < array.size(); ++j) {
matrix[i][j] = array.getInteger(j);
}
}
return new LongList(matrix);
}
@Override
protected Accountable createValue(final AtomicReader reader, CacheKey key, boolean setDocsWithField)
throws IOException {
int maxDoc = reader.maxDoc();
final float[][] matrix = new float[maxDoc][];
BinaryDocValues valuesIn = reader.getBinaryDocValues(key.field);
if (valuesIn == null) {
for (int i = 0; i < maxDoc; ++i) {
matrix[i] = new float[0];
}
return new FloatList(matrix);
}
for (int i = 0; i < maxDoc; ++i) {
String str = valuesIn.get(i).utf8ToString();
if (StringUtils.isEmpty(str)) {
matrix[i] = new float[0];
continue;
}
JSONArray array = JSON.parseArray(str);
matrix[i] = new float[array.size()];
for (int j = 0; j < array.size(); ++j) {
matrix[i][j] = array.getFloat(j);
}
}
return new FloatList(matrix);
}
@Override
protected Accountable createValue(final AtomicReader reader, CacheKey key, boolean setDocsWithField)
throws IOException {
int maxDoc = reader.maxDoc();
final double[][] matrix = new double[maxDoc][];
BinaryDocValues valuesIn = reader.getBinaryDocValues(key.field);
if (valuesIn == null) {
for (int i = 0; i < maxDoc; ++i) {
matrix[i] = new double[0];
}
return new DoubleList(matrix);
}
for (int i = 0; i < maxDoc; ++i) {
String str = valuesIn.get(i).utf8ToString();
if (StringUtils.isEmpty(str)) {
matrix[i] = new double[0];
continue;
}
JSONArray array = JSON.parseArray(str);
matrix[i] = new double[array.size()];
for (int j = 0; j < array.size(); ++j) {
matrix[i][j] = array.getFloat(j);
}
}
return new DoubleList(matrix);
}
@Override
protected Accountable createValue(final AtomicReader reader, CacheKey key, boolean setDocsWithField)
throws IOException {
int maxDoc = reader.maxDoc();
final String[][] matrix = new String[maxDoc][];
BinaryDocValues valuesIn = reader.getBinaryDocValues(key.field);
if (valuesIn == null) {
for (int i = 0; i < maxDoc; ++i) {
matrix[i] = new String[0];
}
return new StringList(matrix);
}
for (int i = 0; i < maxDoc; ++i) {
String str = valuesIn.get(i).utf8ToString();
if (StringUtils.isEmpty(str)) {
matrix[i] = new String[0];
continue;
}
JSONArray array = JSON.parseArray(str);
matrix[i] = new String[array.size()];
for (int j = 0; j < array.size(); ++j) {
matrix[i][j] = array.getString(j);
}
}
return new StringList(matrix);
}
Info(AtomicReaderContext context, Scorer[] scorers, Lock[] locks, String instance) {
AtomicReader reader = context.reader();
_instance = instance;
_bitSet = new OpenBitSet(reader.maxDoc());
_scorers = scorers;
_reader = reader;
_readerStr = _reader.toString();
_maxDoc = _reader.maxDoc();
_locks = locks;
}
@Override
protected Accountable createValue(final AtomicReader reader, CacheKey key, boolean setDocsWithField)
throws IOException {
return new StoredStrings(reader.maxDoc(), key.field);
}
@Override
public int compare(Entry<Object, Info> o1, Entry<Object, Info> o2) {
AtomicReader r1 = o1.getValue()._reader;
AtomicReader r2 = o2.getValue()._reader;
return r2.maxDoc() - r1.maxDoc();
}