/********************************************************************** * * querytools.cpp -- * Copyright (C) 1999 The New Zealand Digital Library Project * * A component of the Greenstone digital library software * from the New Zealand Digital Library Project at the * University of Waikato, New Zealand. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * *********************************************************************/ #include "querytools.h" #include #include "unitool.h" // for is_unicode_letdig // request.filterResultOptions and request.fields (if required) should // be set from the calling code void set_queryfilter_options (FilterRequest_t &request, const text_t &querystring, cgiargsclass &args) { request.filterName = "QueryFilter"; OptionValue_t option; option.name = "Term"; option.value = querystring; request.filterOptions.push_back (option); option.name = "QueryType"; option.value = (args.getintarg("t")) ? "ranked" : "boolean"; request.filterOptions.push_back (option); option.name = "MatchMode"; option.value = (args.getintarg("t")) ? "some" : "all"; request.filterOptions.push_back (option); option.name = "Casefold"; option.value = (args.getintarg("k")) ? "true" : "false"; request.filterOptions.push_back (option); option.name = "Stem"; option.value = (args.getintarg("s")) ? "true" : "false"; request.filterOptions.push_back (option); if (!args["h"].empty()) { option.name = "Index"; option.value = args["h"]; request.filterOptions.push_back (option); } if (!args["j"].empty()) { option.name = "Subcollection"; option.value = args["j"]; request.filterOptions.push_back (option); } if (!args["n"].empty()) { option.name = "Language"; option.value = args["n"]; request.filterOptions.push_back (option); } if (!args["g"].empty()) { // granularity for mgpp option.name = "Level"; option.value = args["g"]; request.filterOptions.push_back (option); } set_more_queryfilter_options (request, args); } void set_queryfilter_options (FilterRequest_t &request, const text_t &querystring1, const text_t &querystring2, cgiargsclass &args) { set_queryfilter_options (request, querystring1, args); // fill in the second query if needed if (!args["cq2"].empty()) { OptionValue_t option; option.name = "CombineQuery"; option.value = args["cq2"]; request.filterOptions.push_back (option); option.name = "Term"; option.value = querystring2; request.filterOptions.push_back (option); option.name = "QueryType"; option.value = (args.getintarg("t")) ? "ranked" : "boolean"; request.filterOptions.push_back (option); option.name = "Casefold"; option.value = (args.getintarg("k")) ? "true" : "false"; request.filterOptions.push_back (option); option.name = "Stem"; option.value = (args.getintarg("s")) ? "true" : "false"; request.filterOptions.push_back (option); if (!args["h2"].empty()) { option.name = "Index"; option.value = args["h2"]; request.filterOptions.push_back (option); } if (!args["j2"].empty()) { option.name = "Subcollection"; option.value = args["j2"]; request.filterOptions.push_back (option); } if (!args["n2"].empty()) { option.name = "Language"; option.value = args["n2"]; request.filterOptions.push_back (option); } } set_more_queryfilter_options (request, args); } void set_more_queryfilter_options (FilterRequest_t &request, cgiargsclass &args) { OptionValue_t option; int arg_m = args.getintarg("m"); option.name = "Maxdocs"; option.value = arg_m; request.filterOptions.push_back (option); // option.name = "StartResults"; // option.value = args["r"]; // request.filterOptions.push_back (option); // option.name = "EndResults"; // int endresults = args.getintarg("o") + (args.getintarg("r") - 1); // if ((endresults > arg_m) && (arg_m != -1)) endresults = arg_m; // option.value = endresults; // request.filterOptions.push_back (option); } void format_querystring (text_t &querystring, int querymode) { text_t formattedstring; text_t::const_iterator here = querystring.begin(); text_t::const_iterator end = querystring.end(); // space is used to insert spaces between Chinese // characters. No space is needed before the first // Chinese character. bool space = false; // want to remove ()|!& from querystring so boolean queries are just // "all the words" queries (unless querymode is advanced) while (here != end) { if ((querymode == 0) && (*here == '(' || *here == ')' || *here == '|' || *here == '!' || *here == '&')) { formattedstring.push_back(' '); } else { if ((*here >= 0x4e00 && *here <= 0x9fa5) || (*here >= 0xf900 && *here <= 0xfa2d)) { // Chinese character if (space) formattedstring.push_back (0x200b); formattedstring.push_back (*here); formattedstring.push_back (0x200b); space = true; } else { // non-Chinese character formattedstring.push_back (*here); space = false; } } here ++; } querystring = formattedstring; } void add_dates(text_t &querystring, int startdate, int enddate, int startbc, int endbc) { if(startdate) { int querystringis = 0; text_t::const_iterator here = querystring.begin(); text_t::const_iterator end = querystring.end(); while(here!=end) { if(!(isspace((*here)))){ here = end; querystringis = 1; } else here++; } //converting BCE dates if(startbc && startdate > 0) { startdate *= -1; } if(endbc && enddate > 0) { enddate *= -1; } if(enddate != 0 && enddate