Java Code Examples for org.apache.lucene.util.ArrayUtil#parseInt()

The following examples show how to use org.apache.lucene.util.ArrayUtil#parseInt() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: IntegerEncoder.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
public BytesRef encode(char[] buffer, int offset, int length) {
  int payload = ArrayUtil.parseInt(buffer, offset, length);//TODO: improve this so that we don't have to new Strings
  byte[] bytes = PayloadHelper.encodeInt(payload);
  BytesRef result = new BytesRef(bytes);
  return result;
}
 
Example 2
Source File: SimpleTextStoredFieldsReader.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
private int parseIntAt(int offset) {
  scratchUTF16.copyUTF8Bytes(scratch.bytes(), offset, scratch.length()-offset);
  return ArrayUtil.parseInt(scratchUTF16.chars(), 0, scratchUTF16.length());
}
 
Example 3
Source File: SimpleTextLiveDocsFormat.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
private int parseIntAt(BytesRef bytes, int offset, CharsRefBuilder scratch) {
  scratch.copyUTF8Bytes(bytes.bytes, bytes.offset + offset, bytes.length-offset);
  return ArrayUtil.parseInt(scratch.chars(), 0, scratch.length());
}
 
Example 4
Source File: SimpleTextTermVectorsReader.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
private int parseIntAt(int offset) {
  scratchUTF16.copyUTF8Bytes(scratch.bytes(), offset, scratch.length()-offset);
  return ArrayUtil.parseInt(scratchUTF16.chars(), 0, scratchUTF16.length());
}
 
Example 5
Source File: SimpleTextFieldsReader.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
private void loadTerms() throws IOException {
  PositiveIntOutputs posIntOutputs = PositiveIntOutputs.getSingleton();
  final FSTCompiler<PairOutputs.Pair<Long,PairOutputs.Pair<Long,Long>>> fstCompiler;
  final PairOutputs<Long,Long> outputsInner = new PairOutputs<>(posIntOutputs, posIntOutputs);
  final PairOutputs<Long,PairOutputs.Pair<Long,Long>> outputs = new PairOutputs<>(posIntOutputs,
      outputsInner);
  fstCompiler = new FSTCompiler<>(FST.INPUT_TYPE.BYTE1, outputs);
  IndexInput in = SimpleTextFieldsReader.this.in.clone();
  in.seek(termsStart);
  final BytesRefBuilder lastTerm = new BytesRefBuilder();
  long lastDocsStart = -1;
  int docFreq = 0;
  long totalTermFreq = 0;
  FixedBitSet visitedDocs = new FixedBitSet(maxDoc);
  final IntsRefBuilder scratchIntsRef = new IntsRefBuilder();
  while(true) {
    SimpleTextUtil.readLine(in, scratch);
    if (scratch.get().equals(END) || StringHelper.startsWith(scratch.get(), FIELD)) {
      if (lastDocsStart != -1) {
        fstCompiler.add(Util.toIntsRef(lastTerm.get(), scratchIntsRef),
            outputs.newPair(lastDocsStart,
                outputsInner.newPair((long) docFreq, totalTermFreq)));
        sumTotalTermFreq += totalTermFreq;
      }
      break;
    } else if (StringHelper.startsWith(scratch.get(), DOC)) {
      docFreq++;
      sumDocFreq++;
      totalTermFreq++;
      scratchUTF16.copyUTF8Bytes(scratch.bytes(), DOC.length, scratch.length()-DOC.length);
      int docID = ArrayUtil.parseInt(scratchUTF16.chars(), 0, scratchUTF16.length());
      visitedDocs.set(docID);
    } else if (StringHelper.startsWith(scratch.get(), FREQ)) {
      scratchUTF16.copyUTF8Bytes(scratch.bytes(), FREQ.length, scratch.length()-FREQ.length);
      totalTermFreq += ArrayUtil.parseInt(scratchUTF16.chars(), 0, scratchUTF16.length()) - 1;
    } else if (StringHelper.startsWith(scratch.get(), TERM)) {
      if (lastDocsStart != -1) {
        fstCompiler.add(Util.toIntsRef(lastTerm.get(), scratchIntsRef), outputs.newPair(lastDocsStart,
            outputsInner.newPair((long) docFreq, totalTermFreq)));
      }
      lastDocsStart = in.getFilePointer();
      final int len = scratch.length() - TERM.length;
      lastTerm.grow(len);
      System.arraycopy(scratch.bytes(), TERM.length, lastTerm.bytes(), 0, len);
      lastTerm.setLength(len);
      docFreq = 0;
      sumTotalTermFreq += totalTermFreq;
      totalTermFreq = 0;
      termCount++;
    }
  }
  docCount = visitedDocs.cardinality();
  fst = fstCompiler.compile();
  /*
  PrintStream ps = new PrintStream("out.dot");
  fst.toDot(ps);
  ps.close();
  System.out.println("SAVED out.dot");
  */
  //System.out.println("FST " + fst.sizeInBytes());
}