source: trunk/gsdl3/packages/mg/java/org/greenstone/mg/MGQueryResult.java@ 9874

Last change on this file since 9874 was 9874, checked in by kjdon, 19 years ago

merged from branch ant-install-branch: merge 1

  • Property svn:keywords set to Author Date Id Revision
File size: 3.9 KB
Line 
1/*
2 * MGQueryResult.java
3 * Copyright (C) 2002 New Zealand Digital Library, http://www.nzdl.org
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19package org.greenstone.mg;
20
21
22import java.util.Vector;
23
24
25/** a java version of QueryResult for mg
26 *
27 * contains get methods for the java side, and simple
28 * set methods to be called from c side
29 *
30 */
31public class MGQueryResult
32{
33 /** the list of MGDocInfo */
34 protected Vector docs_ = null;
35 /** the list of MGTermInfo */
36 protected Vector terms_ = null;
37 /** the total number of docs found - not likely to be the size of docs_ */
38 protected long total_num_docs_ = 0;
39
40
41 MGQueryResult() {
42 docs_ = new Vector();
43 terms_ = new Vector();
44 }
45
46
47 /** clear the info from the last query
48 should be called before setting any new docs/terms */
49 public void clear() {
50 total_num_docs_ = 0;
51 docs_.clear();
52 terms_.clear();
53 }
54
55 public boolean isClear() {
56 return (total_num_docs_ == 0 && docs_.isEmpty() && terms_.isEmpty());
57 }
58
59 /** returns the result as a String - useful for printing out results */
60 public String toString()
61 {
62 String result = "";
63 result += "docs (ranks): ";
64 for (int i = 0; i < docs_.size(); i++) {
65 if (i > 0) result += ", ";
66 result += ((MGDocInfo) docs_.elementAt(i)).toString();
67 }
68 result += "\nterms: ";
69 for (int i = 0; i < terms_.size(); i++) {
70 if (i > 0) result += ", ";
71 result += ((MGTermInfo) terms_.elementAt(i)).toString();
72 }
73 result += "\nactual number of docs found = " + total_num_docs_;
74 return result;
75 }
76
77
78 /** a shorter representation - just terms and total docs - not the
79 individual docnums and ranks */
80 public String toShortString() {
81 String result = "";
82 result += "\nterms: ";
83 for (int i = 0; i < terms_.size(); i++) {
84 if (i > 0) result += ", ";
85 result += ((MGTermInfo) terms_.elementAt(i)).toString();
86 }
87 result += "\nactual number of docs found = "+total_num_docs_;
88 return result;
89 }
90
91
92 // set methods used by c++ code
93
94 public void setTotalDocs(long num) {
95 total_num_docs_=num;
96 }
97
98
99 public void addDoc(long doc, float rank) {
100 MGDocInfo doc_info = new MGDocInfo(doc, rank);
101 System.out.println("(Java) Added doc " + doc_info);
102
103 docs_.add(doc_info);
104 }
105
106
107 public void addTerm(String term, int stem)
108 {
109 MGTermInfo ti = new MGTermInfo();
110 ti.term_ = term;
111 ti.stem_method_ = stem;
112 terms_.add(ti);
113 System.out.println("(Java) Added term " + ti);
114 }
115
116
117 public void addEquivTerm(String term, String equivTerm,
118 long match, long freq)
119 {
120 // Find the term to add the equivalent to
121 MGTermInfo ti = null;
122 for (int i = (terms_.size() - 1); i >= 0; i--) {
123 ti = (MGTermInfo) terms_.elementAt(i);
124 // Found
125 if (ti.term_ == term) {
126 break;
127 }
128 }
129
130 if (ti == null) {
131 System.err.println("Internal error: No term exists to add to.\n");
132 }
133 else {
134 ti.addEquivTerm(equivTerm, match, freq);
135 System.out.println("(Java) Added equivalent term " + equivTerm + ", match: " + match + ", freq: " + freq);
136 }
137 }
138
139
140 // Get methods for the java side - GS2MGSearch.java, GS2MGRetrieve.java
141 public Vector getDocs() {
142 return docs_;
143 }
144
145
146 public Vector getTerms() {
147 return terms_;
148 }
149
150
151 public long getTotalDocs() {
152 return total_num_docs_;
153 }
154}
155
Note: See TracBrowser for help on using the repository browser.