本文整理了Java中org.apache.lucene.util.automaton.Automata.makeBinaryInterval()
方法的一些代码示例,展示了Automata.makeBinaryInterval()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Automata.makeBinaryInterval()
方法的具体详情如下:
包路径:org.apache.lucene.util.automaton.Automata
类名称: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
public static Automaton toAutomaton(BytesRef lowerTerm, BytesRef upperTerm, boolean includeLower, boolean includeUpper) {
if (lowerTerm == null) {
// makeBinaryInterval is more picky than we are:
includeLower = true;
}
if (upperTerm == null) {
// makeBinaryInterval is more picky than we are:
includeUpper = true;
}
return Automata.makeBinaryInterval(lowerTerm, includeLower, upperTerm, includeUpper);
}
代码示例来源:origin: org.apache.lucene/lucene-core
/** Test Terms.intersect on this range, and validates that it returns the same doc ids as using non-intersect TermsEnum. Returns true if
* any fake terms were seen. */
private static boolean checkSingleTermRange(String field, int maxDoc, Terms terms, BytesRef minTerm, BytesRef maxTerm, FixedBitSet normalDocs, FixedBitSet intersectDocs) throws IOException {
//System.out.println(" check minTerm=" + minTerm.utf8ToString() + " maxTerm=" + maxTerm.utf8ToString());
assert minTerm.compareTo(maxTerm) <= 0;
TermsEnum termsEnum = terms.iterator();
TermsEnum.SeekStatus status = termsEnum.seekCeil(minTerm);
if (status != TermsEnum.SeekStatus.FOUND) {
throw new RuntimeException("failed to seek to existing term field=" + field + " term=" + minTerm);
}
// Do "dumb" iteration to visit all terms in the range:
long normalTermCount = getDocsFromTermRange(field, maxDoc, termsEnum, normalDocs, minTerm, maxTerm, false);
// Now do the same operation using intersect:
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);
if (intersectTermCount > normalTermCount) {
throw new RuntimeException("intersect returned too many terms: field=" + field + " intersectTermCount=" + intersectTermCount + " normalTermCount=" + normalTermCount);
}
if (normalDocs.equals(intersectDocs) == false) {
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);
}
//System.out.println(" docs=" + normalTermCount);
//System.out.println(" " + intersectTermCount + " vs " + normalTermCount);
return intersectTermCount != normalTermCount;
}
代码示例来源:origin: oracle/opengrok
/** {@inheritDoc} */
@Override
public TermsEnum getTermsEnumForSuggestions(final Terms terms) {
if (terms == null) {
return TermsEnum.EMPTY;
}
BytesRef prefix = getPrefix();
if (prefix != null) {
Automaton prefixAutomaton = PrefixQuery.toAutomaton(prefix);
Automaton finalAutomaton;
if (suggestPosition == SuggestPosition.LOWER) {
Automaton binaryInt = Automata.makeBinaryInterval(
getLowerTerm(), includesLower(), getUpperTerm(), includesUpper());
finalAutomaton = Operations.intersection(binaryInt, prefixAutomaton);
} else {
Automaton binaryInt = Automata.makeBinaryInterval(null, true, getLowerTerm(), !includesLower());
finalAutomaton = Operations.minus(prefixAutomaton, binaryInt, Integer.MIN_VALUE);
}
CompiledAutomaton compiledAutomaton = new CompiledAutomaton(finalAutomaton);
try {
return compiledAutomaton.getTermsEnum(terms);
} catch (IOException e) {
logger.log(Level.WARNING, "Could not compile automaton for range suggestions", e);
}
}
return TermsEnum.EMPTY;
}
代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.lucene
public static Automaton toAutomaton(BytesRef lowerTerm, BytesRef upperTerm, boolean includeLower, boolean includeUpper) {
if (lowerTerm == null) {
// makeBinaryInterval is more picky than we are:
includeLower = true;
}
if (upperTerm == null) {
// makeBinaryInterval is more picky than we are:
includeUpper = true;
}
return Automata.makeBinaryInterval(lowerTerm, includeLower, upperTerm, includeUpper);
}
代码示例来源:origin: org.infinispan/infinispan-embedded-query
public static Automaton toAutomaton(BytesRef lowerTerm, BytesRef upperTerm, boolean includeLower, boolean includeUpper) {
if (lowerTerm == null) {
// makeBinaryInterval is more picky than we are:
includeLower = true;
}
if (upperTerm == null) {
// makeBinaryInterval is more picky than we are:
includeUpper = true;
}
return Automata.makeBinaryInterval(lowerTerm, includeLower, upperTerm, includeUpper);
}
代码示例来源:origin: harbby/presto-connectors
public static Automaton toAutomaton(BytesRef lowerTerm, BytesRef upperTerm, boolean includeLower, boolean includeUpper) {
if (lowerTerm == null) {
// makeBinaryInterval is more picky than we are:
includeLower = true;
}
if (upperTerm == null) {
// makeBinaryInterval is more picky than we are:
includeUpper = true;
}
return Automata.makeBinaryInterval(lowerTerm, includeLower, upperTerm, includeUpper);
}
代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.lucene
/** Test Terms.intersect on this range, and validates that it returns the same doc ids as using non-intersect TermsEnum. Returns true if
* any fake terms were seen. */
private static boolean checkSingleTermRange(String field, int maxDoc, Terms terms, BytesRef minTerm, BytesRef maxTerm, FixedBitSet normalDocs, FixedBitSet intersectDocs) throws IOException {
//System.out.println(" check minTerm=" + minTerm.utf8ToString() + " maxTerm=" + maxTerm.utf8ToString());
assert minTerm.compareTo(maxTerm) <= 0;
TermsEnum termsEnum = terms.iterator();
TermsEnum.SeekStatus status = termsEnum.seekCeil(minTerm);
if (status != TermsEnum.SeekStatus.FOUND) {
throw new RuntimeException("failed to seek to existing term field=" + field + " term=" + minTerm);
}
// Do "dumb" iteration to visit all terms in the range:
long normalTermCount = getDocsFromTermRange(field, maxDoc, termsEnum, normalDocs, minTerm, maxTerm, false);
// Now do the same operation using intersect:
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);
if (intersectTermCount > normalTermCount) {
throw new RuntimeException("intersect returned too many terms: field=" + field + " intersectTermCount=" + intersectTermCount + " normalTermCount=" + normalTermCount);
}
if (normalDocs.equals(intersectDocs) == false) {
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);
}
//System.out.println(" docs=" + normalTermCount);
//System.out.println(" " + intersectTermCount + " vs " + normalTermCount);
return intersectTermCount != normalTermCount;
}
代码示例来源:origin: org.infinispan/infinispan-embedded-query
/** Test Terms.intersect on this range, and validates that it returns the same doc ids as using non-intersect TermsEnum. Returns true if
* any fake terms were seen. */
private static boolean checkSingleTermRange(String field, int maxDoc, Terms terms, BytesRef minTerm, BytesRef maxTerm, FixedBitSet normalDocs, FixedBitSet intersectDocs) throws IOException {
//System.out.println(" check minTerm=" + minTerm.utf8ToString() + " maxTerm=" + maxTerm.utf8ToString());
assert minTerm.compareTo(maxTerm) <= 0;
TermsEnum termsEnum = terms.iterator();
TermsEnum.SeekStatus status = termsEnum.seekCeil(minTerm);
if (status != TermsEnum.SeekStatus.FOUND) {
throw new RuntimeException("failed to seek to existing term field=" + field + " term=" + minTerm);
}
// Do "dumb" iteration to visit all terms in the range:
long normalTermCount = getDocsFromTermRange(field, maxDoc, termsEnum, normalDocs, minTerm, maxTerm, false);
// Now do the same operation using intersect:
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);
if (intersectTermCount > normalTermCount) {
throw new RuntimeException("intersect returned too many terms: field=" + field + " intersectTermCount=" + intersectTermCount + " normalTermCount=" + normalTermCount);
}
if (normalDocs.equals(intersectDocs) == false) {
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);
}
//System.out.println(" docs=" + normalTermCount);
//System.out.println(" " + intersectTermCount + " vs " + normalTermCount);
return intersectTermCount != normalTermCount;
}
代码示例来源:origin: harbby/presto-connectors
/** Test Terms.intersect on this range, and validates that it returns the same doc ids as using non-intersect TermsEnum. Returns true if
* any fake terms were seen. */
private static boolean checkSingleTermRange(String field, int maxDoc, Terms terms, BytesRef minTerm, BytesRef maxTerm, FixedBitSet normalDocs, FixedBitSet intersectDocs) throws IOException {
//System.out.println(" check minTerm=" + minTerm.utf8ToString() + " maxTerm=" + maxTerm.utf8ToString());
assert minTerm.compareTo(maxTerm) <= 0;
TermsEnum termsEnum = terms.iterator();
TermsEnum.SeekStatus status = termsEnum.seekCeil(minTerm);
if (status != TermsEnum.SeekStatus.FOUND) {
throw new RuntimeException("failed to seek to existing term field=" + field + " term=" + minTerm);
}
// Do "dumb" iteration to visit all terms in the range:
long normalTermCount = getDocsFromTermRange(field, maxDoc, termsEnum, normalDocs, minTerm, maxTerm, false);
// Now do the same operation using intersect:
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);
if (intersectTermCount > normalTermCount) {
throw new RuntimeException("intersect returned too many terms: field=" + field + " intersectTermCount=" + intersectTermCount + " normalTermCount=" + normalTermCount);
}
if (normalDocs.equals(intersectDocs) == false) {
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);
}
//System.out.println(" docs=" + normalTermCount);
//System.out.println(" " + intersectTermCount + " vs " + normalTermCount);
return intersectTermCount != normalTermCount;
}
内容来源于网络,如有侵权,请联系作者删除!