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