gitesh created MNGSITE-382:
------------------------------

             Summary: Deprecated method copyChars is used in example
                 Key: MNGSITE-382
                 URL: https://issues.apache.org/jira/browse/MNGSITE-382
             Project: Maven Project Web Site
          Issue Type: Bug
            Reporter: gitesh


Following documentation page for FST class has some example code.

[https://lucene.apache.org/core/8_3_0/core/org/apache/lucene/util/fst/package-summary.html]
{code:java}
     // 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);
     BytesRef scratchBytes = new BytesRef();
     IntsRefBuilder scratchInts = new IntsRefBuilder();
     for (int i = 0; i < inputValues.length; i++) {
       scratchBytes.copyChars(inputValues[i]);
       builder.add(Util.toIntsRef(scratchBytes, scratchInts), outputValues[i]);
     }
     FST<Long> fst = builder.finish();
{code}
Compilation of above code with Solr 8.3 libraries complains that no method 
copyChars found. copyChars method in BytesRef class is deprecated from long 
time. We should use BytesRefBuilder class instead. Here is the correct code:
{code:java}
String inputValues[] = {"cat", "dog", "dogs"};
long outputValues[] = {5, 7, 12};

PositiveIntOutputs outputs = PositiveIntOutputs.getSingleton();
Builder<Long> builder = new Builder<Long>(FST.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]);
}
FST<Long> fst = builder.finish();
{code}
 



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to