下面列出了org.apache.lucene.index.DocValues#getBinary ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
public ShapeValues getValues(LeafReaderContext readerContext) throws IOException {
final BinaryDocValues docValues = DocValues.getBinary(readerContext.reader(), fieldName);
return new ShapeValues() {
@Override
public boolean advanceExact(int doc) throws IOException {
return docValues.advanceExact(doc);
}
@Override
public Shape value() throws IOException {
BytesRef bytesRef = docValues.binaryValue();
DataInputStream dataInput
= new DataInputStream(new ByteArrayInputStream(bytesRef.bytes, bytesRef.offset, bytesRef.length));
return binaryCodec.readShape(dataInput);
}
};
}
@Override
public AtomicGeoPointFieldData load(LeafReaderContext context) {
try {
if (indexCreatedBefore2x) {
return new GeoPointLegacyDVAtomicFieldData(DocValues.getBinary(context.reader(), fieldNames.indexName()));
}
return new GeoPointDVAtomicFieldData(DocValues.getSortedNumeric(context.reader(), fieldNames.indexName()));
} catch (IOException e) {
throw new IllegalStateException("Cannot load doc values", e);
}
}
@Override
public BytesBinaryDVAtomicFieldData load(LeafReaderContext context) {
try {
return new BytesBinaryDVAtomicFieldData(DocValues.getBinary(context.reader(), fieldNames.indexName()));
} catch (IOException e) {
throw new IllegalStateException("Cannot load doc values", e);
}
}
@Override
public SortedBinaryDocValues getBytesValues() {
try {
final BinaryDocValues values = DocValues.getBinary(reader, field);
final Bits docsWithField = DocValues.getDocsWithField(reader, field);
return FieldData.singleton(values, docsWithField);
} catch (IOException e) {
throw new IllegalStateException("Cannot load doc values", e);
}
}
@Override
public LeafFieldComparator getLeafComparator(LeafReaderContext context) throws IOException
{
docTerms = DocValues.getBinary(context.reader(), field);
docsWithField = DocValues.getDocsWithField(context.reader(), field);
if (docsWithField instanceof Bits.MatchAllBits) {
docsWithField = null;
}
return this;
}
@Override
public LeafFieldComparator getLeafComparator(LeafReaderContext context) throws IOException
{
docTerms = DocValues.getBinary(context.reader(), field);
docsWithField = DocValues.getDocsWithField(context.reader(), field);
if (docsWithField instanceof Bits.MatchAllBits)
{
docsWithField = null;
}
return this;
}
@Override
public FunctionValues getValues(Map<Object, Object> context, LeafReaderContext readerContext) throws IOException
{
final BinaryDocValues terms = DocValues.getBinary(readerContext.reader(), field);
final IndexReader top = ReaderUtil.getTopLevelContext(readerContext).reader();
Terms t = MultiTerms.getTerms(top, qfield);
final TermsEnum termsEnum = t == null ? TermsEnum.EMPTY : t.iterator();
return new IntDocValues(this) {
int lastDocID = -1;
@Override
public int intVal(int doc) throws IOException {
if (doc < lastDocID) {
throw new IllegalArgumentException("docs were sent out-of-order: lastDocID=" + lastDocID + " vs docID=" + doc);
}
lastDocID = doc;
int curDocID = terms.docID();
if (doc > curDocID) {
curDocID = terms.advance(doc);
}
if (doc == curDocID) {
BytesRef term = terms.binaryValue();
if (termsEnum.seekExact(term)) {
return termsEnum.docFreq();
}
}
return 0;
}
};
}
@Override
public AtomicNumericFieldData load(LeafReaderContext context) {
try {
final BinaryDocValues values = DocValues.getBinary(context.reader(), fieldNames.indexName());
if (numericType.isFloatingPoint()) {
return new AtomicDoubleFieldData(-1) {
@Override
public SortedNumericDoubleValues getDoubleValues() {
switch (numericType) {
case FLOAT:
return new BinaryAsSortedNumericFloatValues(values);
case DOUBLE:
return new BinaryAsSortedNumericDoubleValues(values);
default:
throw new IllegalArgumentException("" + numericType);
}
}
@Override
public Collection<Accountable> getChildResources() {
return Collections.emptyList();
}
};
} else {
return new AtomicLongFieldData(0) {
@Override
public SortedNumericDocValues getLongValues() {
return new BinaryAsSortedNumericDocValues(values);
}
@Override
public Collection<Accountable> getChildResources() {
return Collections.emptyList();
}
};
}
} catch (IOException e) {
throw new IllegalStateException("Cannot load doc values", e);
}
}
@Override
public LeafCollector getLeafCollector(LeafReaderContext context)
throws IOException {
this.vals = DocValues.getBinary(context.reader(), field);
return super.getLeafCollector(context);
}
static Function<BinaryDocValues> binaryDocValues(String field) {
return (ctx) -> DocValues.getBinary(ctx, field);
}
/** Retrieves the BinaryDocValues for the field in this segment */
protected BinaryDocValues getBinaryDocValues(LeafReaderContext context, String field) throws IOException {
return DocValues.getBinary(context.reader(), field);
}
@Override
public void doSetNextReader(LeafReaderContext context) throws IOException {
docValues = DocValues.getBinary(context.reader(), fieldName);
}
@Override
protected void doSetNextReader(LeafReader r )
throws IOException {
docs = DocValues.getBinary(r, name);
}
@Override
protected void doSetNextReader(LeafReader r)
throws IOException {
docs = DocValues.getBinary(r, name);
}
@Override
protected void doSetNextReader(LeafReader r)
throws IOException {
docs = DocValues.getBinary(r, name);
}
@Override
protected void doSetNextReader(LeafReader r)
throws IOException {
docs = DocValues.getBinary(r, name);
}