org.apache.lucene.util.fst.Util.toBytesRef()方法的使用及代码示例

x33g5p2x  于2022-02-01 转载在 其他  
字(7.7k)|赞(0)|评价(0)|浏览(163)

本文整理了Java中org.apache.lucene.util.fst.Util.toBytesRef()方法的一些代码示例,展示了Util.toBytesRef()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Util.toBytesRef()方法的具体详情如下:
包路径:org.apache.lucene.util.fst.Util
类名称:Util
方法名:toBytesRef

Util.toBytesRef介绍

[英]Just converts IntsRef to BytesRef; you must ensure the int values fit into a byte.
[中]只是将IntsRef转换为BytesRef;必须确保int值适合一个字节。

代码示例

代码示例来源:origin: org.apache.lucene/lucene-analyzers-common

@Override
public boolean incrementToken() throws IOException {
 if (finiteStrings == null) {
  if (wasReset == false) {
   throw new IllegalStateException("reset() missing before incrementToken");
  }
  // lazy init/consume
  Automaton automaton = toAutomaton(); // calls reset(), incrementToken() repeatedly, and end() on inputTokenStream
  finiteStrings = new LimitedFiniteStringsIterator(automaton, maxGraphExpansions);
  //note: would be nice to know the startOffset but toAutomaton doesn't capture it.  We'll assume 0
  endOffset = inputTokenStream.getAttribute(OffsetAttribute.class).endOffset();
 }
 IntsRef string = finiteStrings.next();
 if (string == null) {
  return false;
 }
 clearAttributes();
 if (finiteStrings.size() > 1) { // if number of iterated strings so far is more than one...
  posIncrAtt.setPositionIncrement(0); // stacked
 }
 offsetAtt.setOffset(0, endOffset);
 Util.toBytesRef(string, bytesAtt.builder()); // now we have UTF-8
 if (charTermAttribute != null) {
  charTermAttribute.setLength(0);
  charTermAttribute.append(bytesAtt.toUTF16());
 }
 return true;
}

代码示例来源:origin: org.elasticsearch/elasticsearch

new LimitedFiniteStringsIterator(toAutomaton(surfaceForm, ts2a), maxGraphExpansions);
for (IntsRef string; (string = finiteStrings.next()) != null; count++) {
 Util.toBytesRef(string, scratch);

代码示例来源:origin: harbby/presto-connectors

@Override
public String toString(String field) {
 StringBuilder buffer = new StringBuilder();
 BytesRefBuilder scratch = new BytesRefBuilder();
 for (IntsRef context : contexts.keySet()) {
  if (buffer.length() != 0) {
   buffer.append(",");
  } else {
   buffer.append("contexts");
   buffer.append(":[");
  }
  buffer.append(Util.toBytesRef(context, scratch).utf8ToString());
  ContextMetaData metaData = contexts.get(context);
  if (metaData.exact == false) {
   buffer.append("*");
  }
  if (metaData.boost != 0) {
   buffer.append("^");
   buffer.append(Float.toString(metaData.boost));
  }
 }
 if (buffer.length() != 0) {
  buffer.append("]");
  buffer.append(",");
 }
 return buffer.toString() + innerQuery.toString(field);
}

代码示例来源:origin: org.apache.lucene/lucene-codecs

@Override
public BytesRef lookupOrd(long ord) {
 try {
  in.setPosition(0);
  fst.getFirstArc(firstArc);
  IntsRef output = Util.getByOutput(fst, ord, in, firstArc, scratchArc, scratchInts);
  return Util.toBytesRef(output, term);
 } catch (IOException bogus) {
  throw new RuntimeException(bogus);
 }
}

代码示例来源:origin: org.apache.lucene/lucene-codecs

@Override
public BytesRef lookupOrd(int ord) {
 try {
  in.setPosition(0);
  fst.getFirstArc(firstArc);
  IntsRef output = Util.getByOutput(fst, ord, in, firstArc, scratchArc, scratchInts);
  return Util.toBytesRef(output, term);
 } catch (IOException bogus) {
  throw new RuntimeException(bogus);
 }
}

代码示例来源:origin: lintool/warcbase

public String getUrl(int id) {
 BytesRef scratchBytes = new BytesRef();
 IntsRef key = null;
 try {
  key = Util.getByOutput(fst, id);
 } catch (IOException e) {
  LOG.error("Error id " + id);
  e.printStackTrace();
  return null;
 }
 if (key == null) {
  return null;
 }
 return Util.toBytesRef(key, scratchBytes).utf8ToString();
}

代码示例来源:origin: harbby/presto-connectors

@Override
public BytesRef lookupOrd(long ord) {
 try {
  in.setPosition(0);
  fst.getFirstArc(firstArc);
  IntsRef output = Util.getByOutput(fst, ord, in, firstArc, scratchArc, scratchInts);
  term.grow(output.length);
  term.clear();
  return Util.toBytesRef(output, term);
 } catch (IOException bogus) {
  throw new RuntimeException(bogus);
 }
}

代码示例来源:origin: harbby/presto-connectors

@Override
public BytesRef lookupOrd(int ord) {
 try {
  in.setPosition(0);
  fst.getFirstArc(firstArc);
  IntsRef output = Util.getByOutput(fst, ord, in, firstArc, scratchArc, scratchInts);
  term.grow(output.length);
  term.clear();
  return Util.toBytesRef(output, term);
 } catch (IOException bogus) {
  throw new RuntimeException(bogus);
 }
}

代码示例来源:origin: org.codelibs/elasticsearch-querybuilders

Util.toBytesRef(finiteStrings.next(), bytesAtt.builder()); // now we have UTF-8
if (charTermAttribute != null) {
  charTermAttribute.setLength(0);

代码示例来源:origin: com.strapdata.elasticsearch/elasticsearch

Util.toBytesRef(finiteStrings.next(), bytesAtt.builder()); // now we have UTF-8
if (charTermAttribute != null) {
  charTermAttribute.setLength(0);

代码示例来源:origin: harbby/presto-connectors

Util.toBytesRef(finiteStrings.next(), bytesAtt.builder()); // now we have UTF-8
if (charTermAttribute != null) {
  charTermAttribute.setLength(0);

代码示例来源:origin: org.apache.lucene/lucene-codecs

@Override
public void seekExact(long ord) throws IOException {
 // TODO: would be better to make this simpler and faster.
 // but we dont want to introduce a bug that corrupts our enum state!
 bytesReader.setPosition(0);
 fst.getFirstArc(firstArc);
 IntsRef output = Util.getByOutput(fst, ord, bytesReader, firstArc, scratchArc, scratchInts);
 // TODO: we could do this lazily, better to try to push into FSTEnum though?
 in.seekExact(Util.toBytesRef(output, new BytesRefBuilder()));
}

代码示例来源:origin: harbby/presto-connectors

@Override
public void seekExact(long ord) throws IOException {
 // TODO: would be better to make this simpler and faster.
 // but we dont want to introduce a bug that corrupts our enum state!
 bytesReader.setPosition(0);
 fst.getFirstArc(firstArc);
 IntsRef output = Util.getByOutput(fst, ord, bytesReader, firstArc, scratchArc, scratchInts);
 BytesRefBuilder scratchBytes = new BytesRefBuilder();
 scratchBytes.clear();
 Util.toBytesRef(output, scratchBytes);
 // TODO: we could do this lazily, better to try to push into FSTEnum though?
 in.seekExact(scratchBytes.get());
}

代码示例来源:origin: harbby/presto-connectors

scratch.setLength(prefixLength);
Util.toBytesRef(completion.input, suffix);
scratch.append(suffix);
spare.copyUTF8Bytes(scratch.get());

代码示例来源:origin: org.apache.lucene/lucene-spellchecker

scratch.length = prefixLength;
Util.toBytesRef(completion.input, suffix);
scratch.append(suffix);
spare.grow(scratch.length);

代码示例来源:origin: harbby/presto-connectors

private void setInnerWeight(IntsRef ref, int offset) {
 IntsRefBuilder refBuilder = new IntsRefBuilder();
 for (int i = offset; i < ref.length; i++) {
  if (ref.ints[ref.offset + i] == ContextSuggestField.CONTEXT_SEPARATOR) {
   if (i > 0) {
    refBuilder.copyInts(ref.ints, ref.offset, i);
    currentContext = Util.toBytesRef(refBuilder.get(), scratch).utf8ToString();
   } else {
    currentContext = null;
   }
   ref.offset = ++i;
   assert ref.offset < ref.length : "input should not end with the context separator";
   if (ref.ints[i] == CompletionAnalyzer.SEP_LABEL) {
    ref.offset++;
    assert ref.offset < ref.length : "input should not end with a context separator followed by SEP_LABEL";
   }
   ref.length = ref.length - ref.offset;
   refBuilder.copyInts(ref.ints, ref.offset, ref.length);
   innerWeight.setNextMatch(refBuilder.get());
   return;
  }
 }
}

代码示例来源:origin: org.apache.lucene/lucene-codecs

term.grow(io.input.length);
Util.toBytesRef(io.input, term);
if (io.input.length == 0) {
 currentFrame = staticFrame;

代码示例来源:origin: harbby/presto-connectors

@Override
public boolean incrementToken() throws IOException {
 clearAttributes();
 if (finiteStrings == null) {
  Automaton automaton = toAutomaton();
  finiteStrings = new LimitedFiniteStringsIterator(automaton, maxGraphExpansions);
 }
 IntsRef string = finiteStrings.next();
 if (string == null) {
  return false;
 }
 Util.toBytesRef(string, bytesAtt.builder()); // now we have UTF-8
 if (charTermAttribute != null) {
  charTermAttribute.setLength(0);
  charTermAttribute.append(bytesAtt.toUTF16());
 }
 if (payload != null) {
  payloadAttr.setPayload(this.payload);
 }
 return true;
}

代码示例来源:origin: com.strapdata.elasticsearch/elasticsearch

new LimitedFiniteStringsIterator(toAutomaton(surfaceForm, ts2a), maxGraphExpansions);
for (IntsRef string; (string = finiteStrings.next()) != null; count++) {
 Util.toBytesRef(string, scratch);

代码示例来源:origin: apache/servicemix-bundles

new LimitedFiniteStringsIterator(toAutomaton(surfaceForm, ts2a), maxGraphExpansions);
for (IntsRef string; (string = finiteStrings.next()) != null; count++) {
 Util.toBytesRef(string, scratch);

相关文章