当前位置: 首页>>代码示例>>Java>>正文


Java BytesRef.deepCopyOf方法代码示例

本文整理汇总了Java中org.apache.lucene.util.BytesRef.deepCopyOf方法的典型用法代码示例。如果您正苦于以下问题:Java BytesRef.deepCopyOf方法的具体用法?Java BytesRef.deepCopyOf怎么用?Java BytesRef.deepCopyOf使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.lucene.util.BytesRef的用法示例。


在下文中一共展示了BytesRef.deepCopyOf方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testImmutable

import org.apache.lucene.util.BytesRef; //导入方法依赖的package包/类
public void testImmutable() throws IOException {
    BytesReference bytesReference = newBytesReference(randomIntBetween(10, 3 * PAGE_SIZE));
    BytesRef bytesRef = BytesRef.deepCopyOf(bytesReference.toBytesRef());
    ByteBuf channelBuffer = Unpooled.wrappedBuffer(bytesRef.bytes, bytesRef.offset,
        bytesRef.length);
    ByteBufBytesReference byteBufBytesReference = new ByteBufBytesReference(channelBuffer, bytesRef.length);
    assertEquals(byteBufBytesReference, bytesReference);
    channelBuffer.readInt(); // this advances the index of the channel buffer
    assertEquals(byteBufBytesReference, bytesReference);
    assertEquals(bytesRef, byteBufBytesReference.toBytesRef());

    BytesRef unicodeBytes = new BytesRef(randomUnicodeOfCodepointLength(100));
    channelBuffer = Unpooled.wrappedBuffer(unicodeBytes.bytes, unicodeBytes.offset, unicodeBytes.length);
    byteBufBytesReference = new ByteBufBytesReference(channelBuffer, unicodeBytes.length);
    String utf8ToString = byteBufBytesReference.utf8ToString();
    channelBuffer.readInt(); // this advances the index of the channel buffer
    assertEquals(utf8ToString, byteBufBytesReference.utf8ToString());
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:19,代码来源:ByteBufBytesReferenceTests.java

示例2: testEquals

import org.apache.lucene.util.BytesRef; //导入方法依赖的package包/类
public void testEquals() throws IOException {
    BytesReference bytesReference = newBytesReference(randomIntBetween(100, PAGE_SIZE * randomIntBetween(2, 5)));
    BytesReference copy = bytesReference.slice(0, bytesReference.length());

    // get refs & compare
    assertEquals(copy, bytesReference);
    int sliceFrom = randomIntBetween(0, bytesReference.length());
    int sliceLength = randomIntBetween(0, bytesReference.length() - sliceFrom);
    assertEquals(copy.slice(sliceFrom, sliceLength), bytesReference.slice(sliceFrom, sliceLength));

    BytesRef bytesRef = BytesRef.deepCopyOf(copy.toBytesRef());
    assertEquals(new BytesArray(bytesRef), copy);

    int offsetToFlip = randomIntBetween(0, bytesRef.length - 1);
    int value = ~Byte.toUnsignedInt(bytesRef.bytes[bytesRef.offset+offsetToFlip]);
    bytesRef.bytes[bytesRef.offset+offsetToFlip] = (byte)value;
    assertNotEquals(new BytesArray(bytesRef), copy);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:19,代码来源:AbstractBytesReferenceTestCase.java

示例3: next

import org.apache.lucene.util.BytesRef; //导入方法依赖的package包/类
@Override
public BytesRef next() throws IOException {
  if (queuedBottom != null) {
    bottomChanged(queuedBottom, false);
    queuedBottom = null;
  }
  
  BytesRef term = actualEnum.next();
  boostAtt.setBoost(actualBoostAtt.getBoost());
  
  final float bottom = maxBoostAtt.getMaxNonCompetitiveBoost();
  final BytesRef bottomTerm = maxBoostAtt.getCompetitiveTerm();
  if (term != null && (bottom != this.bottom || bottomTerm != this.bottomTerm)) {
    this.bottom = bottom;
    this.bottomTerm = bottomTerm;
    // clone the term before potentially doing something with it
    // this is a rare but wonderful occurrence anyway
    queuedBottom = BytesRef.deepCopyOf(term);
  }
  
  return term;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:23,代码来源:FuzzyTermsEnum.java

示例4: analyzeMultitermTerm

import org.apache.lucene.util.BytesRef; //导入方法依赖的package包/类
protected BytesRef analyzeMultitermTerm(String field, String part, Analyzer analyzerIn) {
  if (analyzerIn == null) analyzerIn = getAnalyzer();

  TokenStream source = null;
  try {
    source = analyzerIn.tokenStream(field, part);
    source.reset();
    
    TermToBytesRefAttribute termAtt = source.getAttribute(TermToBytesRefAttribute.class);
    BytesRef bytes = termAtt.getBytesRef();

    if (!source.incrementToken())
      throw new IllegalArgumentException("analyzer returned no terms for multiTerm term: " + part);
    termAtt.fillBytesRef();
    if (source.incrementToken())
      throw new IllegalArgumentException("analyzer returned too many terms for multiTerm term: " + part);
    source.end();
    return BytesRef.deepCopyOf(bytes);
  } catch (IOException e) {
    throw new RuntimeException("Error analyzing multiTerm term: " + part, e);
  } finally {
    IOUtils.closeWhileHandlingException(source);
  }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:25,代码来源:QueryParserBase.java

示例5: copy

import org.apache.lucene.util.BytesRef; //导入方法依赖的package包/类
@Override
public BytesRef copy(BytesRef value, BytesRef reuse) {
    if (value == null) {
        return null;
    }
    if (reuse != null) {
        reuse.bytes = ArrayUtil.grow(reuse.bytes, value.length);
        reuse.offset = 0;
        reuse.length = value.length;
        System.arraycopy(value.bytes, value.offset, reuse.bytes, 0, value.length);
        return reuse;
    } else {
        return BytesRef.deepCopyOf(value);
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:16,代码来源:CollapsingDocValuesSource.java

示例6: WrapperQueryBuilder

import org.apache.lucene.util.BytesRef; //导入方法依赖的package包/类
/**
 * Creates a query builder given a query provided as a {@link BytesReference}
 */
public WrapperQueryBuilder(BytesReference source) {
    if (source == null || source.length() == 0) {
        throw new IllegalArgumentException("query source text cannot be null or empty");
    }
    this.source = BytesRef.deepCopyOf(source.toBytesRef()).bytes;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:10,代码来源:WrapperQueryBuilder.java

示例7: BytesArray

import org.apache.lucene.util.BytesRef; //导入方法依赖的package包/类
public BytesArray(BytesRef bytesRef, boolean deepCopy) {
    if (deepCopy) {
        bytesRef = BytesRef.deepCopyOf(bytesRef);
    }
    bytes = bytesRef.bytes;
    offset = bytesRef.offset;
    length = bytesRef.length;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:9,代码来源:BytesArray.java

示例8: toBytes

import org.apache.lucene.util.BytesRef; //导入方法依赖的package包/类
/**
 * Returns a compact array from the given BytesReference. The returned array won't be copied unless necessary. If you need
 * to modify the returned array use <tt>BytesRef.deepCopyOf(reference.toBytesRef()</tt> instead
 */
public static byte[] toBytes(BytesReference reference) {
    final BytesRef bytesRef = reference.toBytesRef();
    if (bytesRef.offset == 0 && bytesRef.length == bytesRef.bytes.length) {
        return bytesRef.bytes;
    }
    return BytesRef.deepCopyOf(bytesRef).bytes;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:12,代码来源:BytesReference.java

示例9: testSingleValuedStrings

import org.apache.lucene.util.BytesRef; //导入方法依赖的package包/类
public void testSingleValuedStrings() throws Exception  {
    final int numDocs = scaledRandomIntBetween(1, 100);
    final BytesRef[] array = new BytesRef[numDocs];
    final FixedBitSet docsWithValue = randomBoolean() ? null : new FixedBitSet(numDocs);
    for (int i = 0; i < array.length; ++i) {
        if (randomBoolean()) {
            array[i] = new BytesRef(RandomStrings.randomAsciiOfLength(random(), 8));
            if (docsWithValue != null) {
                docsWithValue.set(i);
            }
        } else {
            array[i] = new BytesRef();
            if (docsWithValue != null && randomBoolean()) {
                docsWithValue.set(i);
            }
        }
    }
    final BinaryDocValues singleValues = new BinaryDocValues() {
        @Override
        public BytesRef get(int docID) {
            return BytesRef.deepCopyOf(array[docID]);
        }
    };
    final SortedBinaryDocValues multiValues = FieldData.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,代码行数:30,代码来源:MultiValueModeTests.java

示例10: verify

import org.apache.lucene.util.BytesRef; //导入方法依赖的package包/类
private void verify(SortedBinaryDocValues values, int maxDoc) {
    for (BytesRef missingValue : new BytesRef[] { new BytesRef(), new BytesRef(RandomStrings.randomAsciiOfLength(random(), 8)) }) {
        for (MultiValueMode mode : new MultiValueMode[] {MultiValueMode.MIN, MultiValueMode.MAX}) {
            final BinaryDocValues selected = mode.select(values, missingValue);
            for (int i = 0; i < maxDoc; ++i) {
                final BytesRef actual = selected.get(i);
                BytesRef expected = null;
                values.setDocument(i);
                int numValues = values.count();
                if (numValues == 0) {
                    expected = missingValue;
                } else {
                    for (int j = 0; j < numValues; ++j) {
                        if (expected == null) {
                            expected = BytesRef.deepCopyOf(values.valueAt(j));
                        } else {
                            if (mode == MultiValueMode.MIN) {
                                expected = expected.compareTo(values.valueAt(j)) <= 0 ? expected : BytesRef.deepCopyOf(values.valueAt(j));
                            } else if (mode == MultiValueMode.MAX) {
                                expected = expected.compareTo(values.valueAt(j)) > 0 ? expected : BytesRef.deepCopyOf(values.valueAt(j));
                            }
                        }
                    }
                    if (expected == null) {
                        expected = missingValue;
                    }
                }

                assertEquals(mode.toString() + " docId=" + i, expected, actual);
            }
        }
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:34,代码来源:MultiValueModeTests.java

示例11: getSpanQuery

import org.apache.lucene.util.BytesRef; //导入方法依赖的package包/类
@Override
public SpanQuery getSpanQuery(Element e) throws ParserException {
  String fieldName = DOMUtils.getAttributeWithInheritanceOrFail(e, "fieldName");
  String value = DOMUtils.getNonBlankTextOrFail(e);

  List<SpanQuery> clausesList = new ArrayList<>();

  TokenStream ts = null;
  try {
    ts = analyzer.tokenStream(fieldName, value);
    TermToBytesRefAttribute termAtt = ts.addAttribute(TermToBytesRefAttribute.class);
    BytesRef bytes = termAtt.getBytesRef();
    ts.reset();
    while (ts.incrementToken()) {
      termAtt.fillBytesRef();
      SpanTermQuery stq = new SpanTermQuery(new Term(fieldName, BytesRef.deepCopyOf(bytes)));
      clausesList.add(stq);
    }
    ts.end();
    SpanOrQuery soq = new SpanOrQuery(clausesList.toArray(new SpanQuery[clausesList.size()]));
    soq.setBoost(DOMUtils.getAttribute(e, "boost", 1.0f));
    return soq;
  }
  catch (IOException ioe) {
    throw new ParserException("IOException parsing value:" + value);
  } finally {
    IOUtils.closeWhileHandlingException(ts);
  }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:30,代码来源:SpanOrTermsBuilder.java

示例12: value

import org.apache.lucene.util.BytesRef; //导入方法依赖的package包/类
@Override
public BytesRef value() throws ValidationException {
    switch (values.cardinality()) {
        case 0:
            return null;
        case 1:
            return BytesRef.deepCopyOf(values.lookupOrd(values.ordAt(0)));
        default:
            throw new GroupByOnArrayUnsupportedException(columnName());
    }
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:12,代码来源:BytesRefColumnReference.java

示例13: BytesArray

import org.apache.lucene.util.BytesRef; //导入方法依赖的package包/类
public BytesArray(BytesRef bytesRef, boolean deepCopy) {
    if (deepCopy) {
        BytesRef copy = BytesRef.deepCopyOf(bytesRef);
        bytes = copy.bytes;
        offset = copy.offset;
        length = copy.length;
    } else {
        bytes = bytesRef.bytes;
        offset = bytesRef.offset;
        length = bytesRef.length;
    }
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:13,代码来源:BytesArray.java

示例14: addSurface

import org.apache.lucene.util.BytesRef; //导入方法依赖的package包/类
public void addSurface(BytesRef surface, BytesRef payload, long cost) throws IOException {
    int surfaceIndex = -1;
    long encodedWeight = cost == -1 ? cost : encodeWeight(cost);
    /*
     * we need to check if we have seen this surface form, if so only use the
     * the surface form with the highest weight and drop the rest no matter if
     * the payload differs.
     */
    if (count >= maxSurfaceFormsPerAnalyzedForm) {
        // More than maxSurfaceFormsPerAnalyzedForm
        // dups: skip the rest:
        return;
    }

    BytesRef surfaceCopy;
    final int keySlot;
    if (count > 0 && (keySlot = seenSurfaceForms.indexOf(surface)) >= 0) {
        surfaceIndex = seenSurfaceForms.indexGet(keySlot);
        SurfaceFormAndPayload surfaceFormAndPayload = surfaceFormsAndPayload[surfaceIndex];
        if (encodedWeight >= surfaceFormAndPayload.weight) {
            return;
        }
        surfaceCopy = BytesRef.deepCopyOf(surface);
    } else {
        surfaceIndex = count++;
        surfaceCopy = BytesRef.deepCopyOf(surface);
        seenSurfaceForms.put(surfaceCopy, surfaceIndex);
    }

    BytesRef payloadRef;
    if (!hasPayloads) {
        payloadRef = surfaceCopy;
    } else {
        int len = surface.length + 1 + payload.length;
        final BytesRef br = new BytesRef(len);
        System.arraycopy(surface.bytes, surface.offset, br.bytes, 0, surface.length);
        br.bytes[surface.length] = (byte) payloadSep;
        System.arraycopy(payload.bytes, payload.offset, br.bytes, surface.length + 1, payload.length);
        br.length = len;
        payloadRef = br;
    }
    if (surfaceFormsAndPayload[surfaceIndex] == null) {
        surfaceFormsAndPayload[surfaceIndex] = new SurfaceFormAndPayload(payloadRef, encodedWeight);
    } else {
        surfaceFormsAndPayload[surfaceIndex].payload = payloadRef;
        surfaceFormsAndPayload[surfaceIndex].weight = encodedWeight;
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:49,代码来源:XAnalyzingSuggester.java

示例15: testThreads

import org.apache.lucene.util.BytesRef; //导入方法依赖的package包/类
public void testThreads() throws Exception {
    final ParentChildIndexFieldData indexFieldData = getForField(childType);
    final DirectoryReader reader = ElasticsearchDirectoryReader.wrap(
            DirectoryReader.open(writer), new ShardId(new Index("test", ""), 0));
    final IndexParentChildFieldData global = indexFieldData.loadGlobal(reader);
    final AtomicReference<Exception> error = new AtomicReference<>();
    final int numThreads = scaledRandomIntBetween(3, 8);
    final Thread[] threads = new Thread[numThreads];
    final CountDownLatch latch = new CountDownLatch(1);

    final Map<Object, BytesRef[]> expected = new HashMap<>();
    for (LeafReaderContext context : reader.leaves()) {
        AtomicParentChildFieldData leafData = global.load(context);
        SortedDocValues parentIds = leafData.getOrdinalsValues(parentType);
        final BytesRef[] ids = new BytesRef[parentIds.getValueCount()];
        for (int j = 0; j < parentIds.getValueCount(); ++j) {
            final BytesRef id = parentIds.lookupOrd(j);
            if (id != null) {
                ids[j] = BytesRef.deepCopyOf(id);
            }
        }
        expected.put(context.reader().getCoreCacheKey(), ids);
    }

    for (int i = 0; i < numThreads; ++i) {
        threads[i] = new Thread() {
            @Override
            public void run() {
                try {
                    latch.await();
                    for (int i = 0; i < 100000; ++i) {
                        for (LeafReaderContext context : reader.leaves()) {
                            AtomicParentChildFieldData leafData = global.load(context);
                            SortedDocValues parentIds = leafData.getOrdinalsValues(parentType);
                            final BytesRef[] expectedIds = expected.get(context.reader().getCoreCacheKey());
                            for (int j = 0; j < parentIds.getValueCount(); ++j) {
                                final BytesRef id = parentIds.lookupOrd(j);
                                assertEquals(expectedIds[j], id);
                            }
                        }
                    }
                } catch (Exception e) {
                    error.compareAndSet(null, e);
                }
            }
        };
        threads[i].start();
    }
    latch.countDown();
    for (Thread thread : threads) {
        thread.join();
    }
    if (error.get() != null) {
        throw error.get();
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:57,代码来源:ParentChildFieldDataTests.java


注:本文中的org.apache.lucene.util.BytesRef.deepCopyOf方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。