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

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

Moved from src/library.

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 4.0 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 110 1999-01-08 09:02:22Z rjmcnab $
9 *
10 *********************************************************************/
11
12/*
13 $Log$
14 Revision 1.1 1999/01/08 09:02:18 rjmcnab
15
16 Moved from src/library.
17
18 */
19
20static char *RCSID = "$Id: queryinfo.cpp 110 1999-01-08 09:02:22Z rjmcnab $";
21
22
23#include "queryinfo.h"
24
25
26// query parameters
27
28queryparamclass &queryparamclass::operator=(const queryparamclass &q)
29{
30 collection = q.collection;
31 search_index = q.search_index;
32 querystring = q.querystring;
33 search_type = q.search_type;
34 casefolding = q.casefolding;
35 stemming = q.stemming;
36 maxdocs = q.maxdocs;
37
38 return *this;
39}
40
41
42bool operator==(const queryparamclass &x, const queryparamclass &y)
43{
44 return ((x.collection == y.collection) &&
45 (x.search_index == y.search_index) &&
46 (x.querystring == y.querystring) &&
47 (x.search_type == y.search_type) &&
48 (x.casefolding == y.casefolding) &&
49 (x.stemming == y.stemming) &&
50 (x.maxdocs == y.maxdocs));
51}
52
53bool operator!=(const queryparamclass &x, const queryparamclass &y)
54{
55 return !(x == y);
56}
57
58
59ostream &operator<< (ostream &outs, queryparamclass &q)
60{
61 outconvertclass text_t2ascii;
62
63 outs << "*** queryparamclass\n";
64 outs << text_t2ascii << " collection = \"" << q.collection << "\"\n";
65 outs << text_t2ascii << " search_index = \"" << q.search_index << "\"\n";
66 outs << text_t2ascii << " querystring = \"" << q.querystring << "\"\n";
67 outs << " search_type = \"" << q.search_type << "\"\n";
68 outs << " casefolding = \"" << q.casefolding << "\"\n";
69 outs << " stemming = \"" << q.stemming << "\"\n";
70 outs << " maxdocs = \"" << q.maxdocs << "\"\n";
71 outs << "\n";
72
73 return outs;
74}
75
76
77
78
79// term frequencies
80
81termfreqclass &termfreqclass::operator=(const termfreqclass &t)
82{
83 termstr = t.termstr;
84 termfreq = t.termfreq;
85
86 return *this;
87}
88
89bool operator==(const termfreqclass &x, const termfreqclass &y)
90{
91 return ((x.termstr == y.termstr) &&
92 (x.termfreq == y.termfreq));
93}
94
95bool operator!=(const termfreqclass &x, const termfreqclass &y)
96{
97 return !(x == y);
98}
99
100// ordered by termfreq and then by termstr
101bool operator<(const termfreqclass &x, const termfreqclass &y)
102{
103 return ((x.termfreq < y.termfreq) ||
104 ((x.termfreq == y.termfreq) && (x.termstr < y.termstr)));
105
106}
107
108bool operator>(const termfreqclass &x, const termfreqclass &y)
109{
110 return ((x.termfreq > y.termfreq) ||
111 ((x.termfreq == y.termfreq) && (x.termstr > y.termstr)));
112
113}
114
115// stream output for debugging purposes
116ostream &operator<< (ostream &outs, termfreqclass &t)
117{
118 outconvertclass text_t2ascii;
119
120 outs << text_t2ascii << " t:\"" << t.termstr << "\"";
121 outs << " f:" << t.termfreq << "\n";
122
123 return outs;
124}
125
126
127
128// one query result
129
130// stream output for debugging purposes
131ostream &operator<< (ostream &outs, docresultclass &a)
132{
133 outs << " d:" << a.docnum << " w:" << a.docweight << "\n";
134 return outs;
135}
136
137
138
139// query results
140
141void queryresultsclass::clear ()
142{
143 docs.erase(docs.begin(),docs.end());
144 terms.erase(terms.begin(),terms.end());
145}
146
147queryresultsclass &queryresultsclass::operator=(const queryresultsclass &q)
148{
149 docs = q.docs;
150 terms = q.terms;
151
152 return *this;
153}
154
155void queryresultsclass::sortqueryterms()
156{
157 sort (terms.begin(), terms.end());
158}
159
160void queryresultsclass::uniqqueryterms()
161{
162 vector<termfreqclass>::iterator new_end = unique (terms.begin(), terms.end());
163 terms.erase(new_end, terms.end());
164}
165
166
167
168// stream output for debugging purposes
169ostream &operator<< (ostream &outs, queryresultsclass &q)
170{
171 outs << "*** queryresultsclass\n";
172 outs << "docs\n";
173
174 vector<docresultclass>::iterator docshere = q.docs.begin();
175 vector<docresultclass>::iterator docsend = q.docs.end();
176 while (docshere != docsend) {
177 outs << (*docshere);
178 docshere++;
179 }
180
181 outs << "terms\n";
182 vector<termfreqclass>::iterator termshere = q.terms.begin();
183 vector<termfreqclass>::iterator termsend = q.terms.end();
184 while (termshere != termsend) {
185 outs << (*termshere);
186 termshere++;
187 }
188
189 outs << "\n";
190
191 return outs;
192}
Note: See TracBrowser for help on using the repository browser.