Skip to content

Commit

Permalink
#sonarlint
Browse files Browse the repository at this point in the history
  • Loading branch information
ja-fra committed Sep 5, 2024
1 parent afa888c commit 89e6673
Showing 1 changed file with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,14 @@
import org.apache.lucene.analysis.TokenStream;
import org.apache.lucene.analysis.tokenattributes.CharTermAttribute;
import org.apache.solr.core.SolrCore;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class FieldAnalyzerService {
public final class FieldAnalyzerService {

private static final Logger LOGGER = LoggerFactory.getLogger(FieldAnalyzerService.class);

private FieldAnalyzerService() {}

/**
* analyzes string like the given field
Expand All @@ -17,7 +23,7 @@ public class FieldAnalyzerService {
*/
public static String analyzeString(SolrCore core, String field, String value) {
try {
StringBuilder b = new StringBuilder();
final StringBuilder b = new StringBuilder();
try (TokenStream ts = core.getLatestSchema().getFieldType(field).getQueryAnalyzer().tokenStream(field, new StringReader(value))) {
ts.reset();
while (ts.incrementToken()) {
Expand All @@ -29,8 +35,7 @@ public static String analyzeString(SolrCore core, String field, String value) {

return b.toString().trim();
} catch (IOException e) {
//FIXME: This error should be properly logged!
e.printStackTrace();
LOGGER.warn("Failed to analyze field '{}' with value '{}'", field, value, e);
return value;
}
}
Expand Down

0 comments on commit 89e6673

Please sign in to comment.