source: trunk/gsdl/src/recpt/querytools.cpp@ 296

Last change on this file since 296 was 270, checked in by sjboddie, 25 years ago

moved do_query from queryaction to new querytools module (as do_action
is also called from documentaction when highlighting text)

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 4.1 KB
Line 
1/**********************************************************************
2 *
3 * querytools.cpp --
4 * Copyright (C) 1999 The New Zealand Digital Library Project
5 *
6 * PUT COPYRIGHT NOTICE HERE
7 *
8 * $Id: querytools.cpp 270 1999-06-15 02:24:06Z sjboddie $
9 *
10 *********************************************************************/
11
12/*
13 $Log$
14 Revision 1.1 1999/06/15 02:24:06 sjboddie
15 moved do_query from queryaction to new querytools module (as do_action
16 is also called from documentaction when highlighting text)
17
18 */
19
20
21#include "querytools.h"
22
23
24// do_query sets the filter options and makes the protocol call to
25// do a query. The results are returned in response.
26// request.filterResultOptions and request.fields (if required)
27// should be set by the calling function.
28// If the query string uses quotes (phrase-searching) the quoted
29// part of the string is returned in quotedstring (as something
30// of a side-effect ;-/
31
32bool do_query (FilterRequest_t &request, cgiargsclass &args,
33 recptproto *collectproto, text_t &quotedstring,
34 FilterResponse_t &response, ostream &logout) {
35
36 request.filterName = "QueryFilter";
37
38 comerror_t err;
39 OptionValue_t option;
40 text_t formattedstring = args["q"];
41
42 // format the query string ready to do the query (and remember
43 // the quoted part for later)
44 format_querystring (formattedstring, quotedstring);
45
46 option.name = "Term";
47 option.value = formattedstring;
48 request.filterOptions.push_back (option);
49
50 option.name = "QueryType";
51 option.value = (args.getintarg("t")) ? "ranked" : "boolean";
52 request.filterOptions.push_back (option);
53
54 option.name = "Casefold";
55 option.value = (args.getintarg("k")) ? "true" : "false";
56 request.filterOptions.push_back (option);
57
58 option.name = "Stem";
59 option.value = (args.getintarg("s")) ? "true" : "false";
60 request.filterOptions.push_back (option);
61
62 if (!args["h"].empty()) {
63 option.name = "Index";
64 option.value = args["h"];
65 request.filterOptions.push_back (option);
66 }
67
68 if (!args["j"].empty()) {
69 option.name = "Subcollection";
70 option.value = args["j"];
71 request.filterOptions.push_back (option);
72 }
73
74 if (!args["n"].empty()) {
75 option.name = "Language";
76 option.value = args["n"];
77 request.filterOptions.push_back (option);
78 }
79
80 option.name = "StartResults";
81 option.value = args["r"];
82 request.filterOptions.push_back (option);
83
84 option.name = "EndResults";
85 int arg_m = args.getintarg("m");
86 int endresults = args.getintarg("o") + (args.getintarg("r") - 1);
87 if (endresults > arg_m) endresults = arg_m;
88 option.value = endresults;
89 request.filterOptions.push_back (option);
90
91 collectproto->filter (args["c"], request, response, err, logout);
92
93 if (err != noError) {
94 outconvertclass text_t2ascii;
95 logout << text_t2ascii
96 << "Error: call to QueryFilter failed in queryaction ("
97 << get_comerror_string (err) << ")\n";
98 return false;
99 }
100 return true;
101}
102
103void format_querystring (text_t &querystring, text_t &quotedstring) {
104 text_t formattedstring;
105 quotedstring.clear();
106
107 text_t::const_iterator here = querystring.begin();
108 text_t::const_iterator end = querystring.end();
109 int foundquote = 0;
110
111 // space is used to insert spaces between Chinese
112 // characters. No space is needed before the first
113 // Chinese character.
114 bool space = false;
115
116 // want to remove ()|!& from querystring so boolean queries are just
117 // "all the words" queries
118 while (here != end) {
119 if (*here == '(' || *here == ')' || *here == '|' ||
120 *here == '!' || *here == '&') {
121 formattedstring.push_back(' ');
122 } else {
123 if (*here == '"') {
124 if (foundquote) {foundquote = 0; quotedstring.push_back(*here);}
125 else foundquote = 1;
126 } else {
127 if ((*here >= 0x4e00 && *here <= 0x9fa5) ||
128 (*here >= 0xf900 && *here <= 0xfa2d)) {
129 // Chinese character
130 if (space) formattedstring.push_back (0x200b);
131 formattedstring.push_back (*here);
132 formattedstring.push_back (0x200b);
133 space = true;
134 } else {
135 // non-Chinese character
136 formattedstring.push_back (*here);
137 space = false;
138 }
139 }
140 if (foundquote) quotedstring.push_back(*here);
141 }
142 here ++;
143 }
144 querystring = formattedstring + quotedstring;
145}
146
Note: See TracBrowser for help on using the repository browser.