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