Package org.apache.lucene.util

Examples of org.apache.lucene.util.BytesRef


    HashSet<BytesRef> uniqueValues = new HashSet<BytesRef>();
    int minLength = Integer.MAX_VALUE;
    int maxLength = Integer.MIN_VALUE;
    for (BytesRef b : values) {
      if (b == null) {
        b = new BytesRef(); // 4.0 doesnt distinguish
      }
      if (b.length > Lucene40DocValuesFormat.MAX_BINARY_FIELD_LENGTH) {
        throw new IllegalArgumentException("DocValuesField \"" + field.name + "\" is too large, must be <= " + Lucene40DocValuesFormat.MAX_BINARY_FIELD_LENGTH);
      }
      minLength = Math.min(minLength, b.length);
View Full Code Here


                          Lucene40DocValuesFormat.BYTES_FIXED_DEREF_VERSION_CURRENT);
   
    // deduplicate
    TreeSet<BytesRef> dictionary = new TreeSet<BytesRef>();
    for (BytesRef v : values) {
      dictionary.add(v == null ? new BytesRef() : BytesRef.deepCopyOf(v));
    }
   
    /* values */
    data.writeInt(length);
    for (BytesRef v : dictionary) {
      data.writeBytes(v.bytes, v.offset, v.length);
    }
   
    /* ordinals */
    int valueCount = dictionary.size();
    assert valueCount > 0;
    index.writeInt(valueCount);
    final int maxDoc = state.segmentInfo.getDocCount();
    final PackedInts.Writer w = PackedInts.getWriter(index, maxDoc, PackedInts.bitsRequired(valueCount-1), PackedInts.DEFAULT);

    for (BytesRef v : values) {
      if (v == null) {
        v = new BytesRef();
      }
      int ord = dictionary.headSet(v).size();
      w.add(ord);
    }
    w.finish();
View Full Code Here

                          Lucene40DocValuesFormat.BYTES_VAR_DEREF_VERSION_CURRENT);
   
    // deduplicate
    TreeSet<BytesRef> dictionary = new TreeSet<BytesRef>();
    for (BytesRef v : values) {
      dictionary.add(v == null ? new BytesRef() : BytesRef.deepCopyOf(v));
    }
   
    /* values */
    long startPosition = data.getFilePointer();
    long currentAddress = 0;
    HashMap<BytesRef,Long> valueToAddress = new HashMap<BytesRef,Long>();
    for (BytesRef v : dictionary) {
      currentAddress = data.getFilePointer() - startPosition;
      valueToAddress.put(v, currentAddress);
      writeVShort(data, v.length);
      data.writeBytes(v.bytes, v.offset, v.length);
    }
   
    /* ordinals */
    long totalBytes = data.getFilePointer() - startPosition;
    index.writeLong(totalBytes);
    final int maxDoc = state.segmentInfo.getDocCount();
    final PackedInts.Writer w = PackedInts.getWriter(index, maxDoc, PackedInts.bitsRequired(currentAddress), PackedInts.DEFAULT);

    for (BytesRef v : values) {
      w.add(valueToAddress.get(v == null ? new BytesRef() : v));
    }
    w.finish();
  }
View Full Code Here

public class MockUTF16TermAttributeImpl extends CharTermAttributeImpl {
  static final Charset charset = Charset.forName("UTF-16LE");
 
  @Override
  public int fillBytesRef() {
    BytesRef bytes = getBytesRef();
    byte[] utf16 = toString().getBytes(charset);
    bytes.bytes = utf16;
    bytes.offset = 0;
    bytes.length = utf16.length;
    return bytes.hashCode();
  }
View Full Code Here

    }

    @Override
    public BytesRef getPayload() {
      if (current.payloads != null && current.payloads[posUpto-1] != null) {
        return new BytesRef(current.payloads[posUpto-1]);
      } else {
        return null;
      }
    }
View Full Code Here

   
    int numChecks = atLeast(100);
    for (int i = 0; i < numChecks; i++) {
      String start = _TestUtil.randomSimpleString(random());
      String end = _TestUtil.randomSimpleString(random());
      BytesRef lowerVal = new BytesRef(collator.getCollationKey(start).toByteArray());
      BytesRef upperVal = new BytesRef(collator.getCollationKey(end).toByteArray());
      Query query = new ConstantScoreQuery(FieldCacheRangeFilter.newBytesRefRange("collated", lowerVal, upperVal, true, true));
      doTestRanges(is, start, end, query, collator);
    }
   
    ir.close();
View Full Code Here

      assertEquals(Double.parseDouble(expected), groupValue);
    } else if (Long.class.isAssignableFrom(groupValue.getClass())) {
      assertEquals(Long.parseLong(expected), groupValue);
    } else if (MutableValue.class.isAssignableFrom(groupValue.getClass())) {
      MutableValueStr mutableValue = new MutableValueStr();
      mutableValue.value = new BytesRef(expected);
      assertEquals(mutableValue, groupValue);
    } else {
      fail();
    }
  }
View Full Code Here

    switch (type) {
      case NUMERIC:
        valuesField = new NumericDocValuesField(dvField, Integer.parseInt(value));
        break;
      case BINARY:
        valuesField = new BinaryDocValuesField(dvField, new BytesRef(value));
        break;
      case SORTED:
        valuesField = new SortedDocValuesField(dvField, new BytesRef(value));
        break;
    }
    doc.add(valuesField);
  }
View Full Code Here

      if (topN <= i++) {
        break;
      }
      Set<BytesRef> uniqueValues = new HashSet<BytesRef>();
      for (String val : groupCounts.get(group)) {
        uniqueValues.add(val != null ? new BytesRef(val) : null);
      }
      result.add(new GroupCount(group != null ? new BytesRef(group) : null, uniqueValues));
    }
    return result;
  }
View Full Code Here

  }

  private void addGroupField(Document doc, String groupField, String value, boolean canUseIDV) {
    doc.add(new TextField(groupField, value, Field.Store.YES));
    if (canUseIDV) {
      doc.add(new SortedDocValuesField(groupField, new BytesRef(value)));
    }
  }
View Full Code Here

TOP

Related Classes of org.apache.lucene.util.BytesRef

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.