List of usage examples for org.apache.lucene.util ArrayUtil swap
public static <T> void swap(T[] arr, int i, int j)
i and j From source file:org.codelibs.elasticsearch.index.fielddata.SortingBinaryDocValues.java
License:Apache License
protected SortingBinaryDocValues() { values = new BytesRefBuilder[] { new BytesRefBuilder() }; sorter = new InPlaceMergeSorter() { @Override// w w w . ja v a 2s.c o m protected void swap(int i, int j) { ArrayUtil.swap(values, i, j); } @Override protected int compare(int i, int j) { return values[i].get().compareTo(values[j].get()); } }; }
From source file:org.elasticsearch.index.fielddata.plain.AbstractAtomicParentChildFieldData.java
License:Apache License
@Override public final SortedBinaryDocValues getBytesValues() { return new SortedBinaryDocValues() { private final BytesRef[] terms = new BytesRef[2]; private int count; @Override/*from w w w . ja v a 2 s . c o m*/ public void setDocument(int docId) { count = 0; for (String type : types()) { final SortedDocValues values = getOrdinalsValues(type); final int ord = values.getOrd(docId); if (ord >= 0) { terms[count++] = values.lookupOrd(ord); } } assert count <= 2 : "A single doc can potentially be both parent and child, so the maximum allowed values is 2"; if (count > 1) { int cmp = terms[0].compareTo(terms[1]); if (cmp > 0) { ArrayUtil.swap(terms, 0, 1); } else if (cmp == 0) { // If the id is the same between types the only omit one. For example: a doc has parent#1 in _uid field and has grand_parent#1 in _parent field. count = 1; } } } @Override public int count() { return count; } @Override public BytesRef valueAt(int index) { return terms[index]; } }; }