-
Notifications
You must be signed in to change notification settings - Fork 0
/
SearchResult.java
45 lines (42 loc) · 1.27 KB
/
SearchResult.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/**
* ************************** DO NOT MODIFY THIS FILE *********************************
* This class serves as a placeholder object for a search result, including a document
* and the corresponding relevance score.
* @author Dr. Suppawong Tuarob, Copyrighted 2018
*
*/
public class SearchResult implements Comparable
{
private Document document = null;
private double score = -1;
public SearchResult(Document document, double score) {
this.document = document;
this.score = score;
}
public Document getDocument() {
return document;
}
public void setDocument(Document document) {
this.document = document;
}
//This function is a temporary solution, BUG-4 will resolve this.
public double getScore() {
return score;
}
public void setScore(double score) {
this.score = score;
}
// TODO: Use this for now then modify this once https://github.com/mockito/mockito/issues/769 is fixed
@Override
public String toString() {
return "[score=" + score + "]"+document+"\n";
}
/**
* So that the default sort would be descending on scores.
*/
@Override
public int compareTo(Object o) {
if(this.score == ((SearchResult)o).score) return this.document.compareTo(((SearchResult)o).document);
return -1*Double.compare(this.score,((SearchResult)o).score);
}
}