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