Java Code Examples for org.apache.lucene.util.BytesRef#equals()
The following examples show how to use
org.apache.lucene.util.BytesRef#equals() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DocValuesTermsQuery.java From lucene-solr with Apache License 2.0 | 6 votes |
public DocValuesTermsQuery(String field, Collection<BytesRef> terms) { this.field = Objects.requireNonNull(field); Objects.requireNonNull(terms, "Collection of terms must not be null"); BytesRef[] sortedTerms = terms.toArray(new BytesRef[terms.size()]); ArrayUtil.timSort(sortedTerms); PrefixCodedTerms.Builder builder = new PrefixCodedTerms.Builder(); BytesRef previous = null; for (BytesRef term : sortedTerms) { if (term.equals(previous) == false) { builder.add(field, term); } previous = term; } termData = builder.finish(); termDataHashCode = termData.hashCode(); }
Example 2
Source File: CheckIndex.java From lucene-solr with Apache License 2.0 | 6 votes |
private static void checkBinaryDocValues(String fieldName, int maxDoc, BinaryDocValues bdv, BinaryDocValues bdv2) throws IOException { if (bdv.docID() != -1) { throw new RuntimeException("binary dv iterator for field: " + fieldName + " should start at docID=-1, but got " + bdv.docID()); } // TODO: we could add stats to DVs, e.g. total doc count w/ a value for this field for (int doc = bdv.nextDoc(); doc != NO_MORE_DOCS; doc = bdv.nextDoc()) { BytesRef value = bdv.binaryValue(); value.isValid(); if (bdv2.advanceExact(doc) == false) { throw new RuntimeException("advanceExact did not find matching doc ID: " + doc); } BytesRef value2 = bdv2.binaryValue(); if (value.equals(value2) == false) { throw new RuntimeException("nextDoc and advanceExact report different values: " + value + " != " + value2); } } }
Example 3
Source File: TimeZoneParser.java From Elasticsearch with Apache License 2.0 | 5 votes |
public static DateTimeZone parseTimeZone(BytesRef timezone) throws IllegalArgumentException { if (timezone == null) { throw new IllegalArgumentException("invalid time zone value NULL"); } if (timezone.equals(DEFAULT_TZ_BYTES_REF)) { return DEFAULT_TZ; } DateTimeZone tz = TIME_ZONE_MAP.get(timezone); if (tz == null) { try { String text = timezone.utf8ToString(); int index = text.indexOf(':'); if (index != -1) { int beginIndex = text.charAt(0) == '+' ? 1 : 0; // format like -02:30 tz = DateTimeZone.forOffsetHoursMinutes( Integer.parseInt(text.substring(beginIndex, index)), Integer.parseInt(text.substring(index + 1)) ); } else { // id, listed here: http://joda-time.sourceforge.net/timezones.html // or here: http://www.joda.org/joda-time/timezones.html tz = DateTimeZone.forID(text); } } catch (IllegalArgumentException e) { throw new IllegalArgumentException(String.format(Locale.ENGLISH, "invalid time zone value '%s'", timezone.utf8ToString())); } TIME_ZONE_MAP.putIfAbsent(timezone, tz); } return tz; }
Example 4
Source File: IndexNumericFieldData.java From Elasticsearch with Apache License 2.0 | 5 votes |
@Override public long toLong(BytesRef indexForm) { if (indexForm.equals(BooleanFieldMapper.Values.FALSE)) { return 0; } else if (indexForm.equals(BooleanFieldMapper.Values.TRUE)) { return 1; } else { throw new IllegalArgumentException("Cannot convert " + indexForm + " to a boolean"); } }
Example 5
Source File: FSTTermsReader.java From lucene-solr with Apache License 2.0 | 5 votes |
@Override public void seekExact(BytesRef target, TermState otherState) { if (!target.equals(term)) { state.copyFrom(otherState); term = BytesRef.deepCopyOf(target); seekPending = true; } }
Example 6
Source File: FSTTermsReader.java From lucene-solr with Apache License 2.0 | 5 votes |
IntersectTermsEnum(CompiledAutomaton compiled, BytesRef startTerm) throws IOException { super(); //if (TEST) System.out.println("Enum init, startTerm=" + startTerm); this.fst = dict; this.fstReader = fst.getBytesReader(); this.fstOutputs = dict.outputs; this.fsa = compiled.runAutomaton; this.level = -1; this.stack = new Frame[16]; for (int i = 0 ; i < stack.length; i++) { this.stack[i] = new Frame(); } loadVirtualFrame(newFrame()); this.level++; pushFrame(loadFirstFrame(newFrame())); this.meta = null; this.metaUpto = 1; this.decoded = false; this.pending = false; if (startTerm == null) { pending = isAccept(topFrame()); } else { doSeekCeil(startTerm); pending = (term == null || !startTerm.equals(term.get())) && isValid(topFrame()) && isAccept(topFrame()); } }
Example 7
Source File: TestFSTDirectAddressing.java From lucene-solr with Apache License 2.0 | 5 votes |
private static FST<Object> buildFST(List<BytesRef> entries, FSTCompiler<Object> fstCompiler) throws Exception { BytesRef last = null; for (BytesRef entry : entries) { if (entry.equals(last) == false) { fstCompiler.add(Util.toIntsRef(entry, new IntsRefBuilder()), NoOutputs.getSingleton().getNoOutput()); } last = entry; } return fstCompiler.compile(); }
Example 8
Source File: BlockReader.java From lucene-solr with Apache License 2.0 | 4 votes |
protected boolean isCurrentTerm(BytesRef searchedTerm) { // Optimization and also required to not search with the same BytesRef // instance as the BytesRef used to read the block line (BlockLine.Serializer). // Indeed getCurrentTerm() is allowed to return the same BytesRef instance. return searchedTerm.equals(term()); }
Example 9
Source File: FuzzyTermsEnum.java From lucene-solr with Apache License 2.0 | 4 votes |
/** returns true if term is within k edits of the query term */ private boolean matches(BytesRef termIn, int k) { return k == 0 ? termIn.equals(term.bytes()) : automata[k].runAutomaton.run(termIn.bytes, termIn.offset, termIn.length); }
Example 10
Source File: SingleTermsEnum.java From lucene-solr with Apache License 2.0 | 4 votes |
@Override protected AcceptStatus accept(BytesRef term) { return term.equals(singleRef) ? AcceptStatus.YES : AcceptStatus.END; }