Apache Solr open-source search software
Merged /lucene/dev/trunk:r1445016-1445800
Robert Muir6d858dd01a9b
diff --cc lucene/facet/src/java/org/apache/lucene/facet/codecs/facet42/Facet42DocValuesConsumer.javaindex 00000000000,f82f1a23fba..e08899c5d01mode 000000,100644..100644--- a/lucene/facet/src/java/org/apache/lucene/facet/codecs/facet42/Facet42DocValuesConsumer.java+++ b/lucene/facet/src/java/org/apache/lucene/facet/codecs/facet42/Facet42DocValuesConsumer.java@@@ -1,0 -1,115 +1,120 @@@+ package org.apache.lucene.facet.codecs.facet42;++ /*+ * Licensed to the Apache Software Foundation (ASF) under one or more+ * contributor license agreements. See the NOTICE file distributed with+ * this work for additional information regarding copyright ownership.+ * The ASF licenses this file to You under the Apache License, Version 2.0+ * (the "License"); you may not use this file except in compliance with+ * the License. You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++ import java.io.IOException;++ import org.apache.lucene.codecs.CodecUtil;+ import org.apache.lucene.codecs.DocValuesConsumer;+ import org.apache.lucene.index.FieldInfo;+ import org.apache.lucene.index.IndexFileNames;+ import org.apache.lucene.index.SegmentWriteState;+ import org.apache.lucene.store.IndexOutput;+ import org.apache.lucene.util.BytesRef;+ import org.apache.lucene.util.IOUtils;+ import org.apache.lucene.util.packed.PackedInts;++ /** Writer for {@link Facet42DocValuesFormat}. */+ public class Facet42DocValuesConsumer extends DocValuesConsumer {++ final IndexOutput out;+ final int maxDoc;+ final float acceptableOverheadRatio;++ public Facet42DocValuesConsumer(SegmentWriteState state) throws IOException {+ this(state, PackedInts.DEFAULT);+ }++ public Facet42DocValuesConsumer(SegmentWriteState state, float acceptableOverheadRatio) throws IOException {+ this.acceptableOverheadRatio = acceptableOverheadRatio;+ boolean success = false;+ try {+ String fileName = IndexFileNames.segmentFileName(state.segmentInfo.name, state.segmentSuffix, Facet42DocValuesFormat.EXTENSION);+ out = state.directory.createOutput(fileName, state.context);+ CodecUtil.writeHeader(out, Facet42DocValuesFormat.CODEC, Facet42DocValuesFormat.VERSION_CURRENT);+ maxDoc = state.segmentInfo.getDocCount();+ success = true;+ } finally {+ if (!success) {+ IOUtils.closeWhileHandlingException(this);+ }+ }+ }++ @Override+ public void addNumericField(FieldInfo field, Iterable<Number> values) throws IOException {+ throw new UnsupportedOperationException("FacetsDocValues can only handle binary fields");+ }++ @Override+ public void addBinaryField(FieldInfo field, final Iterable<BytesRef> values) throws IOException {+ // write the byte[] data+ out.writeVInt(field.number);++ long totBytes = 0;+ for (BytesRef v : values) {+ totBytes += v.length;+ }++ if (totBytes > Integer.MAX_VALUE) {+ throw new IllegalStateException("too many facets in one segment: Facet42DocValues cannot handle more than 2 GB facet data per segment");+ }++ out.writeVInt((int) totBytes);++ for (BytesRef v : values) {+ out.writeBytes(v.bytes, v.offset, v.length);+ }++ PackedInts.Writer w = PackedInts.getWriter(out, maxDoc+1, PackedInts.bitsRequired(totBytes+1), acceptableOverheadRatio);++ int address = 0;+ for(BytesRef v : values) {+ w.add(address);+ address += v.length;+ }+ w.add(address);+ w.finish();+ }++ @Override+ public void addSortedField(FieldInfo field, Iterable<BytesRef> values, Iterable<Number> docToOrd) throws IOException {+ throw new UnsupportedOperationException("FacetsDocValues can only handle binary fields");+ }+++ @Override++ public void addSortedSetField(FieldInfo field, Iterable<BytesRef> values, Iterable<Number> docToOrdCount, Iterable<Number> ords) throws IOException {++ throw new UnsupportedOperationException("FacetsDocValues can only handle binary fields");++ }+++ @Override+ public void close() throws IOException {+ boolean success = false;+ try {+ out.writeVInt(-1); // write EOF marker+ success = true;+ } finally {+ if (success) {+ IOUtils.close(out);+ } else {+ IOUtils.closeWhileHandlingException(out);+ }+ }+ }++ }diff --cc lucene/facet/src/java/org/apache/lucene/facet/codecs/facet42/Facet42DocValuesProducer.javaindex 00000000000,1ecfa57e02b..ad7cb27cacamode 000000,100644..100644--- a/lucene/facet/src/java/org/apache/lucene/facet/codecs/facet42/Facet42DocValuesProducer.java+++ b/lucene/facet/src/java/org/apache/lucene/facet/codecs/facet42/Facet42DocValuesProducer.java@@@ -1,0 -1,80 +1,86 @@@+ package org.apache.lucene.facet.codecs.facet42;++ /*+ * Licensed to the Apache Software Foundation (ASF) under one or more+ * contributor license agreements. See the NOTICE file distributed with+ * this work for additional information regarding copyright ownership.+ * The ASF licenses this file to You under the Apache License, Version 2.0+ * (the "License"); you may not use this file except in compliance with+ * the License. You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++ import java.io.IOException;+ import java.util.HashMap;+ import java.util.Map;++ import org.apache.lucene.codecs.CodecUtil;+ import org.apache.lucene.codecs.DocValuesProducer;+ import org.apache.lucene.index.BinaryDocValues;+ import org.apache.lucene.index.FieldInfo;+ import org.apache.lucene.index.IndexFileNames;+ import org.apache.lucene.index.NumericDocValues;+ import org.apache.lucene.index.SegmentReadState;+ import org.apache.lucene.index.SortedDocValues;++import org.apache.lucene.index.SortedSetDocValues;+ import org.apache.lucene.store.IndexInput;+ import org.apache.lucene.util.IOUtils;++ class Facet42DocValuesProducer extends DocValuesProducer {++ private final Map<Integer,Facet42BinaryDocValues> fields = new HashMap<Integer,Facet42BinaryDocValues>();++ Facet42DocValuesProducer(SegmentReadState state) throws IOException {+ String fileName = IndexFileNames.segmentFileName(state.segmentInfo.name, state.segmentSuffix, Facet42DocValuesFormat.EXTENSION);+ IndexInput in = state.directory.openInput(fileName, state.context);+ boolean success = false;+ try {+ CodecUtil.checkHeader(in, Facet42DocValuesFormat.CODEC,+ Facet42DocValuesFormat.VERSION_START,+ Facet42DocValuesFormat.VERSION_START);+ int fieldNumber = in.readVInt();+ while (fieldNumber != -1) {+ fields.put(fieldNumber, new Facet42BinaryDocValues(in));+ fieldNumber = in.readVInt();+ }+ success = true;+ } finally {+ if (success) {+ IOUtils.close(in);+ } else {+ IOUtils.closeWhileHandlingException(in);+ }+ }+ }++ @Override+ public NumericDocValues getNumeric(FieldInfo field) throws IOException {+ throw new UnsupportedOperationException("FacetsDocValues only implements binary");+ }++ @Override+ public BinaryDocValues getBinary(FieldInfo field) throws IOException {+ return fields.get(field.number);+ }++ @Override+ public SortedDocValues getSorted(FieldInfo field) throws IOException {+ throw new UnsupportedOperationException("FacetsDocValues only implements binary");+ }+++ @Override++ public SortedSetDocValues getSortedSet(FieldInfo field) throws IOException {++ throw new UnsupportedOperationException("FacetsDocValues only implements binary");++ }+++ @Override+ public void close() throws IOException {+ }+ }