[110] | 1 | /**********************************************************************
|
---|
| 2 | *
|
---|
| 3 | * queryinfo.h --
|
---|
| 4 | * Copyright (C) 1999 The New Zealand Digital Library Project
|
---|
| 5 | *
|
---|
[534] | 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.
|
---|
[110] | 9 | *
|
---|
[534] | 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 | *
|
---|
[110] | 24 | * $Id: queryinfo.h 534 1999-09-07 04:57:43Z sjboddie $
|
---|
| 25 | *
|
---|
| 26 | *********************************************************************/
|
---|
| 27 |
|
---|
| 28 |
|
---|
| 29 | #ifndef QUERYINFO_H
|
---|
| 30 | #define QUERYINFO_H
|
---|
| 31 |
|
---|
| 32 |
|
---|
[114] | 33 | #include "gsdlconf.h"
|
---|
[110] | 34 | #include "text_t.h"
|
---|
[398] | 35 | #include "comtypes.h"
|
---|
[110] | 36 |
|
---|
[114] | 37 | #if defined(GSDL_USE_OBJECTSPACE)
|
---|
| 38 | # include <ospace\std\vector>
|
---|
| 39 | # include <ospace\std\algorithm>
|
---|
| 40 | #elif defined(GSDL_USE_STL_H)
|
---|
| 41 | # include <vector.h>
|
---|
| 42 | # if defined(GSDL_USE_ALGO_H)
|
---|
| 43 | # include <algo.h>
|
---|
| 44 | # else
|
---|
| 45 | # include <algorithm.h>
|
---|
| 46 | # endif
|
---|
| 47 | #else
|
---|
[110] | 48 | # include <vector>
|
---|
| 49 | # include <algorithm>
|
---|
| 50 | #endif
|
---|
| 51 |
|
---|
| 52 | // query parameters
|
---|
| 53 |
|
---|
[351] | 54 | struct queryparamclass {
|
---|
| 55 | text_t combinequery;
|
---|
[110] | 56 | text_t collection;
|
---|
[351] | 57 |
|
---|
| 58 | // search_index = index+subcollection+language
|
---|
| 59 | text_t index;
|
---|
| 60 | text_t subcollection;
|
---|
| 61 | text_t language;
|
---|
| 62 |
|
---|
[110] | 63 | text_t querystring;
|
---|
| 64 | int search_type; // 0 = boolean, 1 = ranked
|
---|
[503] | 65 | int match_mode; // 0 = some, 1 = all
|
---|
[110] | 66 | int casefolding;
|
---|
| 67 | int stemming;
|
---|
| 68 | int maxdocs;
|
---|
| 69 |
|
---|
[351] | 70 | queryparamclass ();
|
---|
| 71 | void clear ();
|
---|
[110] | 72 | queryparamclass &operator=(const queryparamclass &q);
|
---|
| 73 | };
|
---|
| 74 |
|
---|
| 75 | bool operator==(const queryparamclass &x, const queryparamclass &y);
|
---|
| 76 | bool operator!=(const queryparamclass &x, const queryparamclass &y);
|
---|
| 77 |
|
---|
| 78 | // stream output for debugging purposes
|
---|
| 79 | ostream &operator<< (ostream &outs, queryparamclass &q);
|
---|
| 80 |
|
---|
| 81 |
|
---|
| 82 |
|
---|
| 83 | // term frequencies
|
---|
| 84 |
|
---|
[351] | 85 | struct termfreqclass {
|
---|
[110] | 86 | text_t termstr;
|
---|
[319] | 87 | text_t termstemstr;
|
---|
[326] | 88 | text_tset utf8equivterms; // kept as utf8 string for fast matching
|
---|
[110] | 89 | unsigned int termfreq;
|
---|
[351] | 90 |
|
---|
| 91 | termfreqclass ();
|
---|
| 92 | void clear();
|
---|
[110] | 93 | termfreqclass &operator=(const termfreqclass &t);
|
---|
| 94 | };
|
---|
| 95 |
|
---|
[394] | 96 | typedef vector<termfreqclass> termfreqclassarray;
|
---|
| 97 |
|
---|
[110] | 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 | bool operator>(const termfreqclass &x, const termfreqclass &y);
|
---|
| 102 |
|
---|
| 103 | // stream output for debugging purposes
|
---|
| 104 | ostream &operator<< (ostream &outs, termfreqclass &q);
|
---|
| 105 |
|
---|
| 106 |
|
---|
| 107 |
|
---|
| 108 | // one query result
|
---|
| 109 |
|
---|
[351] | 110 | struct docresultclass {
|
---|
[110] | 111 | int docnum;
|
---|
| 112 | float docweight;
|
---|
[326] | 113 | unsigned int num_query_terms_matched; // not available on all versions of mg
|
---|
[351] | 114 | int num_phrase_match; // not available on all versions of mg
|
---|
| 115 |
|
---|
| 116 | docresultclass();
|
---|
[503] | 117 | ~docresultclass() {}
|
---|
[351] | 118 | void clear ();
|
---|
| 119 |
|
---|
| 120 | // merges two result classes relating to a single docnum
|
---|
| 121 | docresultclass &combine(const docresultclass &d);
|
---|
| 122 |
|
---|
| 123 | docresultclass &operator=(const docresultclass &d);
|
---|
[110] | 124 | };
|
---|
| 125 |
|
---|
[503] | 126 | bool operator==(const docresultclass &x, const docresultclass &y);
|
---|
| 127 | bool operator<(const docresultclass &x, const docresultclass &y);
|
---|
| 128 |
|
---|
| 129 |
|
---|
[110] | 130 | // stream output for debugging purposes
|
---|
| 131 | ostream &operator<< (ostream &outs, docresultclass &a);
|
---|
| 132 |
|
---|
| 133 |
|
---|
[351] | 134 | struct ltint {
|
---|
| 135 | bool operator()(const int &t1, const int &t2) const
|
---|
| 136 | { return t1 < t2; }
|
---|
| 137 | };
|
---|
[110] | 138 |
|
---|
[351] | 139 | typedef map<int, docresultclass, ltint> docresultmap;
|
---|
| 140 |
|
---|
| 141 |
|
---|
| 142 |
|
---|
| 143 | // many document results
|
---|
| 144 |
|
---|
| 145 | struct docresultsclass {
|
---|
| 146 | docresultmap docset;
|
---|
| 147 | vector<int> docorder;
|
---|
| 148 |
|
---|
| 149 | docresultsclass ();
|
---|
| 150 | void clear ();
|
---|
| 151 | void docnum_order();
|
---|
| 152 |
|
---|
| 153 | void combine_and (const docresultsclass &d);
|
---|
| 154 | void combine_or (const docresultsclass &d);
|
---|
| 155 | void combine_not (const docresultsclass &d);
|
---|
| 156 |
|
---|
| 157 | docresultsclass &operator=(const docresultsclass &d);
|
---|
| 158 | };
|
---|
| 159 |
|
---|
| 160 |
|
---|
| 161 |
|
---|
| 162 |
|
---|
[110] | 163 | // query results
|
---|
| 164 |
|
---|
[351] | 165 | struct queryresultsclass {
|
---|
[311] | 166 | queryresultsclass () {clear();}
|
---|
| 167 |
|
---|
| 168 | int docs_matched; // not available on all versions of mg
|
---|
[398] | 169 | isapprox is_approx;
|
---|
| 170 | // bool is_approx; // not available on all versions of mg
|
---|
[326] | 171 |
|
---|
| 172 | bool postprocessed; // whether this record has been post-processed
|
---|
[311] | 173 |
|
---|
[351] | 174 | docresultsclass docs;
|
---|
[394] | 175 | termfreqclassarray orgterms; // terms before they are sorted and uniqued
|
---|
| 176 | termfreqclassarray terms;
|
---|
[351] | 177 | text_tset termvariants;
|
---|
[311] | 178 |
|
---|
[110] | 179 | void clear ();
|
---|
| 180 | queryresultsclass &operator=(const queryresultsclass &q);
|
---|
[311] | 181 |
|
---|
[319] | 182 | void sortuniqqueryterms();
|
---|
[110] | 183 | };
|
---|
| 184 |
|
---|
| 185 | // stream output for debugging purposes
|
---|
| 186 | ostream &operator<< (ostream &outs, queryresultsclass &q);
|
---|
| 187 |
|
---|
| 188 |
|
---|
| 189 | #endif
|
---|