public static FST<Long> buildFST(SortedMap<String, Integer> input)
      throws IOException {
    PositiveIntOutputs fstOutput = PositiveIntOutputs.getSingleton();
    FSTCompiler.Builder<Long> fstCompilerBuilder = new FSTCompiler.Builder<>(FST.INPUT_TYPE.BYTE4, fstOutput);
    FSTCompiler<Long> fstCompiler = fstCompilerBuilder.build();

    IntsRefBuilder scratch = new IntsRefBuilder();
    for (Map.Entry<String, Integer> entry : input.entrySet()) {
      fstCompiler.add(Util.toUTF16(entry.getKey(), scratch), entry.getValue().longValue());
    }

    return FST.fromFSTReader(fstCompiler.compile(), fstCompiler.getFSTReader());
  }
@Test
  public void testFSTBuilder()
      throws IOException {
    SortedMap<String, Integer> x = new TreeMap<>();
    x.put("hello-world", 12);
    x.put("hello-world123", 21);
    x.put("still", 123);

    FST<Long> fst = FSTBuilder.buildFST(x);
    File outputFile = new File(TEMP_DIR, "test.lucene");
    FileOutputStream fileOutputStream = new FileOutputStream(outputFile);
    OutputStreamDataOutput d = new OutputStreamDataOutput(fileOutputStream);
    fst.save(d, d);
    fileOutputStream.close();

    Outputs<Long> outputs = PositiveIntOutputs.getSingleton();
    File fstFile = new File(outputFile.getAbsolutePath());

    PinotDataBuffer pinotDataBuffer =
        PinotDataBuffer.mapFile(fstFile, true, 0, fstFile.length(), ByteOrder.BIG_ENDIAN, "");
    PinotBufferIndexInput indexInput = new PinotBufferIndexInput(pinotDataBuffer, 0L, fstFile.length());

    List<Long> results = RegexpMatcher.regexMatch("hello.*123", fst);
    Assert.assertEquals(results.size(), 1);
    Assert.assertEquals(results.get(0).longValue(), 21L);

    results = RegexpMatcher.regexMatch(".*world", fst);
    Assert.assertEquals(results.size(), 1);
    Assert.assertEquals(results.get(0).longValue(), 12L);
  }