source: trunk/gsdl/src/colservr/queryinfo.cpp@ 334

Last change on this file since 334 was 334, checked in by rjmcnab, 25 years ago

Changes for better reporting of number documents which match a query. Changes
should still work as before with older versions of mg.

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 5.6 KB
Line 
1/**********************************************************************
2 *
3 * queryinfo.cpp --
4 * Copyright (C) 1999 The New Zealand Digital Library Project
5 *
6 * PUT COPYRIGHT NOTICE HERE
7 *
8 * $Id: queryinfo.cpp 334 1999-07-01 09:29:21Z rjmcnab $
9 *
10 *********************************************************************/
11
12/*
13 $Log$
14 Revision 1.6 1999/07/01 09:29:21 rjmcnab
15 Changes for better reporting of number documents which match a query. Changes
16 should still work as before with older versions of mg.
17
18 Revision 1.5 1999/07/01 03:56:17 rjmcnab
19 Added a set of utf8 encoded equivalent terms of a query term. I also
20 added a flag for handling post-processing of the query.
21
22 Revision 1.4 1999/06/30 04:04:13 rjmcnab
23 made stemming functions available from mgsearch and made the stems
24 for the query terms available in queryinfo
25
26 Revision 1.3 1999/06/29 22:06:23 rjmcnab
27 Added a couple of fields to queryinfo to handle a special version
28 of mg.
29
30 Revision 1.2 1999/01/12 01:51:02 rjmcnab
31
32 Standard header.
33
34 Revision 1.1 1999/01/08 09:02:18 rjmcnab
35
36 Moved from src/library.
37
38 */
39
40
41#include "queryinfo.h"
42
43
44// query parameters
45
46queryparamclass &queryparamclass::operator=(const queryparamclass &q)
47{
48 collection = q.collection;
49 search_index = q.search_index;
50 querystring = q.querystring;
51 search_type = q.search_type;
52 casefolding = q.casefolding;
53 stemming = q.stemming;
54 maxdocs = q.maxdocs;
55
56 return *this;
57}
58
59
60bool operator==(const queryparamclass &x, const queryparamclass &y)
61{
62 return ((x.collection == y.collection) &&
63 (x.search_index == y.search_index) &&
64 (x.querystring == y.querystring) &&
65 (x.search_type == y.search_type) &&
66 (x.casefolding == y.casefolding) &&
67 (x.stemming == y.stemming) &&
68 (x.maxdocs == y.maxdocs));
69}
70
71bool operator!=(const queryparamclass &x, const queryparamclass &y)
72{
73 return !(x == y);
74}
75
76
77ostream &operator<< (ostream &outs, queryparamclass &q)
78{
79 outconvertclass text_t2ascii;
80
81 outs << "*** queryparamclass\n";
82 outs << text_t2ascii << " collection = \"" << q.collection << "\"\n";
83 outs << text_t2ascii << " search_index = \"" << q.search_index << "\"\n";
84 outs << text_t2ascii << " querystring = \"" << q.querystring << "\"\n";
85 outs << " search_type = \"" << q.search_type << "\"\n";
86 outs << " casefolding = \"" << q.casefolding << "\"\n";
87 outs << " stemming = \"" << q.stemming << "\"\n";
88 outs << " maxdocs = \"" << q.maxdocs << "\"\n";
89 outs << "\n";
90
91 return outs;
92}
93
94
95
96
97// term frequencies
98
99termfreqclass &termfreqclass::operator=(const termfreqclass &t)
100{
101 termstr = t.termstr;
102 termstemstr = t.termstemstr;
103 utf8equivterms = t.utf8equivterms;
104 termfreq = t.termfreq;
105
106 return *this;
107}
108
109bool operator==(const termfreqclass &x, const termfreqclass &y)
110{
111 return ((x.termstr == y.termstr) &&
112 (x.termstemstr == y.termstemstr) &&
113 (x.termfreq == y.termfreq));
114}
115
116bool operator!=(const termfreqclass &x, const termfreqclass &y)
117{
118 return !(x == y);
119}
120
121// ordered by termfreq and then by termstr
122bool operator<(const termfreqclass &x, const termfreqclass &y)
123{
124 return ((x.termfreq < y.termfreq) ||
125 ((x.termfreq == y.termfreq) && (x.termstemstr < y.termstemstr)) ||
126 ((x.termfreq == y.termfreq) && (x.termstemstr == y.termstemstr) && (x.termstr < y.termstr)));
127}
128
129bool operator>(const termfreqclass &x, const termfreqclass &y)
130{
131 return ((x.termfreq > y.termfreq) ||
132 ((x.termfreq == y.termfreq) && (x.termstemstr > y.termstemstr)) ||
133 ((x.termfreq == y.termfreq) && (x.termstemstr == y.termstemstr) && (x.termstr > y.termstr)));
134}
135
136// stream output for debugging purposes
137ostream &operator<< (ostream &outs, termfreqclass &t)
138{
139 outconvertclass text_t2ascii;
140
141 outs << text_t2ascii << " t:\"" << t.termstr << "\"";
142 outs << text_t2ascii << " s:\"" << t.termstemstr << "\"";
143 outs << " f:" << t.termfreq << "\n";
144
145 return outs;
146}
147
148
149
150// one query result
151
152// stream output for debugging purposes
153ostream &operator<< (ostream &outs, docresultclass &a)
154{
155 outs << " d:" << a.docnum << " w:" << a.docweight << "\n";
156 return outs;
157}
158
159
160
161// query results
162
163void queryresultsclass::clear () {
164 docs_matched = 0;
165 is_approx = false;
166
167 postprocessed = false;
168
169 docs.erase(docs.begin(),docs.end());
170 orgterms.erase(orgterms.begin(),orgterms.end());
171 terms.erase(terms.begin(),terms.end());
172}
173
174queryresultsclass &queryresultsclass::operator=(const queryresultsclass &q) {
175 docs_matched = q.docs_matched;
176 is_approx = q.is_approx;
177
178 postprocessed = q.postprocessed;
179
180 docs = q.docs;
181 terms = q.terms;
182 termvariants = q.termvariants;
183
184 return *this;
185}
186
187void queryresultsclass::sortuniqqueryterms() {
188 terms = orgterms;
189
190 // sort the terms
191 sort (terms.begin(), terms.end());
192
193 // and then unique them
194 vector<termfreqclass>::iterator new_end = unique (terms.begin(), terms.end());
195 terms.erase(new_end, terms.end());
196}
197
198
199// stream output for debugging purposes
200ostream &operator<< (ostream &outs, queryresultsclass &q)
201{
202 outs << "*** queryresultsclass\n";
203 outs << "docs\n";
204
205 vector<docresultclass>::iterator docshere = q.docs.begin();
206 vector<docresultclass>::iterator docsend = q.docs.end();
207 while (docshere != docsend) {
208 outs << (*docshere);
209 docshere++;
210 }
211
212 outs << "orgterms\n";
213 vector<termfreqclass>::iterator orgtermshere = q.orgterms.begin();
214 vector<termfreqclass>::iterator orgtermsend = q.orgterms.end();
215 while (orgtermshere != orgtermsend) {
216 outs << (*orgtermshere);
217 orgtermshere++;
218 }
219
220 outs << "terms\n";
221 vector<termfreqclass>::iterator termshere = q.terms.begin();
222 vector<termfreqclass>::iterator termsend = q.terms.end();
223 while (termshere != termsend) {
224 outs << (*termshere);
225 termshere++;
226 }
227
228 outs << "\n";
229
230 return outs;
231}
Note: See TracBrowser for help on using the repository browser.