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