本文整理汇总了Java中org.apache.lucene.index.SortedNumericDocValues类的典型用法代码示例。如果您正苦于以下问题:Java SortedNumericDocValues类的具体用法?Java SortedNumericDocValues怎么用?Java SortedNumericDocValues使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SortedNumericDocValues类属于org.apache.lucene.index包,在下文中一共展示了SortedNumericDocValues类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: createWeight
import org.apache.lucene.index.SortedNumericDocValues; //导入依赖的package包/类
@Override
public Weight createWeight(IndexSearcher searcher, boolean needsScores) throws IOException {
return new RandomAccessWeight(this) {
@Override
protected Bits getMatchingDocs(final LeafReaderContext context) throws IOException {
final SortedNumericDocValues values = DocValues.getSortedNumeric(context.reader(), getField());
return new Bits() {
@Override
public boolean get(int doc) {
values.setDocument(doc);
for (int i = 0; i < values.count(); i++) {
return contains(BitMixer.mix(values.valueAt(i)));
}
return contains(0);
}
@Override
public int length() {
return context.reader().maxDoc();
}
};
}
};
}
开发者ID:justor,项目名称:elasticsearch_my,代码行数:25,代码来源:DocValuesSliceQuery.java
示例2: testLong
import org.apache.lucene.index.SortedNumericDocValues; //导入依赖的package包/类
public void testLong() throws Exception {
IndexService indexService = createIndex("index", Settings.EMPTY, "type",
"long", "type=long");
client().prepareIndex("index", "type", "1")
.setSource("long", 42)
.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE)
.get();
try (Searcher searcher = indexService.getShard(0).acquireSearcher("test")) {
QueryShardContext context = indexService.newQueryShardContext(0, searcher.reader(), () -> 42L);
ValuesSourceConfig<ValuesSource.Numeric> config = ValuesSourceConfig.resolve(
context, null, "long", null, null, null, null);
ValuesSource.Numeric valuesSource = config.toValuesSource(context);
LeafReaderContext ctx = searcher.reader().leaves().get(0);
SortedNumericDocValues values = valuesSource.longValues(ctx);
values.setDocument(0);
assertEquals(1, values.count());
assertEquals(42, values.valueAt(0));
}
}
开发者ID:justor,项目名称:elasticsearch_my,代码行数:22,代码来源:ValuesSourceConfigTests.java
示例3: testUnmappedLong
import org.apache.lucene.index.SortedNumericDocValues; //导入依赖的package包/类
public void testUnmappedLong() throws Exception {
IndexService indexService = createIndex("index", Settings.EMPTY, "type");
client().prepareIndex("index", "type", "1")
.setSource()
.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE)
.get();
try (Searcher searcher = indexService.getShard(0).acquireSearcher("test")) {
QueryShardContext context = indexService.newQueryShardContext(0, searcher.reader(), () -> 42L);
ValuesSourceConfig<ValuesSource.Numeric> config = ValuesSourceConfig.resolve(
context, ValueType.NUMBER, "long", null, null, null, null);
ValuesSource.Numeric valuesSource = config.toValuesSource(context);
assertNull(valuesSource);
config = ValuesSourceConfig.resolve(
context, ValueType.NUMBER, "long", null, 42, null, null);
valuesSource = config.toValuesSource(context);
LeafReaderContext ctx = searcher.reader().leaves().get(0);
SortedNumericDocValues values = valuesSource.longValues(ctx);
values.setDocument(0);
assertEquals(1, values.count());
assertEquals(42, values.valueAt(0));
}
}
开发者ID:justor,项目名称:elasticsearch_my,代码行数:26,代码来源:ValuesSourceConfigTests.java
示例4: testBoolean
import org.apache.lucene.index.SortedNumericDocValues; //导入依赖的package包/类
public void testBoolean() throws Exception {
IndexService indexService = createIndex("index", Settings.EMPTY, "type",
"bool", "type=boolean");
client().prepareIndex("index", "type", "1")
.setSource("bool", true)
.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE)
.get();
try (Searcher searcher = indexService.getShard(0).acquireSearcher("test")) {
QueryShardContext context = indexService.newQueryShardContext(0, searcher.reader(), () -> 42L);
ValuesSourceConfig<ValuesSource.Numeric> config = ValuesSourceConfig.resolve(
context, null, "bool", null, null, null, null);
ValuesSource.Numeric valuesSource = config.toValuesSource(context);
LeafReaderContext ctx = searcher.reader().leaves().get(0);
SortedNumericDocValues values = valuesSource.longValues(ctx);
values.setDocument(0);
assertEquals(1, values.count());
assertEquals(1, values.valueAt(0));
}
}
开发者ID:justor,项目名称:elasticsearch_my,代码行数:22,代码来源:ValuesSourceConfigTests.java
示例5: testUnmappedBoolean
import org.apache.lucene.index.SortedNumericDocValues; //导入依赖的package包/类
public void testUnmappedBoolean() throws Exception {
IndexService indexService = createIndex("index", Settings.EMPTY, "type");
client().prepareIndex("index", "type", "1")
.setSource()
.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE)
.get();
try (Searcher searcher = indexService.getShard(0).acquireSearcher("test")) {
QueryShardContext context = indexService.newQueryShardContext(0, searcher.reader(), () -> 42L);
ValuesSourceConfig<ValuesSource.Numeric> config = ValuesSourceConfig.resolve(
context, ValueType.BOOLEAN, "bool", null, null, null, null);
ValuesSource.Numeric valuesSource = config.toValuesSource(context);
assertNull(valuesSource);
config = ValuesSourceConfig.resolve(
context, ValueType.BOOLEAN, "bool", null, true, null, null);
valuesSource = config.toValuesSource(context);
LeafReaderContext ctx = searcher.reader().leaves().get(0);
SortedNumericDocValues values = valuesSource.longValues(ctx);
values.setDocument(0);
assertEquals(1, values.count());
assertEquals(1, values.valueAt(0));
}
}
开发者ID:justor,项目名称:elasticsearch_my,代码行数:26,代码来源:ValuesSourceConfigTests.java
示例6: testSingleValuedLongs
import org.apache.lucene.index.SortedNumericDocValues; //导入依赖的package包/类
public void testSingleValuedLongs() throws Exception {
final int numDocs = scaledRandomIntBetween(1, 100);
final long[] array = new long[numDocs];
final FixedBitSet docsWithValue = randomBoolean() ? null : new FixedBitSet(numDocs);
for (int i = 0; i < array.length; ++i) {
if (randomBoolean()) {
array[i] = randomLong();
if (docsWithValue != null) {
docsWithValue.set(i);
}
} else if (docsWithValue != null && randomBoolean()) {
docsWithValue.set(i);
}
}
final NumericDocValues singleValues = new NumericDocValues() {
@Override
public long get(int docID) {
return array[docID];
}
};
final SortedNumericDocValues multiValues = DocValues.singleton(singleValues, docsWithValue);
verify(multiValues, numDocs);
final FixedBitSet rootDocs = randomRootDocs(numDocs);
final FixedBitSet innerDocs = randomInnerDocs(rootDocs);
verify(multiValues, numDocs, rootDocs, innerDocs);
}
开发者ID:justor,项目名称:elasticsearch_my,代码行数:27,代码来源:MultiValueModeTests.java
示例7: wrap
import org.apache.lucene.index.SortedNumericDocValues; //导入依赖的package包/类
private Longs wrap(long[][] values) {
return new Longs(new SortedNumericDocValues() {
long[] current;
@Override
public void setDocument(int doc) {
current = values[doc];
}
@Override
public int count() {
return current.length;
}
@Override
public long valueAt(int index) {
return current[index];
}
});
}
开发者ID:justor,项目名称:elasticsearch_my,代码行数:19,代码来源:ScriptDocValuesLongsTests.java
示例8: wrap
import org.apache.lucene.index.SortedNumericDocValues; //导入依赖的package包/类
private Dates wrap(long[][] values) {
return new Dates(new SortedNumericDocValues() {
long[] current;
@Override
public void setDocument(int doc) {
current = values[doc];
}
@Override
public int count() {
return current.length;
}
@Override
public long valueAt(int index) {
return current[index];
}
});
}
开发者ID:justor,项目名称:elasticsearch_my,代码行数:19,代码来源:ScriptDocValuesDatesTests.java
示例9: cast
import org.apache.lucene.index.SortedNumericDocValues; //导入依赖的package包/类
/**
* Return a {@link MurmurHash3Values} instance that returns each value as its hash.
*/
public static MurmurHash3Values cast(final SortedNumericDocValues values) {
return new MurmurHash3Values() {
@Override
public void setDocument(int docId) {
values.setDocument(docId);
}
@Override
public int count() {
return values.count();
}
@Override
public long valueAt(int index) {
return values.valueAt(index);
}
};
}
开发者ID:baidu,项目名称:Elasticsearch,代码行数:20,代码来源:CardinalityAggregator.java
示例10: getLongValues
import org.apache.lucene.index.SortedNumericDocValues; //导入依赖的package包/类
@Override
public SortedNumericDocValues getLongValues() {
try {
return DocValues.getSortedNumeric(reader, field);
} catch (IOException e) {
throw new IllegalStateException("Cannot load doc values", e);
}
}
开发者ID:justor,项目名称:elasticsearch_my,代码行数:9,代码来源:SortedNumericDVIndexFieldData.java
示例11: getDoubleValues
import org.apache.lucene.index.SortedNumericDocValues; //导入依赖的package包/类
@Override
public SortedNumericDoubleValues getDoubleValues() {
try {
SortedNumericDocValues raw = DocValues.getSortedNumeric(reader, field);
NumericDocValues single = DocValues.unwrapSingleton(raw);
if (single != null) {
return FieldData.singleton(new SingleHalfFloatValues(single), DocValues.unwrapSingletonBits(raw));
} else {
return new MultiHalfFloatValues(raw);
}
} catch (IOException e) {
throw new IllegalStateException("Cannot load doc values", e);
}
}
开发者ID:justor,项目名称:elasticsearch_my,代码行数:16,代码来源:SortedNumericDVIndexFieldData.java
示例12: getDoubleValues
import org.apache.lucene.index.SortedNumericDocValues; //导入依赖的package包/类
@Override
public SortedNumericDoubleValues getDoubleValues() {
final SortedNumericDocValues values = scaledFieldData.getLongValues();
final NumericDocValues singleValues = DocValues.unwrapSingleton(values);
if (singleValues != null) {
return FieldData.singleton(new NumericDoubleValues() {
@Override
public double get(int docID) {
return singleValues.get(docID) * scalingFactorInverse;
}
}, DocValues.unwrapSingletonBits(values));
} else {
return new SortedNumericDoubleValues() {
@Override
public double valueAt(int index) {
return values.valueAt(index) * scalingFactorInverse;
}
@Override
public void setDocument(int doc) {
values.setDocument(doc);
}
@Override
public int count() {
return values.count();
}
};
}
}
开发者ID:justor,项目名称:elasticsearch_my,代码行数:32,代码来源:ScaledFloatFieldMapper.java
示例13: testEmptyLong
import org.apache.lucene.index.SortedNumericDocValues; //导入依赖的package包/类
public void testEmptyLong() throws Exception {
IndexService indexService = createIndex("index", Settings.EMPTY, "type",
"long", "type=long");
client().prepareIndex("index", "type", "1")
.setSource()
.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE)
.get();
try (Searcher searcher = indexService.getShard(0).acquireSearcher("test")) {
QueryShardContext context = indexService.newQueryShardContext(0, searcher.reader(), () -> 42L);
ValuesSourceConfig<ValuesSource.Numeric> config = ValuesSourceConfig.resolve(
context, null, "long", null, null, null, null);
ValuesSource.Numeric valuesSource = config.toValuesSource(context);
LeafReaderContext ctx = searcher.reader().leaves().get(0);
SortedNumericDocValues values = valuesSource.longValues(ctx);
values.setDocument(0);
assertEquals(0, values.count());
config = ValuesSourceConfig.resolve(
context, null, "long", null, 42, null, null);
valuesSource = config.toValuesSource(context);
values = valuesSource.longValues(ctx);
values.setDocument(0);
assertEquals(1, values.count());
assertEquals(42, values.valueAt(0));
}
}
开发者ID:justor,项目名称:elasticsearch_my,代码行数:29,代码来源:ValuesSourceConfigTests.java
示例14: testEmptyBoolean
import org.apache.lucene.index.SortedNumericDocValues; //导入依赖的package包/类
public void testEmptyBoolean() throws Exception {
IndexService indexService = createIndex("index", Settings.EMPTY, "type",
"bool", "type=boolean");
client().prepareIndex("index", "type", "1")
.setSource()
.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE)
.get();
try (Searcher searcher = indexService.getShard(0).acquireSearcher("test")) {
QueryShardContext context = indexService.newQueryShardContext(0, searcher.reader(), () -> 42L);
ValuesSourceConfig<ValuesSource.Numeric> config = ValuesSourceConfig.resolve(
context, null, "bool", null, null, null, null);
ValuesSource.Numeric valuesSource = config.toValuesSource(context);
LeafReaderContext ctx = searcher.reader().leaves().get(0);
SortedNumericDocValues values = valuesSource.longValues(ctx);
values.setDocument(0);
assertEquals(0, values.count());
config = ValuesSourceConfig.resolve(
context, null, "bool", null, true, null, null);
valuesSource = config.toValuesSource(context);
values = valuesSource.longValues(ctx);
values.setDocument(0);
assertEquals(1, values.count());
assertEquals(1, values.valueAt(0));
}
}
开发者ID:justor,项目名称:elasticsearch_my,代码行数:29,代码来源:ValuesSourceConfigTests.java
示例15: verify
import org.apache.lucene.index.SortedNumericDocValues; //导入依赖的package包/类
private void verify(SortedNumericDocValues values, int maxDoc, FixedBitSet rootDocs, FixedBitSet innerDocs) throws IOException {
for (long missingValue : new long[] { 0, randomLong() }) {
for (MultiValueMode mode : new MultiValueMode[] {MultiValueMode.MIN, MultiValueMode.MAX, MultiValueMode.SUM, MultiValueMode.AVG}) {
final NumericDocValues selected = mode.select(values, missingValue, rootDocs, new BitSetIterator(innerDocs, 0L), maxDoc);
int prevRoot = -1;
for (int root = rootDocs.nextSetBit(0); root != -1; root = root + 1 < maxDoc ? rootDocs.nextSetBit(root + 1) : -1) {
final long actual = selected.get(root);
long expected = 0;
if (mode == MultiValueMode.MAX) {
expected = Long.MIN_VALUE;
} else if (mode == MultiValueMode.MIN) {
expected = Long.MAX_VALUE;
}
int numValues = 0;
for (int child = innerDocs.nextSetBit(prevRoot + 1); child != -1 && child < root; child = innerDocs.nextSetBit(child + 1)) {
values.setDocument(child);
for (int j = 0; j < values.count(); ++j) {
if (mode == MultiValueMode.SUM || mode == MultiValueMode.AVG) {
expected += values.valueAt(j);
} else if (mode == MultiValueMode.MIN) {
expected = Math.min(expected, values.valueAt(j));
} else if (mode == MultiValueMode.MAX) {
expected = Math.max(expected, values.valueAt(j));
}
++numValues;
}
}
if (numValues == 0) {
expected = missingValue;
} else if (mode == MultiValueMode.AVG) {
expected = numValues > 1 ? Math.round((double) expected / (double) numValues) : expected;
}
assertEquals(mode.toString() + " docId=" + root, expected, actual);
prevRoot = root;
}
}
}
}
开发者ID:justor,项目名称:elasticsearch_my,代码行数:41,代码来源:MultiValueModeTests.java
示例16: testSortableLongBitsToDoubles
import org.apache.lucene.index.SortedNumericDocValues; //导入依赖的package包/类
public void testSortableLongBitsToDoubles() {
final double value = randomDouble();
final long valueBits = NumericUtils.doubleToSortableLong(value);
NumericDocValues values = new NumericDocValues() {
@Override
public long get(int docID) {
return valueBits;
}
};
SortedNumericDoubleValues asMultiDoubles = FieldData.sortableLongBitsToDoubles(DocValues.singleton(values, null));
NumericDoubleValues asDoubles = FieldData.unwrapSingleton(asMultiDoubles);
assertNotNull(asDoubles);
assertEquals(value, asDoubles.get(0), 0);
NumericDocValues backToLongs = DocValues.unwrapSingleton(FieldData.toSortableLongBits(asMultiDoubles));
assertSame(values, backToLongs);
SortedNumericDocValues multiValues = new SortedNumericDocValues() {
@Override
public long valueAt(int index) {
return valueBits;
}
@Override
public void setDocument(int doc) {
}
@Override
public int count() {
return 1;
}
};
asMultiDoubles = FieldData.sortableLongBitsToDoubles(multiValues);
assertEquals(value, asMultiDoubles.valueAt(0), 0);
assertSame(multiValues, FieldData.toSortableLongBits(asMultiDoubles));
}
开发者ID:justor,项目名称:elasticsearch_my,代码行数:41,代码来源:FieldDataTests.java
示例17: testDoublesToSortableLongBits
import org.apache.lucene.index.SortedNumericDocValues; //导入依赖的package包/类
public void testDoublesToSortableLongBits() {
final double value = randomDouble();
final long valueBits = NumericUtils.doubleToSortableLong(value);
NumericDoubleValues values = new NumericDoubleValues() {
@Override
public double get(int docID) {
return value;
}
};
SortedNumericDocValues asMultiLongs = FieldData.toSortableLongBits(FieldData.singleton(values, null));
NumericDocValues asLongs = DocValues.unwrapSingleton(asMultiLongs);
assertNotNull(asLongs);
assertEquals(valueBits, asLongs.get(0));
SortedNumericDoubleValues multiValues = new SortedNumericDoubleValues() {
@Override
public double valueAt(int index) {
return value;
}
@Override
public void setDocument(int doc) {
}
@Override
public int count() {
return 1;
}
};
asMultiLongs = FieldData.toSortableLongBits(multiValues);
assertEquals(valueBits, asMultiLongs.valueAt(0));
assertSame(multiValues, FieldData.sortableLongBitsToDoubles(asMultiLongs));
}
开发者ID:justor,项目名称:elasticsearch_my,代码行数:37,代码来源:FieldDataTests.java
示例18: testDefaults
import org.apache.lucene.index.SortedNumericDocValues; //导入依赖的package包/类
public void testDefaults() throws IOException {
String mapping = XContentFactory.jsonBuilder().startObject().startObject("type")
.startObject("properties").startObject("field").field("type", "boolean").endObject().endObject()
.endObject().endObject().string();
DocumentMapper defaultMapper = parser.parse("type", new CompressedXContent(mapping));
ParsedDocument doc = defaultMapper.parse("test", "type", "1", XContentFactory.jsonBuilder()
.startObject()
.field("field", true)
.endObject()
.bytes());
try (Directory dir = new RAMDirectory();
IndexWriter w = new IndexWriter(dir, new IndexWriterConfig(new MockAnalyzer(random())))) {
w.addDocuments(doc.docs());
try (DirectoryReader reader = DirectoryReader.open(w)) {
final LeafReader leaf = reader.leaves().get(0).reader();
// boolean fields are indexed and have doc values by default
assertEquals(new BytesRef("T"), leaf.terms("field").iterator().next());
SortedNumericDocValues values = leaf.getSortedNumericDocValues("field");
assertNotNull(values);
values.setDocument(0);
assertEquals(1, values.count());
assertEquals(1, values.valueAt(0));
}
}
}
开发者ID:justor,项目名称:elasticsearch_my,代码行数:29,代码来源:BooleanFieldMapperTests.java
示例19: getSortedNumeric
import org.apache.lucene.index.SortedNumericDocValues; //导入依赖的package包/类
@Override
public SortedNumericDocValues getSortedNumeric(FieldInfo field) throws IOException {
SortedSetEntry ss = sortedNumerics.get(field.number);
NumericEntry numericEntry = numerics.get(field.number);
final LongValues values = getNumeric(numericEntry);
if (ss.format == SORTED_SINGLE_VALUED) {
final Bits docsWithField = getMissingBits(numericEntry.missingOffset);
return DocValues.singleton(values, docsWithField);
} else if (ss.format == SORTED_WITH_ADDRESSES) {
final IndexInput data = this.data.clone();
final MonotonicBlockPackedReader ordIndex = getOrdIndexInstance(data, field, ordIndexes.get(field.number));
return new SortedNumericDocValues() {
long startOffset;
long endOffset;
@Override
public void setDocument(int doc) {
startOffset = ordIndex.get(doc);
endOffset = ordIndex.get(doc+1L);
}
@Override
public long valueAt(int index) {
return values.get(startOffset + index);
}
@Override
public int count() {
return (int) (endOffset - startOffset);
}
};
} else {
throw new AssertionError();
}
}
开发者ID:lamsfoundation,项目名称:lams,代码行数:37,代码来源:Lucene49DocValuesProducer.java
示例20: getSortedNumeric
import org.apache.lucene.index.SortedNumericDocValues; //导入依赖的package包/类
@Override
public SortedNumericDocValues getSortedNumeric(FieldInfo field) throws IOException {
SortedSetEntry ss = sortedNumerics.get(field.number);
NumericEntry numericEntry = numerics.get(field.number);
final LongValues values = getNumeric(numericEntry);
if (ss.format == SORTED_SINGLE_VALUED) {
final Bits docsWithField = getMissingBits(numericEntry.missingOffset);
return DocValues.singleton(values, docsWithField);
} else if (ss.format == SORTED_WITH_ADDRESSES) {
final MonotonicBlockPackedReader ordIndex = getOrdIndexInstance(field, ordIndexes.get(field.number));
return new SortedNumericDocValues() {
long startOffset;
long endOffset;
@Override
public void setDocument(int doc) {
startOffset = ordIndex.get(doc);
endOffset = ordIndex.get(doc+1L);
}
@Override
public long valueAt(int index) {
return values.get(startOffset + index);
}
@Override
public int count() {
return (int) (endOffset - startOffset);
}
};
} else {
throw new AssertionError();
}
}
开发者ID:lamsfoundation,项目名称:lams,代码行数:36,代码来源:Lucene410DocValuesProducer.java
注:本文中的org.apache.lucene.index.SortedNumericDocValues类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论