1
2
3
4
5
6
7
8
9
10
11
12
13
14 package net.sf.mmapps.modules.lucenesearch;
15
16 import java.io.IOException;
17
18 import org.apache.lucene.document.Document;
19 import org.apache.lucene.search.Hits;
20
21 /***
22 * Search result object, is returned after a search is completed. This object holds the basic information needed to show
23 * the seatch result and the information Lucene's search gathered from the index.
24 *
25 * @author Wouter Heijke
26 * @version $Revision: 1.1 $
27 */
28 public final class SearchResult {
29
30 private String number;
31
32
33 private int doc;
34
35
36 private float score;
37
38
39 private float boost;
40
41
42 private String builder;
43
44 /***
45 * Constructs a Lucene module SearchResult
46 *
47 * @param hits Lucene search result Hits object
48 * @param document Lucene document id to retreive for this SearchResult
49 * @throws IOException
50 */
51 public SearchResult(Hits hits, int document) throws IOException {
52 this.setDoc(document);
53 this.setScore(hits.score(document));
54
55 Document result = hits.doc(document);
56 this.setNumber(result.get(Constants.NODE_FIELD));
57 this.setBuilder(result.get(Constants.BUILDER_FIELD));
58 this.setBoost(result.getBoost());
59 }
60
61 /***
62 * @return Returns the builder.
63 */
64 public String getBuilder() {
65 return builder;
66 }
67
68 /***
69 * @param builder The builder to set.
70 */
71 private void setBuilder(String builder) {
72 this.builder = builder;
73 }
74
75 /***
76 * @return Returns the doc.
77 */
78 public int getDoc() {
79 return doc;
80 }
81
82 /***
83 * @param doc The doc to set.
84 */
85 private void setDoc(int doc) {
86 this.doc = doc;
87 }
88
89 /***
90 * @return Returns the number.
91 */
92 public String getNumber() {
93 return number;
94 }
95
96 /***
97 * @param string The number to set.
98 */
99 private void setNumber(String string) {
100 this.number = string;
101 }
102
103 /***
104 * @return Returns the score.
105 */
106 public float getScore() {
107 return score;
108 }
109
110 /***
111 * @param score The score to set.
112 */
113 private void setScore(float score) {
114 this.score = score;
115 }
116
117 /***
118 * @return Returns the boost.
119 */
120 public float getBoost() {
121 return boost;
122 }
123
124 /***
125 * @param boost The boost to set.
126 */
127 private void setBoost(float boost) {
128 this.boost = boost;
129 }
130 }