Apache Solr open-source search software
LUCENE-3695: move some confusing FST sugar out
Michael McCandless87bc4521c2f1
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txtindex c4648835771..ae08c308c26 100644--- a/lucene/CHANGES.txt+++ b/lucene/CHANGES.txt@@ -723,6 +723,9 @@ Changes in backwards compatibility policyhas been removed and replaced with the experimental getFieldInfosAPI. All IndexReader subclasses must implement getFieldInfos.(Mike McCandless)++* LUCENE-3695: Move confusing add(X) methods out of FST.Builder into+ FST.Util. (Robert Muir, Mike McCandless)Security fixesdiff --git a/lucene/src/java/org/apache/lucene/codecs/BlockTreeTermsWriter.java b/lucene/src/java/org/apache/lucene/codecs/BlockTreeTermsWriter.javaindex e9190545ae4..0b9870df057 100644--- a/lucene/src/java/org/apache/lucene/codecs/BlockTreeTermsWriter.java+++ b/lucene/src/java/org/apache/lucene/codecs/BlockTreeTermsWriter.java@@ -22,8 +22,8 @@ import java.util.ArrayList;import java.util.Comparator;import java.util.List;-import org.apache.lucene.index.FieldInfo;import org.apache.lucene.index.FieldInfo.IndexOptions;+import org.apache.lucene.index.FieldInfo;import org.apache.lucene.index.FieldInfos;import org.apache.lucene.index.IndexFileNames;import org.apache.lucene.index.SegmentWriteState;@@ -39,6 +39,7 @@ import org.apache.lucene.util.fst.ByteSequenceOutputs;import org.apache.lucene.util.fst.BytesRefFSTEnum;import org.apache.lucene.util.fst.FST;import org.apache.lucene.util.fst.NoOutputs;+import org.apache.lucene.util.fst.Util;/*TODO:@@ -244,6 +245,7 @@ public class BlockTreeTermsWriter extends FieldsConsumer {public final boolean hasTerms;public final boolean isFloor;public final int floorLeadByte;+ private final IntsRef scratchIntsRef = new IntsRef();public PendingBlock(BytesRef prefix, long fp, boolean hasTerms, boolean isFloor, int floorLeadByte, List<FST<BytesRef>> subIndices) {super(false);@@ -294,7 +296,7 @@ public class BlockTreeTermsWriter extends FieldsConsumer {final byte[] bytes = new byte[(int) scratchBytes.getFilePointer()];assert bytes.length > 0;scratchBytes.writeTo(bytes, 0);- indexBuilder.add(prefix, new BytesRef(bytes, 0, bytes.length));+ indexBuilder.add(Util.toIntsRef(prefix, scratchIntsRef), new BytesRef(bytes, 0, bytes.length));scratchBytes.reset();// Copy over index for all sub-blocks@@ -337,7 +339,7 @@ public class BlockTreeTermsWriter extends FieldsConsumer {//if (DEBUG) {// System.out.println(" add sub=" + indexEnt.input + " " + indexEnt.input + " output=" + indexEnt.output);//}- builder.add(indexEnt.input, indexEnt.output);+ builder.add(Util.toIntsRef(indexEnt.input, scratchIntsRef), indexEnt.output);}}}@@ -853,13 +855,15 @@ public class BlockTreeTermsWriter extends FieldsConsumer {return postingsWriter;}+ private final IntsRef scratchIntsRef = new IntsRef();+@Overridepublic void finishTerm(BytesRef text, TermStats stats) throws IOException {assert stats.docFreq > 0;//if (DEBUG) System.out.println("BTTW.finishTerm term=" + fieldInfo.name + ":" + toString(text) + " seg=" + segment + " df=" + stats.docFreq);- blockBuilder.add(text, noOutputs.getNoOutput());+ blockBuilder.add(Util.toIntsRef(text, scratchIntsRef), noOutputs.getNoOutput());pending.add(new PendingTerm(BytesRef.deepCopyOf(text), stats));postingsWriter.finishTerm(stats);numTerms++;diff --git a/lucene/src/java/org/apache/lucene/codecs/VariableGapTermsIndexReader.java b/lucene/src/java/org/apache/lucene/codecs/VariableGapTermsIndexReader.javaindex 2c0e72a9f43..abfc399bba9 100644--- a/lucene/src/java/org/apache/lucene/codecs/VariableGapTermsIndexReader.java+++ b/lucene/src/java/org/apache/lucene/codecs/VariableGapTermsIndexReader.java@@ -33,6 +33,7 @@ import org.apache.lucene.store.IOContext;import org.apache.lucene.store.IndexInput;import org.apache.lucene.util.BytesRef;import org.apache.lucene.util.CodecUtil;+import org.apache.lucene.util.IntsRef;import org.apache.lucene.util.fst.Builder;import org.apache.lucene.util.fst.BytesRefFSTEnum;import org.apache.lucene.util.fst.FST;@@ -187,6 +188,7 @@ public class VariableGapTermsIndexReader extends TermsIndexReaderBase {if (indexDivisor > 1) {// subsample+ final IntsRef scratchIntsRef = new IntsRef();final PositiveIntOutputs outputs = PositiveIntOutputs.getSingleton(true);final Builder<Long> builder = new Builder<Long>(FST.INPUT_TYPE.BYTE1, outputs);final BytesRefFSTEnum<Long> fstEnum = new BytesRefFSTEnum<Long>(fst);@@ -194,7 +196,7 @@ public class VariableGapTermsIndexReader extends TermsIndexReaderBase {int count = indexDivisor;while((result = fstEnum.next()) != null) {if (count == indexDivisor) {- builder.add(result.input, result.output);+ builder.add(Util.toIntsRef(result.input, scratchIntsRef), result.output);count = 0;}count++;diff --git a/lucene/src/java/org/apache/lucene/codecs/VariableGapTermsIndexWriter.java b/lucene/src/java/org/apache/lucene/codecs/VariableGapTermsIndexWriter.javaindex 40df5694818..5ad16a02967 100644--- a/lucene/src/java/org/apache/lucene/codecs/VariableGapTermsIndexWriter.java+++ b/lucene/src/java/org/apache/lucene/codecs/VariableGapTermsIndexWriter.java@@ -29,9 +29,11 @@ import org.apache.lucene.store.IndexOutput;import org.apache.lucene.util.BytesRef;import org.apache.lucene.util.CodecUtil;import org.apache.lucene.util.IOUtils;+import org.apache.lucene.util.IntsRef;import org.apache.lucene.util.fst.Builder;import org.apache.lucene.util.fst.FST;import org.apache.lucene.util.fst.PositiveIntOutputs;+import org.apache.lucene.util.fst.Util;/*** Selects index terms according to provided pluggable@@ -227,7 +229,7 @@ public class VariableGapTermsIndexWriter extends TermsIndexWriterBase {////System.out.println("VGW: field=" + fieldInfo.name);// Always put empty string in- fstBuilder.add(new BytesRef(), fstOutputs.get(termsFilePointer));+ fstBuilder.add(new IntsRef(), fstOutputs.get(termsFilePointer));startTermsFilePointer = termsFilePointer;}@@ -246,6 +248,8 @@ public class VariableGapTermsIndexWriter extends TermsIndexWriterBase {}}+ private final IntsRef scratchIntsRef = new IntsRef();+@Overridepublic void add(BytesRef text, TermStats stats, long termsFilePointer) throws IOException {if (text.length == 0) {@@ -256,7 +260,7 @@ public class VariableGapTermsIndexWriter extends TermsIndexWriterBase {final int lengthSave = text.length;text.length = indexedTermPrefixLength(lastTerm, text);try {- fstBuilder.add(text, fstOutputs.get(termsFilePointer));+ fstBuilder.add(Util.toIntsRef(text, scratchIntsRef), fstOutputs.get(termsFilePointer));} finally {text.length = lengthSave;}diff --git a/lucene/src/java/org/apache/lucene/codecs/memory/MemoryPostingsFormat.java b/lucene/src/java/org/apache/lucene/codecs/memory/MemoryPostingsFormat.javaindex bda196bd381..bfee7cfb44e 100644--- a/lucene/src/java/org/apache/lucene/codecs/memory/MemoryPostingsFormat.java+++ b/lucene/src/java/org/apache/lucene/codecs/memory/MemoryPostingsFormat.java@@ -51,10 +51,12 @@ import org.apache.lucene.store.RAMOutputStream;import org.apache.lucene.util.ArrayUtil;import org.apache.lucene.util.Bits;import org.apache.lucene.util.BytesRef;+import org.apache.lucene.util.IntsRef;import org.apache.lucene.util.fst.Builder;import org.apache.lucene.util.fst.ByteSequenceOutputs;import org.apache.lucene.util.fst.BytesRefFSTEnum;import org.apache.lucene.util.fst.FST;+import org.apache.lucene.util.fst.Util;// TODO: would be nice to somehow allow this to act like// InstantiatedIndex, by never writing to disk; ie you write@@ -183,6 +185,8 @@ public class MemoryPostingsFormat extends PostingsFormat {private final BytesRef spare = new BytesRef();private byte[] finalBuffer = new byte[128];+ private final IntsRef scratchIntsRef = new IntsRef();+@Overridepublic void finishTerm(BytesRef text, TermStats stats) throws IOException {@@ -213,7 +217,7 @@ public class MemoryPostingsFormat extends PostingsFormat {System.out.println(" " + Integer.toHexString(finalBuffer[i]&0xFF));}}- builder.add(text, BytesRef.deepCopyOf(spare));+ builder.add(Util.toIntsRef(text, scratchIntsRef), BytesRef.deepCopyOf(spare));termCount++;}diff --git a/lucene/src/java/org/apache/lucene/codecs/simpletext/SimpleTextFieldsReader.java b/lucene/src/java/org/apache/lucene/codecs/simpletext/SimpleTextFieldsReader.javaindex 70935f2755e..7c4c1db4834 100644--- a/lucene/src/java/org/apache/lucene/codecs/simpletext/SimpleTextFieldsReader.java+++ b/lucene/src/java/org/apache/lucene/codecs/simpletext/SimpleTextFieldsReader.java@@ -36,6 +36,7 @@ import org.apache.lucene.util.ArrayUtil;import org.apache.lucene.util.Bits;import org.apache.lucene.util.BytesRef;import org.apache.lucene.util.CharsRef;+import org.apache.lucene.util.IntsRef;import org.apache.lucene.util.OpenBitSet;import org.apache.lucene.util.StringHelper;import org.apache.lucene.util.UnicodeUtil;@@ -44,6 +45,7 @@ import org.apache.lucene.util.fst.BytesRefFSTEnum;import org.apache.lucene.util.fst.FST;import org.apache.lucene.util.fst.PairOutputs;import org.apache.lucene.util.fst.PositiveIntOutputs;+import org.apache.lucene.util.fst.Util;class SimpleTextFieldsReader extends FieldsProducer {@@ -529,11 +531,12 @@ class SimpleTextFieldsReader extends FieldsProducer {int docFreq = 0;long totalTermFreq = 0;OpenBitSet visitedDocs = new OpenBitSet();+ final IntsRef scratchIntsRef = new IntsRef();while(true) {SimpleTextUtil.readLine(in, scratch);if (scratch.equals(END) || StringHelper.startsWith(scratch, FIELD)) {if (lastDocsStart != -1) {- b.add(lastTerm, new PairOutputs.Pair<Long,PairOutputs.Pair<Long,Long>>(lastDocsStart,+ b.add(Util.toIntsRef(lastTerm, scratchIntsRef), new PairOutputs.Pair<Long,PairOutputs.Pair<Long,Long>>(lastDocsStart,new PairOutputs.Pair<Long,Long>((long) docFreq,posIntOutputs.get(totalTermFreq))));sumTotalTermFreq += totalTermFreq;@@ -549,7 +552,7 @@ class SimpleTextFieldsReader extends FieldsProducer {totalTermFreq++;} else if (StringHelper.startsWith(scratch, TERM)) {if (lastDocsStart != -1) {- b.add(lastTerm, new PairOutputs.Pair<Long,PairOutputs.Pair<Long,Long>>(lastDocsStart,+ b.add(Util.toIntsRef(lastTerm, scratchIntsRef), new PairOutputs.Pair<Long,PairOutputs.Pair<Long,Long>>(lastDocsStart,new PairOutputs.Pair<Long,Long>((long) docFreq,posIntOutputs.get(totalTermFreq))));}diff --git a/lucene/src/java/org/apache/lucene/util/fst/Builder.java b/lucene/src/java/org/apache/lucene/util/fst/Builder.javaindex f80a6979aab..34e9f5baa66 100644--- a/lucene/src/java/org/apache/lucene/util/fst/Builder.java+++ b/lucene/src/java/org/apache/lucene/util/fst/Builder.java@@ -19,7 +19,6 @@ package org.apache.lucene.util.fst;import org.apache.lucene.util.ArrayUtil;import org.apache.lucene.util.RamUsageEstimator;-import org.apache.lucene.util.BytesRef;import org.apache.lucene.util.IntsRef;import org.apache.lucene.util.fst.FST.INPUT_TYPE; // javadoc@@ -290,54 +289,6 @@ public class Builder<T> {}}- private final IntsRef scratchIntsRef = new IntsRef(10);-- public void add(BytesRef input, T output) throws IOException {- assert fst.getInputType() == FST.INPUT_TYPE.BYTE1;- scratchIntsRef.grow(input.length);- for(int i=0;i<input.length;i++) {- scratchIntsRef.ints[i] = input.bytes[i+input.offset] & 0xFF;- }- scratchIntsRef.length = input.length;- add(scratchIntsRef, output);- }-- /** Sugar: adds the UTF32 codepoints from char[] slice. FST- * must be FST.INPUT_TYPE.BYTE4! */- public void add(char[] s, int offset, int length, T output) throws IOException {- assert fst.getInputType() == FST.INPUT_TYPE.BYTE4;- int charIdx = offset;- int intIdx = 0;- final int charLimit = offset + length;- while(charIdx < charLimit) {- scratchIntsRef.grow(intIdx+1);- final int utf32 = Character.codePointAt(s, charIdx);- scratchIntsRef.ints[intIdx] = utf32;- charIdx += Character.charCount(utf32);- intIdx++;- }- scratchIntsRef.length = intIdx;- add(scratchIntsRef, output);- }-- /** Sugar: adds the UTF32 codepoints from CharSequence. FST- * must be FST.INPUT_TYPE.BYTE4! */- public void add(CharSequence s, T output) throws IOException {- assert fst.getInputType() == FST.INPUT_TYPE.BYTE4;- int charIdx = 0;- int intIdx = 0;- final int charLimit = s.length();- while(charIdx < charLimit) {- scratchIntsRef.grow(intIdx+1);- final int utf32 = Character.codePointAt(s, charIdx);- scratchIntsRef.ints[intIdx] = utf32;- charIdx += Character.charCount(utf32);- intIdx++;- }- scratchIntsRef.length = intIdx;- add(scratchIntsRef, output);- }-// for debugging/*private String toString(BytesRef b) {diff --git a/lucene/src/java/org/apache/lucene/util/fst/Util.java b/lucene/src/java/org/apache/lucene/util/fst/Util.javaindex 8ec209cf7b1..37a85a87c17 100644--- a/lucene/src/java/org/apache/lucene/util/fst/Util.java+++ b/lucene/src/java/org/apache/lucene/util/fst/Util.java@@ -31,10 +31,8 @@ public final class Util {}/** Looks up the output for this input, or null if the- * input is not accepted. FST must be- * INPUT_TYPE.BYTE4. */+ * input is not accepted. */public static<T> T get(FST<T> fst, IntsRef input) throws IOException {- assert fst.inputType == FST.INPUT_TYPE.BYTE4;// TODO: would be nice not to alloc this on every lookupfinal FST.Arc<T> arc = fst.getFirstArc(new FST.Arc<T>());@@ -59,77 +57,7 @@ public final class Util {}}- /** Logically casts input to UTF32 ints then looks up the output- * or null if the input is not accepted. FST must be- * INPUT_TYPE.BYTE4. */- public static<T> T get(FST<T> fst, char[] input, int offset, int length) throws IOException {- assert fst.inputType == FST.INPUT_TYPE.BYTE4;-- // TODO: would be nice not to alloc this on every lookup- final FST.Arc<T> arc = fst.getFirstArc(new FST.Arc<T>());-- int charIdx = offset;- final int charLimit = offset + length;-- // Accumulate output as we go- final T NO_OUTPUT = fst.outputs.getNoOutput();- T output = NO_OUTPUT;- while(charIdx < charLimit) {- final int utf32 = Character.codePointAt(input, charIdx);- charIdx += Character.charCount(utf32);-- if (fst.findTargetArc(utf32, arc, arc) == null) {- return null;- } else if (arc.output != NO_OUTPUT) {- output = fst.outputs.add(output, arc.output);- }- }-- if (fst.findTargetArc(FST.END_LABEL, arc, arc) == null) {- return null;- } else if (arc.output != NO_OUTPUT) {- return fst.outputs.add(output, arc.output);- } else {- return output;- }- }--- /** Logically casts input to UTF32 ints then looks up the output- * or null if the input is not accepted. FST must be- * INPUT_TYPE.BYTE4. */- public static<T> T get(FST<T> fst, CharSequence input) throws IOException {- assert fst.inputType == FST.INPUT_TYPE.BYTE4;-- // TODO: would be nice not to alloc this on every lookup- final FST.Arc<T> arc = fst.getFirstArc(new FST.Arc<T>());-- int charIdx = 0;- final int charLimit = input.length();-- // Accumulate output as we go- final T NO_OUTPUT = fst.outputs.getNoOutput();- T output = NO_OUTPUT;-- while(charIdx < charLimit) {- final int utf32 = Character.codePointAt(input, charIdx);- charIdx += Character.charCount(utf32);-- if (fst.findTargetArc(utf32, arc, arc) == null) {- return null;- } else if (arc.output != NO_OUTPUT) {- output = fst.outputs.add(output, arc.output);- }- }-- if (fst.findTargetArc(FST.END_LABEL, arc, arc) == null) {- return null;- } else if (arc.output != NO_OUTPUT) {- return fst.outputs.add(output, arc.output);- } else {- return output;- }- }+ // TODO: maybe a CharsRef version for BYTE2/** Looks up the output for this input, or null if the* input is not accepted */@@ -381,4 +309,51 @@ public final class Util {return "0x" + Integer.toHexString(label);}}++ /** Decodes the Unicode codepoints from the provided+ * CharSequence and places them in the provided scratch+ * IntsRef, which must not be null, returning it. */+ public static IntsRef toUTF32(CharSequence s, IntsRef scratch) {+ int charIdx = 0;+ int intIdx = 0;+ final int charLimit = s.length();+ while(charIdx < charLimit) {+ scratch.grow(intIdx+1);+ final int utf32 = Character.codePointAt(s, charIdx);+ scratch.ints[intIdx] = utf32;+ charIdx += Character.charCount(utf32);+ intIdx++;+ }+ scratch.length = intIdx;+ return scratch;+ }++ /** Decodes the Unicode codepoints from the provided+ * char[] and places them in the provided scratch+ * IntsRef, which must not be null, returning it. */+ public static IntsRef toUTF32(char[] s, int offset, int length, IntsRef scratch) {+ int charIdx = offset;+ int intIdx = 0;+ final int charLimit = offset + length;+ while(charIdx < charLimit) {+ scratch.grow(intIdx+1);+ final int utf32 = Character.codePointAt(s, charIdx);+ scratch.ints[intIdx] = utf32;+ charIdx += Character.charCount(utf32);+ intIdx++;+ }+ scratch.length = intIdx;+ return scratch;+ }++ /** Just takes unsigned byte values from the BytesRef and+ * converts into an IntsRef. */+ public static IntsRef toIntsRef(BytesRef input, IntsRef scratch) {+ scratch.grow(input.length);+ for(int i=0;i<input.length;i++) {+ scratch.ints[i] = input.bytes[i+input.offset] & 0xFF;+ }+ scratch.length = input.length;+ return scratch;+ }}diff --git a/lucene/src/test/org/apache/lucene/index/TestIndexWriterReader.java b/lucene/src/test/org/apache/lucene/index/TestIndexWriterReader.javaindex f49ae3c75dd..98e43a3ce77 100644--- a/lucene/src/test/org/apache/lucene/index/TestIndexWriterReader.java+++ b/lucene/src/test/org/apache/lucene/index/TestIndexWriterReader.java@@ -18,10 +18,12 @@ package org.apache.lucene.index;import java.io.IOException;import java.util.ArrayList;+import java.util.Collection;import java.util.Collections;import java.util.List;import java.util.Random;import java.util.concurrent.atomic.AtomicBoolean;+import java.util.concurrent.atomic.AtomicInteger;import org.apache.lucene.analysis.MockAnalyzer;import org.apache.lucene.codecs.Codec;@@ -29,19 +31,18 @@ import org.apache.lucene.document.Document;import org.apache.lucene.document.Field;import org.apache.lucene.document.StringField;import org.apache.lucene.document.TextField;-import org.apache.lucene.search.TermQuery;import org.apache.lucene.search.IndexSearcher;import org.apache.lucene.search.Query;+import org.apache.lucene.search.TermQuery;import org.apache.lucene.search.TopDocs;+import org.apache.lucene.store.AlreadyClosedException;import org.apache.lucene.store.Directory;import org.apache.lucene.store.MockDirectoryWrapper;-import org.apache.lucene.store.AlreadyClosedException;import org.apache.lucene.store.RAMDirectory;-import org.apache.lucene.util.LuceneTestCase;-import org.apache.lucene.util._TestUtil;import org.apache.lucene.util.BytesRef;+import org.apache.lucene.util.LuceneTestCase;import org.apache.lucene.util.ThreadInterruptedException;-import java.util.concurrent.atomic.AtomicInteger;+import org.apache.lucene.util._TestUtil;public class TestIndexWriterReader extends LuceneTestCase {@@ -780,7 +781,8 @@ public class TestIndexWriterReader extends LuceneTestCase {assertEquals(0, excs.size());r.close();- assertEquals(0, dir1.getOpenDeletedFiles().size());+ final Collection<String> openDeletedFiles = dir1.getOpenDeletedFiles();+ assertEquals("openDeleted=" + openDeletedFiles, 0, openDeletedFiles.size());writer.close();diff --git a/lucene/src/test/org/apache/lucene/util/fst/TestFSTs.java b/lucene/src/test/org/apache/lucene/util/fst/TestFSTs.javaindex 44e4d3a1f07..fa79fff0857 100644--- a/lucene/src/test/org/apache/lucene/util/fst/TestFSTs.java+++ b/lucene/src/test/org/apache/lucene/util/fst/TestFSTs.java@@ -1050,6 +1050,7 @@ public class TestFSTs extends LuceneTestCase {}Terms terms = MultiFields.getTerms(r, "body");if (terms != null) {+ final IntsRef scratchIntsRef = new IntsRef();final TermsEnum termsEnum = terms.iterator(null);if (VERBOSE) {System.out.println("TEST: got termsEnum=" + termsEnum);@@ -1073,7 +1074,7 @@ public class TestFSTs extends LuceneTestCase {} else {output = termsEnum.docFreq();}- builder.add(term, outputs.get(output));+ builder.add(Util.toIntsRef(term, scratchIntsRef), outputs.get(output));ord++;if (VERBOSE && ord % 100000 == 0 && LuceneTestCase.TEST_NIGHTLY) {System.out.println(ord + " terms...");@@ -1373,7 +1374,7 @@ public class TestFSTs extends LuceneTestCase {public void testSingleString() throws Exception {final Outputs<Object> outputs = NoOutputs.getSingleton();final Builder<Object> b = new Builder<Object>(FST.INPUT_TYPE.BYTE1, outputs);- b.add(new BytesRef("foobar"), outputs.getNoOutput());+ b.add(Util.toIntsRef(new BytesRef("foobar"), new IntsRef()), outputs.getNoOutput());final BytesRefFSTEnum<Object> fstEnum = new BytesRefFSTEnum<Object>(b.finish());assertNull(fstEnum.seekFloor(new BytesRef("foo")));assertNull(fstEnum.seekCeil(new BytesRef("foobaz")));@@ -1395,9 +1396,9 @@ public class TestFSTs extends LuceneTestCase {final BytesRef b = new BytesRef("b");final BytesRef c = new BytesRef("c");- builder.add(a, outputs.get(17));- builder.add(b, outputs.get(42));- builder.add(c, outputs.get(13824324872317238L));+ builder.add(Util.toIntsRef(a, new IntsRef()), outputs.get(17));+ builder.add(Util.toIntsRef(b, new IntsRef()), outputs.get(42));+ builder.add(Util.toIntsRef(c, new IntsRef()), outputs.get(13824324872317238L));final FST<Long> fst = builder.finish();@@ -1628,13 +1629,14 @@ public class TestFSTs extends LuceneTestCase {int line = 0;final BytesRef term = new BytesRef();+ final IntsRef scratchIntsRef = new IntsRef();while (line < lines.length) {String w = lines[line++];if (w == null) {break;}term.copyChars(w);- b.add(term, nothing);+ b.add(Util.toIntsRef(term, scratchIntsRef), nothing);}return b.finish();@@ -1698,8 +1700,8 @@ public class TestFSTs extends LuceneTestCase {final PositiveIntOutputs outputs = PositiveIntOutputs.getSingleton(true);final Builder<Long> builder = new Builder<Long>(FST.INPUT_TYPE.BYTE4, 2, 0, true, true, Integer.MAX_VALUE, outputs, null);- builder.add("stat", outputs.get(17));- builder.add("station", outputs.get(10));+ builder.add(Util.toUTF32("stat", new IntsRef()), outputs.get(17));+ builder.add(Util.toUTF32("station", new IntsRef()), outputs.get(10));final FST<Long> fst = builder.finish();//Writer w = new OutputStreamWriter(new FileOutputStream("/x/tmp/out.dot"));StringWriter w = new StringWriter();@@ -1713,8 +1715,8 @@ public class TestFSTs extends LuceneTestCase {final PositiveIntOutputs outputs = PositiveIntOutputs.getSingleton(true);final Builder<Long> builder = new Builder<Long>(FST.INPUT_TYPE.BYTE1, 0, 0, true, true, Integer.MAX_VALUE, outputs, null);- builder.add(new BytesRef("stat"), outputs.getNoOutput());- builder.add(new BytesRef("station"), outputs.getNoOutput());+ builder.add(Util.toIntsRef(new BytesRef("stat"), new IntsRef()), outputs.getNoOutput());+ builder.add(Util.toIntsRef(new BytesRef("station"), new IntsRef()), outputs.getNoOutput());final FST<Long> fst = builder.finish();StringWriter w = new StringWriter();//Writer w = new OutputStreamWriter(new FileOutputStream("/x/tmp/out.dot"));diff --git a/modules/analysis/common/src/java/org/apache/lucene/analysis/synonym/SynonymMap.java b/modules/analysis/common/src/java/org/apache/lucene/analysis/synonym/SynonymMap.javaindex 9f103372e2e..d871529d844 100644--- a/modules/analysis/common/src/java/org/apache/lucene/analysis/synonym/SynonymMap.java+++ b/modules/analysis/common/src/java/org/apache/lucene/analysis/synonym/SynonymMap.java@@ -33,9 +33,11 @@ import org.apache.lucene.store.ByteArrayDataOutput;import org.apache.lucene.util.BytesRef;import org.apache.lucene.util.BytesRefHash;import org.apache.lucene.util.CharsRef;+import org.apache.lucene.util.IntsRef;import org.apache.lucene.util.UnicodeUtil;import org.apache.lucene.util.fst.ByteSequenceOutputs;import org.apache.lucene.util.fst.FST;+import org.apache.lucene.util.fst.Util;/*** A map of synonyms, keys and values are phrases.@@ -262,6 +264,8 @@ public class SynonymMap {Set<CharsRef> keys = workingSet.keySet();CharsRef sortedKeys[] = keys.toArray(new CharsRef[keys.size()]);Arrays.sort(sortedKeys, CharsRef.getUTF16SortedAsUTF8Comparator());++ final IntsRef scratchIntsRef = new IntsRef();//System.out.println("fmap.build");for (int keyIdx = 0; keyIdx < sortedKeys.length; keyIdx++) {@@ -307,7 +311,7 @@ public class SynonymMap {scratch.length = scratchOutput.getPosition() - scratch.offset;//System.out.println(" add input=" + input + " output=" + scratch + " offset=" + scratch.offset + " length=" + scratch.length + " count=" + count);- builder.add(input, BytesRef.deepCopyOf(scratch));+ builder.add(Util.toUTF32(input, scratchIntsRef), BytesRef.deepCopyOf(scratch));}FST<BytesRef> fst = builder.finish();diff --git a/modules/suggest/src/java/org/apache/lucene/search/suggest/fst/FSTCompletionBuilder.java b/modules/suggest/src/java/org/apache/lucene/search/suggest/fst/FSTCompletionBuilder.javaindex 90d5b64ff4d..7181fc206b1 100644--- a/modules/suggest/src/java/org/apache/lucene/search/suggest/fst/FSTCompletionBuilder.java+++ b/modules/suggest/src/java/org/apache/lucene/search/suggest/fst/FSTCompletionBuilder.java@@ -5,6 +5,7 @@ import java.io.IOException;import java.util.Iterator;import org.apache.lucene.util.BytesRef;+import org.apache.lucene.util.IntsRef;import org.apache.lucene.util.fst.*;/**@@ -219,11 +220,12 @@ public class FSTCompletionBuilder {shareMaxTailLength, outputs, null);BytesRef scratch = new BytesRef();+ final IntsRef scratchIntsRef = new IntsRef();int count = 0;for (Iterator<BytesRef> i = sorter.iterator(); i.hasNext(); count++) {BytesRef entry = i.next();if (scratch.compareTo(entry) != 0) {- builder.add(entry, empty);+ builder.add(Util.toIntsRef(entry, scratchIntsRef), empty);scratch.copyBytes(entry);}}