@@ -28,7 +28,7 @@ class Movie {
28
28
* @param releaseYear Release year of the movie.
29
29
* @param content Content or description of the movie.
30
30
*/
31
- public Movie (int docId , String name , double imdbRating , int releaseYear , String content ) {
31
+ Movie (int docId , String name , double imdbRating , int releaseYear , String content ) {
32
32
this .docId = docId ;
33
33
this .name = name ;
34
34
this .imdbRating = imdbRating ;
@@ -61,7 +61,7 @@ class SearchResult {
61
61
* @param docId Document ID (movie) for this search result.
62
62
* @param relevanceScore The relevance score based on BM25 scoring.
63
63
*/
64
- public SearchResult (int docId , double relevanceScore ) {
64
+ SearchResult (int docId , double relevanceScore ) {
65
65
this .docId = docId ;
66
66
this .relevanceScore = relevanceScore ;
67
67
}
@@ -78,8 +78,12 @@ public String toString() {
78
78
79
79
@ Override
80
80
public boolean equals (Object o ) {
81
- if (this == o ) return true ;
82
- if (o == null || getClass () != o .getClass ()) return false ;
81
+ if (this == o ) {
82
+ return true ;
83
+ }
84
+ if (o == null || getClass () != o .getClass ()) {
85
+ return false ;
86
+ }
83
87
SearchResult that = (SearchResult ) o ;
84
88
return docId == that .docId && Double .compare (that .relevanceScore , relevanceScore ) == 0 ;
85
89
}
@@ -99,14 +103,14 @@ public final class BM25InvertedIndex {
99
103
private Map <Integer , Movie > movies ; // Mapping of movie document IDs to Movie objects
100
104
private int totalDocuments ; // Total number of movies/documents
101
105
private double avgDocumentLength ; // Average length of documents (number of words)
102
- private static final double k = 1.5 ; // BM25 tuning parameter, controls term frequency saturation
103
- private static final double b = 0.75 ; // BM25 tuning parameter, controls length normalization
106
+ private static final double K = 1.5 ; // BM25 tuning parameter, controls term frequency saturation
107
+ private static final double B = 0.75 ; // BM25 tuning parameter, controls length normalization
104
108
105
109
/**
106
110
* Constructor for BM25InvertedIndex.
107
111
* Initializes the inverted index and movie storage.
108
112
*/
109
- public BM25InvertedIndex () {
113
+ BM25InvertedIndex () {
110
114
index = new HashMap <>();
111
115
movies = new HashMap <>();
112
116
totalDocuments = 0 ;
@@ -192,8 +196,8 @@ public List<SearchResult> search(String term) {
192
196
* @return The BM25 relevance score for the term in the document.
193
197
*/
194
198
private double computeBM25Score (int termFrequency , double docLength , double idf ) {
195
- double numerator = termFrequency * (k + 1 );
196
- double denominator = termFrequency + k * (1 - b + b * (docLength / avgDocumentLength ));
199
+ double numerator = termFrequency * (K + 1 );
200
+ double denominator = termFrequency + K * (1 - B + B * (docLength / avgDocumentLength ));
197
201
return idf * (numerator / denominator );
198
202
}
199
203
0 commit comments