source: trunk/indexers/mgpp/java/org/greenstone/mgpp/MGPPQueryResult.java@ 3365

Last change on this file since 3365 was 3365, checked in by kjdon, 22 years ago

Initial revision

  • Property svn:keywords set to Author Date Id Revision
File size: 2.4 KB
Line 
1package org.greenstone.mgpp;
2
3import java.util.Vector;
4
5/** a java version of QueryResult for mgpp
6 *
7 * contains get methods for the java side, and simple
8 * set methods to be called from c++ side
9 *
10 */
11public class MGPPQueryResult {
12
13 /** the list of MGPPDocInfo */
14 protected Vector docs_=null;
15 /** the list of MGPPTermInfo */
16 protected Vector terms_=null;
17 /** the total number of docs found - not likely to be the size of docs_*/
18 protected long total_num_docs_=0;
19
20 MGPPQueryResult() {
21 docs_ = new Vector();
22 terms_ = new Vector();
23 }
24 /** clear the info from the last query - should be called before setting any new docs/terms */
25 public void clear() {
26 total_num_docs_=0;
27 docs_.clear();
28 terms_.clear();
29 }
30 /** returns the result as a String - useful for printing out results */
31 public String toString() {
32 String result = "";
33 result += "docs (ranks): ";
34 for (int i=0; i<docs_.size(); i++) {
35 result += ((MGPPDocInfo)docs_.elementAt(i)).toString()+", ";
36 }
37 result += "\nterms: ";
38 for (int i=0; i<terms_.size(); i++) {
39 result += ((MGPPTermInfo)terms_.elementAt(i)).toString()+", ";
40 }
41 result += "\nactual number of docs found = "+total_num_docs_;
42
43 return result;
44 }
45 /** a shorter representation - just terms and total docs - not the
46 individual docnums and ranks */
47 public String toShortString() {
48 String result = "";
49 result += "\nterms: ";
50 for (int i=0; i<terms_.size(); i++) {
51 result += ((MGPPTermInfo)terms_.elementAt(i)).toString()+", ";
52 }
53 result += "\nactual number of docs found = "+total_num_docs_;
54 return result;
55 }
56
57 // set methods used by c++ code
58
59 public void setTotalDocs(long num) {
60 total_num_docs_=num;
61 }
62
63 public void addDoc(long doc, float rank) {
64 MGPPDocInfo doc_info = new MGPPDocInfo(doc, rank);
65 docs_.add(doc_info);
66 }
67
68 public void addTerm(String term, String tag, int stem, long match, long freq, String[] equivs) {
69 MGPPTermInfo ti = new MGPPTermInfo();
70 ti.term_=term;
71 ti.tag_=tag;
72 ti.stem_method_=stem;
73 ti.match_docs_=match;
74 ti.term_freq_=freq;
75 if (equivs!=null) {
76 for (int i=0; i<equivs.length; i++) {
77 ti.equiv_terms_.add(equivs[i]);
78 }
79 }
80 terms_.add(ti);
81 }
82
83 // get methods for the java side
84 public Vector getDocs() {
85 return docs_;
86 }
87
88 public Vector getTerms() {
89 return terms_;
90 }
91
92 public long getTotalDocs() {
93 return total_num_docs_;
94 }
95
96}
97
Note: See TracBrowser for help on using the repository browser.