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