Deprecated method copyChars is used in example [LUCENE-9052]
- Dominant language
- Java
- Stars
- 3.6k
- Forks
- 1.4k
- Avg merge
- 2d 11h
- Merged PRs (30d)
- 88
Description
Following documentation page for FST class has some example 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 builder = new Builder(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 fst = builder.finish();
```
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:
```java
String inputValues[] = {"cat", "dog", "dogs"};
long outputValues[] = {5, 7, 12};
PositiveIntOutputs outputs = PositiveIntOutputs.getSingleton();
Builder builder = new Builder(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.get(), scratchInts), outputValues[i]);
}
FST fst = builder.finish();
```
---
Migrated from [LUCENE-9052](https://issues.apache.org/jira/browse/LUCENE-9052) by gitesh
Contributor guide
Research direction
Start with the FST package-summary example linked in the issue and compare its BytesRef usage with the current BytesRefBuilder API. Replace the deprecated example usage with the working form shown in the issue, then verify that the example compiles against the relevant Lucene or Solr 8.3 libraries.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 1/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100