mirror of https://github.com/apache/lucene.git
LUCENE-9089: update FST usage example
This commit is contained in:
parent
2dd92fc052
commit
59a8e83520
|
@ -41,14 +41,14 @@
|
||||||
* long outputValues[] = {5, 7, 12};
|
* long outputValues[] = {5, 7, 12};
|
||||||
*
|
*
|
||||||
* PositiveIntOutputs outputs = PositiveIntOutputs.getSingleton();
|
* PositiveIntOutputs outputs = PositiveIntOutputs.getSingleton();
|
||||||
* Builder<Long> builder = new Builder<Long>(INPUT_TYPE.BYTE1, outputs);
|
* FSTCompiler<Long> fstCompiler = new FSTCompiler<Long>(INPUT_TYPE.BYTE1, outputs);
|
||||||
* BytesRef scratchBytes = new BytesRef();
|
* BytesRefBuilder scratchBytes = new BytesRefBuilder();
|
||||||
* IntsRefBuilder scratchInts = new IntsRefBuilder();
|
* IntsRefBuilder scratchInts = new IntsRefBuilder();
|
||||||
* for (int i = 0; i < inputValues.length; i++) {
|
* for (int i = 0; i < inputValues.length; i++) {
|
||||||
* scratchBytes.copyChars(inputValues[i]);
|
* scratchBytes.copyChars(inputValues[i]);
|
||||||
* builder.add(Util.toIntsRef(scratchBytes, scratchInts), outputValues[i]);
|
* fstCompiler.add(Util.toIntsRef(scratchBytes.toBytesRef(), scratchInts), outputValues[i]);
|
||||||
* }
|
* }
|
||||||
* FST<Long> fst = builder.finish();
|
* FST<Long> fst = fstCompiler.compile();
|
||||||
* </pre>
|
* </pre>
|
||||||
* Retrieval by key:
|
* Retrieval by key:
|
||||||
* <pre class="prettyprint">
|
* <pre class="prettyprint">
|
||||||
|
@ -79,11 +79,11 @@
|
||||||
* }
|
* }
|
||||||
* };
|
* };
|
||||||
* Arc<Long> firstArc = fst.getFirstArc(new Arc<Long>());
|
* Arc<Long> firstArc = fst.getFirstArc(new Arc<Long>());
|
||||||
* MinResult<Long> paths[] = Util.shortestPaths(fst, firstArc, comparator, 2);
|
* Util.TopResults<Long> paths = Util.shortestPaths(fst, firstArc, fst.outputs.getNoOutput(), comparator, 3, true);
|
||||||
* System.out.println(Util.toBytesRef(paths[0].input, scratchBytes).utf8ToString()); // cat
|
* System.out.println(Util.toBytesRef(paths.topN.get(0).input, scratchBytes).utf8ToString()); // cat
|
||||||
* System.out.println(paths[0].output); // 5
|
* System.out.println(paths.topN.get(0).output); // 5
|
||||||
* System.out.println(Util.toBytesRef(paths[1].input, scratchBytes).utf8ToString()); // dog
|
* System.out.println(Util.toBytesRef(paths.topN.get(1).input, scratchBytes).utf8ToString()); // dog
|
||||||
* System.out.println(paths[1].output); // 7
|
* System.out.println(paths.topN.get(1).output); // 7
|
||||||
* </pre>
|
* </pre>
|
||||||
*/
|
*/
|
||||||
package org.apache.lucene.util.fst;
|
package org.apache.lucene.util.fst;
|
||||||
|
|
Loading…
Reference in New Issue