Skip to content

Commit

Permalink
fix or suppress additional sonar warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
alecgrieser committed May 19, 2022
1 parent 1989447 commit aaf522e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ private void performLookup() throws IOException {
}
}

@SuppressWarnings("squid:S3776") // Cognitive complexity is too high. Candidate for later refactoring
@Nullable
private String searchAllMaybeHighlight(String text, Set<String> matchedTokens, @Nullable String prefixToken, boolean highlight) {
try (TokenStream ts = queryAnalyzer.tokenStream("text", new StringReader(text))) {
Expand Down Expand Up @@ -408,11 +409,10 @@ private Query getPhrasePrefixQuery(@Nonnull String fieldName, @Nonnull PhraseQue

protected RecordCursor<IndexEntry> createResults(IndexSearcher searcher,
TopDocs topDocs,
Set<String> matchedTokens,
String prefixToken)
throws IOException {
Set<String> queryTokens,
@Nullable String prefixToken) {
return RecordCursor.fromIterator(executor, Arrays.stream(topDocs.scoreDocs).iterator())
.mapPipelined(scoreDoc -> constructIndexEntryFromScoreDoc(searcher, scoreDoc, matchedTokens, prefixToken), state.store.getPipelineSize(PipelineOperation.KEY_TO_RECORD))
.mapPipelined(scoreDoc -> constructIndexEntryFromScoreDoc(searcher, scoreDoc, queryTokens, prefixToken), state.store.getPipelineSize(PipelineOperation.KEY_TO_RECORD))
.filter(Objects::nonNull)
.mapResult(wrappingResult -> {
if (wrappingResult.hasNext()) {
Expand All @@ -428,17 +428,18 @@ protected RecordCursor<IndexEntry> createResults(IndexSearcher searcher,
});
}

@SuppressWarnings("squid:S3776") // Cognitive complexity is too high. Candidate for later refactoring
private CompletableFuture<RecordCursorResult<IndexEntry>> constructIndexEntryFromScoreDoc(IndexSearcher searcher, ScoreDoc scoreDoc, Set<String> queryTokens, @Nullable String prefixToken) {
try {
IndexableField primaryKey = searcher.doc(scoreDoc.doc).getField(LuceneIndexMaintainer.PRIMARY_KEY_FIELD_NAME);
BytesRef pk = primaryKey.binaryValue();
return state.store.loadRecordAsync(Tuple.fromBytes(pk.bytes)).thenApply(record -> {
if (record == null) {
return state.store.loadRecordAsync(Tuple.fromBytes(pk.bytes)).thenApply(rec -> {
if (rec == null) {
// No document found. Return original record.
return null;
}
// Extract the indexed fields from the document again
final List<LuceneDocumentFromRecord.DocumentField> documentFields = LuceneDocumentFromRecord.getRecordFields(state.index.getRootExpression(), record)
final List<LuceneDocumentFromRecord.DocumentField> documentFields = LuceneDocumentFromRecord.getRecordFields(state.index.getRootExpression(), rec)
.get(groupingKey == null ? TupleHelpers.EMPTY : groupingKey);

// Search each field to find the first match.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
import javax.annotation.Nullable;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.EnumMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -238,7 +238,7 @@ private void writeDocument(@Nonnull List<LuceneDocumentFromRecord.DocumentField>

@Nonnull
private Map<IndexOptions, List<LuceneDocumentFromRecord.DocumentField>> getIndexOptionsToFieldsMap(@Nonnull List<LuceneDocumentFromRecord.DocumentField> fields) {
final Map<IndexOptions, List<LuceneDocumentFromRecord.DocumentField>> map = new HashMap<>();
final Map<IndexOptions, List<LuceneDocumentFromRecord.DocumentField>> map = new EnumMap<>(IndexOptions.class);
fields.stream().forEach(f -> {
final IndexOptions indexOptions = getIndexOptions((String) Objects.requireNonNullElse(f.getConfig(LuceneFunctionNames.LUCENE_AUTO_COMPLETE_FIELD_INDEX_OPTIONS),
LuceneFunctionNames.LuceneFieldIndexOptions.DOCS_AND_FREQS_AND_POSITIONS.name()));
Expand Down

0 comments on commit aaf522e

Please sign in to comment.