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

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

本文整理了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

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

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

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

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

  1. @Override
  2. public String toString(String field) {
  3. StringBuilder buffer = new StringBuilder();
  4. BytesRefBuilder scratch = new BytesRefBuilder();
  5. for (IntsRef context : contexts.keySet()) {
  6. if (buffer.length() != 0) {
  7. buffer.append(",");
  8. } else {
  9. buffer.append("contexts");
  10. buffer.append(":[");
  11. }
  12. buffer.append(Util.toBytesRef(context, scratch).utf8ToString());
  13. ContextMetaData metaData = contexts.get(context);
  14. if (metaData.exact == false) {
  15. buffer.append("*");
  16. }
  17. if (metaData.boost != 0) {
  18. buffer.append("^");
  19. buffer.append(Float.toString(metaData.boost));
  20. }
  21. }
  22. if (buffer.length() != 0) {
  23. buffer.append("]");
  24. buffer.append(",");
  25. }
  26. return buffer.toString() + innerQuery.toString(field);
  27. }

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

  1. @Override
  2. public BytesRef lookupOrd(long ord) {
  3. try {
  4. in.setPosition(0);
  5. fst.getFirstArc(firstArc);
  6. IntsRef output = Util.getByOutput(fst, ord, in, firstArc, scratchArc, scratchInts);
  7. return Util.toBytesRef(output, term);
  8. } catch (IOException bogus) {
  9. throw new RuntimeException(bogus);
  10. }
  11. }

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

  1. @Override
  2. public BytesRef lookupOrd(int ord) {
  3. try {
  4. in.setPosition(0);
  5. fst.getFirstArc(firstArc);
  6. IntsRef output = Util.getByOutput(fst, ord, in, firstArc, scratchArc, scratchInts);
  7. return Util.toBytesRef(output, term);
  8. } catch (IOException bogus) {
  9. throw new RuntimeException(bogus);
  10. }
  11. }

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

  1. public String getUrl(int id) {
  2. BytesRef scratchBytes = new BytesRef();
  3. IntsRef key = null;
  4. try {
  5. key = Util.getByOutput(fst, id);
  6. } catch (IOException e) {
  7. LOG.error("Error id " + id);
  8. e.printStackTrace();
  9. return null;
  10. }
  11. if (key == null) {
  12. return null;
  13. }
  14. return Util.toBytesRef(key, scratchBytes).utf8ToString();
  15. }

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

  1. @Override
  2. public BytesRef lookupOrd(long ord) {
  3. try {
  4. in.setPosition(0);
  5. fst.getFirstArc(firstArc);
  6. IntsRef output = Util.getByOutput(fst, ord, in, firstArc, scratchArc, scratchInts);
  7. term.grow(output.length);
  8. term.clear();
  9. return Util.toBytesRef(output, term);
  10. } catch (IOException bogus) {
  11. throw new RuntimeException(bogus);
  12. }
  13. }

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

  1. @Override
  2. public BytesRef lookupOrd(int ord) {
  3. try {
  4. in.setPosition(0);
  5. fst.getFirstArc(firstArc);
  6. IntsRef output = Util.getByOutput(fst, ord, in, firstArc, scratchArc, scratchInts);
  7. term.grow(output.length);
  8. term.clear();
  9. return Util.toBytesRef(output, term);
  10. } catch (IOException bogus) {
  11. throw new RuntimeException(bogus);
  12. }
  13. }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

  1. private void setInnerWeight(IntsRef ref, int offset) {
  2. IntsRefBuilder refBuilder = new IntsRefBuilder();
  3. for (int i = offset; i < ref.length; i++) {
  4. if (ref.ints[ref.offset + i] == ContextSuggestField.CONTEXT_SEPARATOR) {
  5. if (i > 0) {
  6. refBuilder.copyInts(ref.ints, ref.offset, i);
  7. currentContext = Util.toBytesRef(refBuilder.get(), scratch).utf8ToString();
  8. } else {
  9. currentContext = null;
  10. }
  11. ref.offset = ++i;
  12. assert ref.offset < ref.length : "input should not end with the context separator";
  13. if (ref.ints[i] == CompletionAnalyzer.SEP_LABEL) {
  14. ref.offset++;
  15. assert ref.offset < ref.length : "input should not end with a context separator followed by SEP_LABEL";
  16. }
  17. ref.length = ref.length - ref.offset;
  18. refBuilder.copyInts(ref.ints, ref.offset, ref.length);
  19. innerWeight.setNextMatch(refBuilder.get());
  20. return;
  21. }
  22. }
  23. }

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

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

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

  1. @Override
  2. public boolean incrementToken() throws IOException {
  3. clearAttributes();
  4. if (finiteStrings == null) {
  5. Automaton automaton = toAutomaton();
  6. finiteStrings = new LimitedFiniteStringsIterator(automaton, maxGraphExpansions);
  7. }
  8. IntsRef string = finiteStrings.next();
  9. if (string == null) {
  10. return false;
  11. }
  12. Util.toBytesRef(string, bytesAtt.builder()); // now we have UTF-8
  13. if (charTermAttribute != null) {
  14. charTermAttribute.setLength(0);
  15. charTermAttribute.append(bytesAtt.toUTF16());
  16. }
  17. if (payload != null) {
  18. payloadAttr.setPayload(this.payload);
  19. }
  20. return true;
  21. }

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

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

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

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

相关文章