org.apache.lucene.util.automaton.Automata.makeBinaryInterval()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(10.8k)|赞(0)|评价(0)|浏览(109)

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

Automata.makeBinaryInterval介绍

[英]Creates a new deterministic, minimal automaton accepting all binary terms in the specified interval. Note that unlike #makeDecimalInterval, the returned automaton is infinite, because terms behave like floating point numbers leading with a decimal point. However, in the special case where min == max, and both are inclusive, the automata will be finite and accept exactly one term.
[中]创建一个新的确定性最小自动机,该自动机接受指定间隔内的所有二进制项。请注意,与#makeDecimalInterval不同,返回的自动机是无限的,因为术语的行为类似于以小数点开头的浮点数。然而,在特殊情况下,当min==max且两者都包含时,自动机将是有限的,并且只接受一个项。

代码示例

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

  1. public static Automaton toAutomaton(BytesRef lowerTerm, BytesRef upperTerm, boolean includeLower, boolean includeUpper) {
  2. if (lowerTerm == null) {
  3. // makeBinaryInterval is more picky than we are:
  4. includeLower = true;
  5. }
  6. if (upperTerm == null) {
  7. // makeBinaryInterval is more picky than we are:
  8. includeUpper = true;
  9. }
  10. return Automata.makeBinaryInterval(lowerTerm, includeLower, upperTerm, includeUpper);
  11. }

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

  1. /** Test Terms.intersect on this range, and validates that it returns the same doc ids as using non-intersect TermsEnum. Returns true if
  2. * any fake terms were seen. */
  3. private static boolean checkSingleTermRange(String field, int maxDoc, Terms terms, BytesRef minTerm, BytesRef maxTerm, FixedBitSet normalDocs, FixedBitSet intersectDocs) throws IOException {
  4. //System.out.println(" check minTerm=" + minTerm.utf8ToString() + " maxTerm=" + maxTerm.utf8ToString());
  5. assert minTerm.compareTo(maxTerm) <= 0;
  6. TermsEnum termsEnum = terms.iterator();
  7. TermsEnum.SeekStatus status = termsEnum.seekCeil(minTerm);
  8. if (status != TermsEnum.SeekStatus.FOUND) {
  9. throw new RuntimeException("failed to seek to existing term field=" + field + " term=" + minTerm);
  10. }
  11. // Do "dumb" iteration to visit all terms in the range:
  12. long normalTermCount = getDocsFromTermRange(field, maxDoc, termsEnum, normalDocs, minTerm, maxTerm, false);
  13. // Now do the same operation using intersect:
  14. long intersectTermCount = getDocsFromTermRange(field, maxDoc, terms.intersect(new CompiledAutomaton(Automata.makeBinaryInterval(minTerm, true, maxTerm, false), true, false, Integer.MAX_VALUE, true), null), intersectDocs, minTerm, maxTerm, true);
  15. if (intersectTermCount > normalTermCount) {
  16. throw new RuntimeException("intersect returned too many terms: field=" + field + " intersectTermCount=" + intersectTermCount + " normalTermCount=" + normalTermCount);
  17. }
  18. if (normalDocs.equals(intersectDocs) == false) {
  19. throw new RuntimeException("intersect visited different docs than straight terms enum: " + normalDocs.cardinality() + " for straight enum, vs " + intersectDocs.cardinality() + " for intersect, minTerm=" + minTerm + " maxTerm=" + maxTerm);
  20. }
  21. //System.out.println(" docs=" + normalTermCount);
  22. //System.out.println(" " + intersectTermCount + " vs " + normalTermCount);
  23. return intersectTermCount != normalTermCount;
  24. }

代码示例来源:origin: oracle/opengrok

  1. /** {@inheritDoc} */
  2. @Override
  3. public TermsEnum getTermsEnumForSuggestions(final Terms terms) {
  4. if (terms == null) {
  5. return TermsEnum.EMPTY;
  6. }
  7. BytesRef prefix = getPrefix();
  8. if (prefix != null) {
  9. Automaton prefixAutomaton = PrefixQuery.toAutomaton(prefix);
  10. Automaton finalAutomaton;
  11. if (suggestPosition == SuggestPosition.LOWER) {
  12. Automaton binaryInt = Automata.makeBinaryInterval(
  13. getLowerTerm(), includesLower(), getUpperTerm(), includesUpper());
  14. finalAutomaton = Operations.intersection(binaryInt, prefixAutomaton);
  15. } else {
  16. Automaton binaryInt = Automata.makeBinaryInterval(null, true, getLowerTerm(), !includesLower());
  17. finalAutomaton = Operations.minus(prefixAutomaton, binaryInt, Integer.MIN_VALUE);
  18. }
  19. CompiledAutomaton compiledAutomaton = new CompiledAutomaton(finalAutomaton);
  20. try {
  21. return compiledAutomaton.getTermsEnum(terms);
  22. } catch (IOException e) {
  23. logger.log(Level.WARNING, "Could not compile automaton for range suggestions", e);
  24. }
  25. }
  26. return TermsEnum.EMPTY;
  27. }

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.lucene

  1. public static Automaton toAutomaton(BytesRef lowerTerm, BytesRef upperTerm, boolean includeLower, boolean includeUpper) {
  2. if (lowerTerm == null) {
  3. // makeBinaryInterval is more picky than we are:
  4. includeLower = true;
  5. }
  6. if (upperTerm == null) {
  7. // makeBinaryInterval is more picky than we are:
  8. includeUpper = true;
  9. }
  10. return Automata.makeBinaryInterval(lowerTerm, includeLower, upperTerm, includeUpper);
  11. }

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

  1. public static Automaton toAutomaton(BytesRef lowerTerm, BytesRef upperTerm, boolean includeLower, boolean includeUpper) {
  2. if (lowerTerm == null) {
  3. // makeBinaryInterval is more picky than we are:
  4. includeLower = true;
  5. }
  6. if (upperTerm == null) {
  7. // makeBinaryInterval is more picky than we are:
  8. includeUpper = true;
  9. }
  10. return Automata.makeBinaryInterval(lowerTerm, includeLower, upperTerm, includeUpper);
  11. }

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

  1. public static Automaton toAutomaton(BytesRef lowerTerm, BytesRef upperTerm, boolean includeLower, boolean includeUpper) {
  2. if (lowerTerm == null) {
  3. // makeBinaryInterval is more picky than we are:
  4. includeLower = true;
  5. }
  6. if (upperTerm == null) {
  7. // makeBinaryInterval is more picky than we are:
  8. includeUpper = true;
  9. }
  10. return Automata.makeBinaryInterval(lowerTerm, includeLower, upperTerm, includeUpper);
  11. }

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.lucene

  1. /** Test Terms.intersect on this range, and validates that it returns the same doc ids as using non-intersect TermsEnum. Returns true if
  2. * any fake terms were seen. */
  3. private static boolean checkSingleTermRange(String field, int maxDoc, Terms terms, BytesRef minTerm, BytesRef maxTerm, FixedBitSet normalDocs, FixedBitSet intersectDocs) throws IOException {
  4. //System.out.println(" check minTerm=" + minTerm.utf8ToString() + " maxTerm=" + maxTerm.utf8ToString());
  5. assert minTerm.compareTo(maxTerm) <= 0;
  6. TermsEnum termsEnum = terms.iterator();
  7. TermsEnum.SeekStatus status = termsEnum.seekCeil(minTerm);
  8. if (status != TermsEnum.SeekStatus.FOUND) {
  9. throw new RuntimeException("failed to seek to existing term field=" + field + " term=" + minTerm);
  10. }
  11. // Do "dumb" iteration to visit all terms in the range:
  12. long normalTermCount = getDocsFromTermRange(field, maxDoc, termsEnum, normalDocs, minTerm, maxTerm, false);
  13. // Now do the same operation using intersect:
  14. long intersectTermCount = getDocsFromTermRange(field, maxDoc, terms.intersect(new CompiledAutomaton(Automata.makeBinaryInterval(minTerm, true, maxTerm, false), true, false, Integer.MAX_VALUE, true), null), intersectDocs, minTerm, maxTerm, true);
  15. if (intersectTermCount > normalTermCount) {
  16. throw new RuntimeException("intersect returned too many terms: field=" + field + " intersectTermCount=" + intersectTermCount + " normalTermCount=" + normalTermCount);
  17. }
  18. if (normalDocs.equals(intersectDocs) == false) {
  19. throw new RuntimeException("intersect visited different docs than straight terms enum: " + normalDocs.cardinality() + " for straight enum, vs " + intersectDocs.cardinality() + " for intersect, minTerm=" + minTerm + " maxTerm=" + maxTerm);
  20. }
  21. //System.out.println(" docs=" + normalTermCount);
  22. //System.out.println(" " + intersectTermCount + " vs " + normalTermCount);
  23. return intersectTermCount != normalTermCount;
  24. }

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

  1. /** Test Terms.intersect on this range, and validates that it returns the same doc ids as using non-intersect TermsEnum. Returns true if
  2. * any fake terms were seen. */
  3. private static boolean checkSingleTermRange(String field, int maxDoc, Terms terms, BytesRef minTerm, BytesRef maxTerm, FixedBitSet normalDocs, FixedBitSet intersectDocs) throws IOException {
  4. //System.out.println(" check minTerm=" + minTerm.utf8ToString() + " maxTerm=" + maxTerm.utf8ToString());
  5. assert minTerm.compareTo(maxTerm) <= 0;
  6. TermsEnum termsEnum = terms.iterator();
  7. TermsEnum.SeekStatus status = termsEnum.seekCeil(minTerm);
  8. if (status != TermsEnum.SeekStatus.FOUND) {
  9. throw new RuntimeException("failed to seek to existing term field=" + field + " term=" + minTerm);
  10. }
  11. // Do "dumb" iteration to visit all terms in the range:
  12. long normalTermCount = getDocsFromTermRange(field, maxDoc, termsEnum, normalDocs, minTerm, maxTerm, false);
  13. // Now do the same operation using intersect:
  14. long intersectTermCount = getDocsFromTermRange(field, maxDoc, terms.intersect(new CompiledAutomaton(Automata.makeBinaryInterval(minTerm, true, maxTerm, false), true, false, Integer.MAX_VALUE, true), null), intersectDocs, minTerm, maxTerm, true);
  15. if (intersectTermCount > normalTermCount) {
  16. throw new RuntimeException("intersect returned too many terms: field=" + field + " intersectTermCount=" + intersectTermCount + " normalTermCount=" + normalTermCount);
  17. }
  18. if (normalDocs.equals(intersectDocs) == false) {
  19. throw new RuntimeException("intersect visited different docs than straight terms enum: " + normalDocs.cardinality() + " for straight enum, vs " + intersectDocs.cardinality() + " for intersect, minTerm=" + minTerm + " maxTerm=" + maxTerm);
  20. }
  21. //System.out.println(" docs=" + normalTermCount);
  22. //System.out.println(" " + intersectTermCount + " vs " + normalTermCount);
  23. return intersectTermCount != normalTermCount;
  24. }

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

  1. /** Test Terms.intersect on this range, and validates that it returns the same doc ids as using non-intersect TermsEnum. Returns true if
  2. * any fake terms were seen. */
  3. private static boolean checkSingleTermRange(String field, int maxDoc, Terms terms, BytesRef minTerm, BytesRef maxTerm, FixedBitSet normalDocs, FixedBitSet intersectDocs) throws IOException {
  4. //System.out.println(" check minTerm=" + minTerm.utf8ToString() + " maxTerm=" + maxTerm.utf8ToString());
  5. assert minTerm.compareTo(maxTerm) <= 0;
  6. TermsEnum termsEnum = terms.iterator();
  7. TermsEnum.SeekStatus status = termsEnum.seekCeil(minTerm);
  8. if (status != TermsEnum.SeekStatus.FOUND) {
  9. throw new RuntimeException("failed to seek to existing term field=" + field + " term=" + minTerm);
  10. }
  11. // Do "dumb" iteration to visit all terms in the range:
  12. long normalTermCount = getDocsFromTermRange(field, maxDoc, termsEnum, normalDocs, minTerm, maxTerm, false);
  13. // Now do the same operation using intersect:
  14. long intersectTermCount = getDocsFromTermRange(field, maxDoc, terms.intersect(new CompiledAutomaton(Automata.makeBinaryInterval(minTerm, true, maxTerm, false), true, false, Integer.MAX_VALUE, true), null), intersectDocs, minTerm, maxTerm, true);
  15. if (intersectTermCount > normalTermCount) {
  16. throw new RuntimeException("intersect returned too many terms: field=" + field + " intersectTermCount=" + intersectTermCount + " normalTermCount=" + normalTermCount);
  17. }
  18. if (normalDocs.equals(intersectDocs) == false) {
  19. throw new RuntimeException("intersect visited different docs than straight terms enum: " + normalDocs.cardinality() + " for straight enum, vs " + intersectDocs.cardinality() + " for intersect, minTerm=" + minTerm + " maxTerm=" + maxTerm);
  20. }
  21. //System.out.println(" docs=" + normalTermCount);
  22. //System.out.println(" " + intersectTermCount + " vs " + normalTermCount);
  23. return intersectTermCount != normalTermCount;
  24. }

相关文章