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

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

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

Util.getByOutput介绍

[英]Reverse lookup (lookup by output instead of by input), in the special case when your FSTs outputs are strictly ascending. This locates the input/output pair where the output is equal to the target, and will return null if that output does not exist.

NOTE: this only works with FST, only works when the outputs are ascending in order with the inputs. For example, simple ordinals (0, 1, 2, ...), or file offets (when appending to a file) fit this.
[中]在FSTs输出严格递增的特殊情况下,反向查找(按输出而不是按输入查找)。这将定位输出等于目标的输入/输出对,如果该输出不存在,将返回null。
注:这仅适用于FST,仅在输出与输入顺序递增时有效。例如,简单序数(0,1,2,…),或者文件offet(当附加到文件中时)符合此条件。

代码示例

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

/** Reverse lookup (lookup by output instead of by input),
 *  in the special case when your FSTs outputs are
 *  strictly ascending.  This locates the input/output
 *  pair where the output is equal to the target, and will
 *  return null if that output does not exist.
 *
 *  <p>NOTE: this only works with {@code FST<Long>}, only
 *  works when the outputs are ascending in order with
 *  the inputs.
 *  For example, simple ordinals (0, 1,
 *  2, ...), or file offets (when appending to a file)
 *  fit this. */
public static IntsRef getByOutput(FST<Long> fst, long targetOutput) throws IOException {
 final BytesReader in = fst.getBytesReader();
 // TODO: would be nice not to alloc this on every lookup
 FST.Arc<Long> arc = fst.getFirstArc(new FST.Arc<Long>());
 
 FST.Arc<Long> scratchArc = new FST.Arc<>();
 final IntsRefBuilder result = new IntsRefBuilder();
 return getByOutput(fst, targetOutput, in, arc, scratchArc, result);
}

代码示例来源: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.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: org.apache.servicemix.bundles/org.apache.servicemix.bundles.lucene

/** Reverse lookup (lookup by output instead of by input),
 *  in the special case when your FSTs outputs are
 *  strictly ascending.  This locates the input/output
 *  pair where the output is equal to the target, and will
 *  return null if that output does not exist.
 *
 *  <p>NOTE: this only works with {@code FST<Long>}, only
 *  works when the outputs are ascending in order with
 *  the inputs.
 *  For example, simple ordinals (0, 1,
 *  2, ...), or file offets (when appending to a file)
 *  fit this. */
public static IntsRef getByOutput(FST<Long> fst, long targetOutput) throws IOException {
 final BytesReader in = fst.getBytesReader();
 // TODO: would be nice not to alloc this on every lookup
 FST.Arc<Long> arc = fst.getFirstArc(new FST.Arc<Long>());
 
 FST.Arc<Long> scratchArc = new FST.Arc<>();
 final IntsRefBuilder result = new IntsRefBuilder();
 return getByOutput(fst, targetOutput, in, arc, scratchArc, result);
}

代码示例来源:origin: org.infinispan/infinispan-embedded-query

/** Reverse lookup (lookup by output instead of by input),
 *  in the special case when your FSTs outputs are
 *  strictly ascending.  This locates the input/output
 *  pair where the output is equal to the target, and will
 *  return null if that output does not exist.
 *
 *  <p>NOTE: this only works with {@code FST<Long>}, only
 *  works when the outputs are ascending in order with
 *  the inputs.
 *  For example, simple ordinals (0, 1,
 *  2, ...), or file offets (when appending to a file)
 *  fit this. */
public static IntsRef getByOutput(FST<Long> fst, long targetOutput) throws IOException {
 final BytesReader in = fst.getBytesReader();
 // TODO: would be nice not to alloc this on every lookup
 FST.Arc<Long> arc = fst.getFirstArc(new FST.Arc<Long>());
 
 FST.Arc<Long> scratchArc = new FST.Arc<>();
 final IntsRefBuilder result = new IntsRefBuilder();
 return getByOutput(fst, targetOutput, in, arc, scratchArc, result);
}

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

/** Reverse lookup (lookup by output instead of by input),
 *  in the special case when your FSTs outputs are
 *  strictly ascending.  This locates the input/output
 *  pair where the output is equal to the target, and will
 *  return null if that output does not exist.
 *
 *  <p>NOTE: this only works with {@code FST<Long>}, only
 *  works when the outputs are ascending in order with
 *  the inputs.
 *  For example, simple ordinals (0, 1,
 *  2, ...), or file offets (when appending to a file)
 *  fit this. */
public static IntsRef getByOutput(FST<Long> fst, long targetOutput) throws IOException {
 final BytesReader in = fst.getBytesReader();
 // TODO: would be nice not to alloc this on every lookup
 FST.Arc<Long> arc = fst.getFirstArc(new FST.Arc<Long>());
 
 FST.Arc<Long> scratchArc = new FST.Arc<>();
 final IntsRefBuilder result = new IntsRefBuilder();
 return getByOutput(fst, targetOutput, in, arc, scratchArc, result);
}

代码示例来源: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());
}

相关文章