1 | /**********************************************************************
|
---|
2 | *
|
---|
3 | * queryfilter.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 | * $Id: queryfilter.h 766 1999-11-01 22:06:06Z sjboddie $
|
---|
25 | *
|
---|
26 | *********************************************************************/
|
---|
27 |
|
---|
28 |
|
---|
29 | #ifndef QUERYFILTER_H
|
---|
30 | #define QUERYFILTER_H
|
---|
31 |
|
---|
32 |
|
---|
33 | #include "gsdlconf.h"
|
---|
34 | #include "text_t.h"
|
---|
35 | #include "comtypes.h"
|
---|
36 | #include "filter.h"
|
---|
37 | #include "infodbclass.h"
|
---|
38 | #include "maptools.h"
|
---|
39 | #include "mgsearch.h"
|
---|
40 | #include "queryinfo.h"
|
---|
41 |
|
---|
42 |
|
---|
43 | // resultsorderer_t is used to sort the query results
|
---|
44 | struct resultsorderer_t {
|
---|
45 | bool compare_phrase_match;
|
---|
46 | bool compare_terms_match;
|
---|
47 | bool compare_doc_weight;
|
---|
48 | docresultmap *docset;
|
---|
49 |
|
---|
50 | resultsorderer_t();
|
---|
51 | void clear();
|
---|
52 | bool operator()(const int &t1, const int &t2) const;
|
---|
53 | };
|
---|
54 |
|
---|
55 |
|
---|
56 |
|
---|
57 | class queryfilterclass : public filterclass {
|
---|
58 | protected:
|
---|
59 |
|
---|
60 | stringmap indexmap;
|
---|
61 | stringmap subcollectionmap;
|
---|
62 | stringmap languagemap;
|
---|
63 |
|
---|
64 | text_t gdbm_filename;
|
---|
65 | gdbmclass *gdbmptr;
|
---|
66 |
|
---|
67 | mgsearchclass *mgsearchptr;
|
---|
68 |
|
---|
69 | int num_phrases;
|
---|
70 |
|
---|
71 | void get_phrase_terms (const text_t &querystring,
|
---|
72 | const termfreqclassarray &orgterms,
|
---|
73 | vector<termfreqclassarray> &phrases);
|
---|
74 |
|
---|
75 | // do aditional query processing
|
---|
76 | virtual void post_process (const queryparamclass &queryparams,
|
---|
77 | queryresultsclass &queryresults);
|
---|
78 |
|
---|
79 | // get the query parameters
|
---|
80 | void parse_query_params (const FilterRequest_t &request,
|
---|
81 | vector<queryparamclass> &query_params,
|
---|
82 | int &startresults, int &endresults,
|
---|
83 | text_t &phrasematch, ostream &logout);
|
---|
84 |
|
---|
85 | // do query that might involve multiple sub queries
|
---|
86 | // mgsearchptr and gdbmptr are assumed to be valid
|
---|
87 | void do_multi_query (const FilterRequest_t &request,
|
---|
88 | const vector<queryparamclass> &query_params,
|
---|
89 | queryresultsclass &multiresults,
|
---|
90 | comerror_t &err, ostream &logout);
|
---|
91 |
|
---|
92 | virtual void sort_doc_results (const FilterRequest_t &request,
|
---|
93 | docresultsclass &docs);
|
---|
94 |
|
---|
95 |
|
---|
96 | public:
|
---|
97 | queryfilterclass ();
|
---|
98 | virtual ~queryfilterclass ();
|
---|
99 |
|
---|
100 | // the gdbmptr remains the responsability of the calling code
|
---|
101 | void set_gdbmptr (gdbmclass *thegdbmptr) {gdbmptr=thegdbmptr;}
|
---|
102 |
|
---|
103 | // the mgsearchptr remains the responsability of the calling code
|
---|
104 | void set_mgsearchptr (mgsearchclass *themgsearchptr) {mgsearchptr=themgsearchptr;}
|
---|
105 |
|
---|
106 | void configure (const text_t &key, const text_tarray &cfgline);
|
---|
107 | bool init (ostream &logout);
|
---|
108 | text_t get_filter_name () {return "QueryFilter";}
|
---|
109 | void filter (const FilterRequest_t &request,
|
---|
110 | FilterResponse_t &response,
|
---|
111 | comerror_t &err, ostream &logout);
|
---|
112 | };
|
---|
113 |
|
---|
114 |
|
---|
115 | #endif
|
---|