|
|
@@ -3,6 +3,8 @@ package com.uas.search.sort;
|
|
|
import org.apache.lucene.index.BinaryDocValues;
|
|
|
import org.apache.lucene.index.LeafReaderContext;
|
|
|
import org.apache.lucene.search.SimpleFieldComparator;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.util.StringUtils;
|
|
|
|
|
|
import java.io.IOException;
|
|
|
@@ -25,6 +27,8 @@ abstract class DefaultFieldComparator extends SimpleFieldComparator<String> {
|
|
|
private String top;
|
|
|
private String bottom;
|
|
|
|
|
|
+ private Logger logger = LoggerFactory.getLogger(getClass());
|
|
|
+
|
|
|
DefaultFieldComparator(String fieldname, int numHits) {
|
|
|
this.fieldname = fieldname;
|
|
|
this.values = new String[numHits];
|
|
|
@@ -55,14 +59,14 @@ abstract class DefaultFieldComparator extends SimpleFieldComparator<String> {
|
|
|
|
|
|
@Override
|
|
|
public void copy(int slot, int doc) throws IOException {
|
|
|
- values[slot] = binaryDocValues.get(doc).utf8ToString();
|
|
|
+ values[slot] = binaryDocValues == null ? null : binaryDocValues.get(doc).utf8ToString();
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
protected void doSetNextReader(LeafReaderContext context) throws IOException {
|
|
|
binaryDocValues = context.reader().getBinaryDocValues(fieldname);
|
|
|
if (binaryDocValues == null) {
|
|
|
- throw new IllegalStateException("索引中不存在 binaryDocValues :" + fieldname);
|
|
|
+ logger.error("索引中不存在 binaryDocValues :" + fieldname);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -78,13 +82,13 @@ abstract class DefaultFieldComparator extends SimpleFieldComparator<String> {
|
|
|
|
|
|
@Override
|
|
|
public int compareBottom(int doc) throws IOException {
|
|
|
- String value = binaryDocValues.get(doc).utf8ToString();
|
|
|
+ String value = binaryDocValues == null ? null : binaryDocValues.get(doc).utf8ToString();
|
|
|
return compare(bottom, value);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public int compareTop(int doc) throws IOException {
|
|
|
- String value = binaryDocValues.get(doc).utf8ToString();
|
|
|
+ String value = binaryDocValues == null ? null : binaryDocValues.get(doc).utf8ToString();
|
|
|
return compare(top, value);
|
|
|
}
|
|
|
|