1 | /**********************************************************************
|
---|
2 | *
|
---|
3 | * queryinfo.h --
|
---|
4 | * Copyright (C) 1999 The New Zealand Digital Library Project
|
---|
5 | *
|
---|
6 | * A component of the Greenstone digital library software
|
---|
7 | * from the New Zealand Digital Library Project at the
|
---|
8 | * University of Waikato, New Zealand.
|
---|
9 | *
|
---|
10 | * This program is free software; you can redistribute it and/or modify
|
---|
11 | * it under the terms of the GNU General Public License as published by
|
---|
12 | * the Free Software Foundation; either version 2 of the License, or
|
---|
13 | * (at your option) any later version.
|
---|
14 | *
|
---|
15 | * This program is distributed in the hope that it will be useful,
|
---|
16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
18 | * GNU General Public License for more details.
|
---|
19 | *
|
---|
20 | * You should have received a copy of the GNU General Public License
|
---|
21 | * along with this program; if not, write to the Free Software
|
---|
22 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
23 | *
|
---|
24 | *********************************************************************/
|
---|
25 |
|
---|
26 |
|
---|
27 | #ifndef QUERYINFO_H
|
---|
28 | #define QUERYINFO_H
|
---|
29 |
|
---|
30 |
|
---|
31 | #include "gsdlconf.h"
|
---|
32 | #include "text_t.h"
|
---|
33 | #include "comtypes.h"
|
---|
34 |
|
---|
35 | #if defined(GSDL_USE_OBJECTSPACE)
|
---|
36 | # include <ospace\std\vector>
|
---|
37 | # include <ospace\std\algorithm>
|
---|
38 | #elif defined(GSDL_USE_STL_H)
|
---|
39 | # include <vector.h>
|
---|
40 | # if defined(GSDL_USE_ALGO_H)
|
---|
41 | # include <algo.h>
|
---|
42 | # else
|
---|
43 | # include <algorithm.h>
|
---|
44 | # endif
|
---|
45 | #else
|
---|
46 | # include <vector>
|
---|
47 | # include <algorithm>
|
---|
48 | #endif
|
---|
49 |
|
---|
50 | // query parameters
|
---|
51 |
|
---|
52 | struct queryparamclass {
|
---|
53 | text_t combinequery;
|
---|
54 | text_t collection;
|
---|
55 |
|
---|
56 | // search_index = index+subcollection+language
|
---|
57 | text_t index;
|
---|
58 | text_t subcollection;
|
---|
59 | text_t language;
|
---|
60 | text_t level; // for new mg stuff
|
---|
61 | text_t querystring;
|
---|
62 | int search_type; // 0 = boolean, 1 = ranked
|
---|
63 | int match_mode; // 0 = some, 1 = all
|
---|
64 | int casefolding;
|
---|
65 | int stemming;
|
---|
66 | int maxdocs;
|
---|
67 | int maxnumeric;
|
---|
68 |
|
---|
69 | queryparamclass ();
|
---|
70 | void clear ();
|
---|
71 | queryparamclass &operator=(const queryparamclass &q);
|
---|
72 | };
|
---|
73 |
|
---|
74 | bool operator==(const queryparamclass &x, const queryparamclass &y);
|
---|
75 | bool operator!=(const queryparamclass &x, const queryparamclass &y);
|
---|
76 |
|
---|
77 | // stream output for debugging purposes
|
---|
78 | ostream &operator<< (ostream &outs, queryparamclass &q);
|
---|
79 |
|
---|
80 |
|
---|
81 |
|
---|
82 | // term frequencies
|
---|
83 |
|
---|
84 | struct termfreqclass {
|
---|
85 | text_t termstr;
|
---|
86 | text_t termstemstr;
|
---|
87 | text_tset utf8equivterms; // kept as utf8 string for fast matching
|
---|
88 | unsigned int termfreq;
|
---|
89 |
|
---|
90 | termfreqclass ();
|
---|
91 | void clear();
|
---|
92 | termfreqclass &operator=(const termfreqclass &t);
|
---|
93 | };
|
---|
94 |
|
---|
95 | typedef vector<termfreqclass> termfreqclassarray;
|
---|
96 |
|
---|
97 | bool operator==(const termfreqclass &x, const termfreqclass &y);
|
---|
98 | bool operator!=(const termfreqclass &x, const termfreqclass &y);
|
---|
99 | bool operator<(const termfreqclass &x, const termfreqclass &y);
|
---|
100 | bool operator>(const termfreqclass &x, const termfreqclass &y);
|
---|
101 |
|
---|
102 | // stream output for debugging purposes
|
---|
103 | ostream &operator<< (ostream &outs, termfreqclass &q);
|
---|
104 |
|
---|
105 |
|
---|
106 |
|
---|
107 | // one query result
|
---|
108 |
|
---|
109 | struct docresultclass {
|
---|
110 | int docnum;
|
---|
111 | float docweight;
|
---|
112 | unsigned int num_query_terms_matched; // not available on all versions of mg
|
---|
113 | int num_phrase_match; // not available on all versions of mg
|
---|
114 |
|
---|
115 | docresultclass();
|
---|
116 | ~docresultclass() {}
|
---|
117 | void clear ();
|
---|
118 |
|
---|
119 | // merges two result classes relating to a single docnum
|
---|
120 | docresultclass &combine(const docresultclass &d);
|
---|
121 |
|
---|
122 | docresultclass &operator=(const docresultclass &d);
|
---|
123 | };
|
---|
124 |
|
---|
125 | bool operator==(const docresultclass &x, const docresultclass &y);
|
---|
126 | bool operator<(const docresultclass &x, const docresultclass &y);
|
---|
127 |
|
---|
128 |
|
---|
129 | // stream output for debugging purposes
|
---|
130 | ostream &operator<< (ostream &outs, docresultclass &a);
|
---|
131 |
|
---|
132 |
|
---|
133 | struct ltint {
|
---|
134 | bool operator()(const int &t1, const int &t2) const
|
---|
135 | { return t1 < t2; }
|
---|
136 | };
|
---|
137 |
|
---|
138 | typedef map<int, docresultclass, ltint> docresultmap;
|
---|
139 |
|
---|
140 |
|
---|
141 |
|
---|
142 | // many document results
|
---|
143 |
|
---|
144 | struct docresultsclass {
|
---|
145 | docresultmap docset;
|
---|
146 | vector<int> docorder;
|
---|
147 |
|
---|
148 | docresultsclass ();
|
---|
149 | void clear ();
|
---|
150 | void docnum_order();
|
---|
151 |
|
---|
152 | void combine_and (const docresultsclass &d);
|
---|
153 | void combine_or (const docresultsclass &d);
|
---|
154 | void combine_not (const docresultsclass &d);
|
---|
155 |
|
---|
156 | docresultsclass &operator=(const docresultsclass &d);
|
---|
157 | };
|
---|
158 |
|
---|
159 |
|
---|
160 |
|
---|
161 |
|
---|
162 | // query results
|
---|
163 |
|
---|
164 | struct queryresultsclass {
|
---|
165 | queryresultsclass () {clear();}
|
---|
166 |
|
---|
167 | int docs_matched; // not available on all versions of mg
|
---|
168 | isapprox is_approx;
|
---|
169 | // bool is_approx; // not available on all versions of mg
|
---|
170 | bool syntax_error; // whether the query string was invalid
|
---|
171 | bool postprocessed; // whether this record has been post-processed
|
---|
172 |
|
---|
173 | docresultsclass docs;
|
---|
174 | termfreqclassarray orgterms; // terms before they are sorted and uniqued
|
---|
175 | termfreqclassarray terms;
|
---|
176 | text_tset termvariants;
|
---|
177 |
|
---|
178 | void clear ();
|
---|
179 | queryresultsclass &operator=(const queryresultsclass &q);
|
---|
180 |
|
---|
181 | void sortuniqqueryterms();
|
---|
182 | };
|
---|
183 |
|
---|
184 | // stream output for debugging purposes
|
---|
185 | ostream &operator<< (ostream &outs, queryresultsclass &q);
|
---|
186 |
|
---|
187 |
|
---|
188 | #endif
|
---|