Skip to content

Commit 3695abb

Browse files
author
prayas7102
committed
run infer issues resolved
1 parent 9bfc445 commit 3695abb

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/main/java/com/thealgorithms/searches/BM25InvertedIndex.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,10 @@ public void addMovie(int docId, String name, double imdbRating, int releaseYear,
144144

145145
// Get the list of documents containing the term
146146
Map<Integer, Integer> docList = index.get(term);
147-
147+
if (docList == null) {
148+
docList = new HashMap<>();
149+
index.put(term, docList); // Ensure docList is added to the index
150+
}
148151
// Increment the term frequency in this document
149152
docList.put(docId, docList.getOrDefault(docId, 0) + 1);
150153
}
@@ -176,6 +179,9 @@ public List<SearchResult> search(String term) {
176179
int docId = entry.getKey();
177180
int termFrequency = entry.getValue();
178181
Movie movie = movies.get(docId);
182+
if (movie == null) {
183+
continue; // Skip this document if movie doesn't exist
184+
}
179185
double docLength = movie.getWords().length;
180186

181187
// Compute BM25 relevance score

0 commit comments

Comments
 (0)