Skip to content

Commit

Permalink
Simplify bytes arrays in NumericLeafComparator to long (#13246)
Browse files Browse the repository at this point in the history
  • Loading branch information
gf2121 authored Apr 10, 2024
1 parent 26fe2c4 commit 203cf7b
Show file tree
Hide file tree
Showing 8 changed files with 125 additions and 216 deletions.
2 changes: 2 additions & 0 deletions lucene/CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ New Features
Improvements
---------------------

* GITHUB#13246: Simplify bytes comparison as long comparison in NumericComparator. (Guo feng)

* LUCENE-10416: Update Korean Dictionary to mecab-ko-dic-2.1.1-20180720 for Nori.
(Uihyun Kim)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
package org.apache.lucene.search.comparators;

import java.io.IOException;
import org.apache.lucene.document.DoublePoint;
import org.apache.lucene.index.LeafReaderContext;
import org.apache.lucene.search.LeafFieldComparator;
import org.apache.lucene.search.Pruning;
import org.apache.lucene.util.NumericUtils;

/**
* Comparator based on {@link Double#compare} for {@code numHits}. This comparator provides a
Expand Down Expand Up @@ -54,6 +54,16 @@ public Double value(int slot) {
return Double.valueOf(values[slot]);
}

@Override
protected long missingValueAsComparableLong() {
return NumericUtils.doubleToSortableLong(missingValue);
}

@Override
protected long sortableBytesToLong(byte[] bytes) {
return NumericUtils.sortableBytesToLong(bytes, 0);
}

@Override
public LeafFieldComparator getLeafComparator(LeafReaderContext context) throws IOException {
return new DoubleLeafComparator(context);
Expand Down Expand Up @@ -97,23 +107,13 @@ public void copy(int slot, int doc) throws IOException {
}

@Override
protected int compareMissingValueWithBottomValue() {
return Double.compare(missingValue, bottom);
}

@Override
protected int compareMissingValueWithTopValue() {
return Double.compare(missingValue, topValue);
}

@Override
protected void encodeBottom(byte[] packedValue) {
DoublePoint.encodeDimension(bottom, packedValue, 0);
protected long bottomAsComparableLong() {
return NumericUtils.doubleToSortableLong(bottom);
}

@Override
protected void encodeTop(byte[] packedValue) {
DoublePoint.encodeDimension(topValue, packedValue, 0);
protected long topAsComparableLong() {
return NumericUtils.doubleToSortableLong(topValue);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
package org.apache.lucene.search.comparators;

import java.io.IOException;
import org.apache.lucene.document.FloatPoint;
import org.apache.lucene.index.LeafReaderContext;
import org.apache.lucene.search.LeafFieldComparator;
import org.apache.lucene.search.Pruning;
import org.apache.lucene.util.NumericUtils;

/**
* Comparator based on {@link Float#compare} for {@code numHits}. This comparator provides a
Expand Down Expand Up @@ -54,6 +54,16 @@ public Float value(int slot) {
return Float.valueOf(values[slot]);
}

@Override
protected long missingValueAsComparableLong() {
return NumericUtils.floatToSortableInt(missingValue);
}

@Override
protected long sortableBytesToLong(byte[] bytes) {
return NumericUtils.sortableBytesToInt(bytes, 0);
}

@Override
public LeafFieldComparator getLeafComparator(LeafReaderContext context) throws IOException {
return new FloatLeafComparator(context);
Expand Down Expand Up @@ -97,23 +107,13 @@ public void copy(int slot, int doc) throws IOException {
}

@Override
protected int compareMissingValueWithBottomValue() {
return Float.compare(missingValue, bottom);
}

@Override
protected int compareMissingValueWithTopValue() {
return Float.compare(missingValue, topValue);
}

@Override
protected void encodeBottom(byte[] packedValue) {
FloatPoint.encodeDimension(bottom, packedValue, 0);
protected long bottomAsComparableLong() {
return NumericUtils.floatToSortableInt(bottom);
}

@Override
protected void encodeTop(byte[] packedValue) {
FloatPoint.encodeDimension(topValue, packedValue, 0);
protected long topAsComparableLong() {
return NumericUtils.floatToSortableInt(topValue);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
package org.apache.lucene.search.comparators;

import java.io.IOException;
import org.apache.lucene.document.IntPoint;
import org.apache.lucene.index.LeafReaderContext;
import org.apache.lucene.search.LeafFieldComparator;
import org.apache.lucene.search.Pruning;
import org.apache.lucene.util.NumericUtils;

/**
* Comparator based on {@link Integer#compare} for {@code numHits}. This comparator provides a
Expand Down Expand Up @@ -54,6 +54,16 @@ public Integer value(int slot) {
return Integer.valueOf(values[slot]);
}

@Override
protected long missingValueAsComparableLong() {
return missingValue;
}

@Override
protected long sortableBytesToLong(byte[] bytes) {
return NumericUtils.sortableBytesToInt(bytes, 0);
}

@Override
public LeafFieldComparator getLeafComparator(LeafReaderContext context) throws IOException {
return new IntLeafComparator(context);
Expand Down Expand Up @@ -97,23 +107,13 @@ public void copy(int slot, int doc) throws IOException {
}

@Override
protected int compareMissingValueWithBottomValue() {
return Integer.compare(missingValue, bottom);
}

@Override
protected int compareMissingValueWithTopValue() {
return Integer.compare(missingValue, topValue);
}

@Override
protected void encodeBottom(byte[] packedValue) {
IntPoint.encodeDimension(bottom, packedValue, 0);
protected long bottomAsComparableLong() {
return bottom;
}

@Override
protected void encodeTop(byte[] packedValue) {
IntPoint.encodeDimension(topValue, packedValue, 0);
protected long topAsComparableLong() {
return topValue;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
package org.apache.lucene.search.comparators;

import java.io.IOException;
import org.apache.lucene.document.LongPoint;
import org.apache.lucene.index.LeafReaderContext;
import org.apache.lucene.search.LeafFieldComparator;
import org.apache.lucene.search.Pruning;
import org.apache.lucene.util.NumericUtils;

/**
* Comparator based on {@link Long#compare} for {@code numHits}. This comparator provides a skipping
Expand Down Expand Up @@ -54,6 +54,16 @@ public Long value(int slot) {
return Long.valueOf(values[slot]);
}

@Override
protected long missingValueAsComparableLong() {
return missingValue;
}

@Override
protected long sortableBytesToLong(byte[] bytes) {
return NumericUtils.sortableBytesToLong(bytes, 0);
}

@Override
public LeafFieldComparator getLeafComparator(LeafReaderContext context) throws IOException {
return new LongLeafComparator(context);
Expand Down Expand Up @@ -97,23 +107,13 @@ public void copy(int slot, int doc) throws IOException {
}

@Override
protected int compareMissingValueWithBottomValue() {
return Long.compare(missingValue, bottom);
}

@Override
protected int compareMissingValueWithTopValue() {
return Long.compare(missingValue, topValue);
}

@Override
protected void encodeBottom(byte[] packedValue) {
LongPoint.encodeDimension(bottom, packedValue, 0);
protected long bottomAsComparableLong() {
return bottom;
}

@Override
protected void encodeTop(byte[] packedValue) {
LongPoint.encodeDimension(topValue, packedValue, 0);
protected long topAsComparableLong() {
return topValue;
}
}
}
Loading

0 comments on commit 203cf7b

Please sign in to comment.