Example usage for org.apache.lucene.util.fst Util getByOutput

List of usage examples for org.apache.lucene.util.fst Util getByOutput

Introduction

In this page you can find the example usage for org.apache.lucene.util.fst Util getByOutput.

Prototype

@Deprecated
public static IntsRef getByOutput(FST<Long> fst, long targetOutput) throws IOException 

Source Link

Document

Reverse lookup (lookup by output instead of by input), in the special case when your FSTs outputs are strictly ascending.

Usage

From source file:examples.fst.FstTest.java

public static void main(String[] args) throws IOException {
    // Input values (keys). These must be provided to Builder in Unicode sorted order!
    String inputValues[] = { "cat", "dog", "dogs" };
    long outputValues[] = { 5, 7, 12 };

    PositiveIntOutputs outputs = PositiveIntOutputs.getSingleton();
    Builder<Long> builder = new Builder<Long>(INPUT_TYPE.BYTE1, outputs);
    BytesRefBuilder scratchBytes = new BytesRefBuilder();
    IntsRefBuilder scratchInts = new IntsRefBuilder();
    for (int i = 0; i < inputValues.length; i++) {
        scratchBytes.copyChars(inputValues[i]);
        builder.add(Util.toIntsRef(scratchBytes.toBytesRef(), scratchInts), outputValues[i]);
    }//from  w  w  w .java 2 s. co m
    FST<Long> fst = builder.finish();

    Long value = Util.get(fst, new BytesRef("dog"));
    System.out.println(value); // 7

    // Only works because outputs are also in sorted order
    IntsRef key = Util.getByOutput(fst, 12);
    System.out.println(Util.toBytesRef(key, scratchBytes).utf8ToString()); // dogs

}