[27064] | 1 | /**********************************************************************
|
---|
| 2 | *
|
---|
| 3 | * fieldedqueryfilter.cpp --
|
---|
| 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 | #include "fieldedqueryfilter.h"
|
---|
| 27 |
|
---|
| 28 | fieldedqueryfilterclass::fieldedqueryfilterclass ()
|
---|
| 29 | : queryfilterclass() {
|
---|
| 30 |
|
---|
| 31 | FilterOption_t filtopt;
|
---|
| 32 |
|
---|
| 33 | // -- onePerTerm Level enumerated
|
---|
| 34 | // likely to be Doc, Sec, Para, but we dont assume anything now
|
---|
| 35 | filtopt.clear();
|
---|
| 36 | filtopt.name = "Level";
|
---|
| 37 | filtopt.type = FilterOption_t::enumeratedt;
|
---|
| 38 | filtopt.repeatable = FilterOption_t::onePerTerm;
|
---|
| 39 | filtopt.defaultValue = "";
|
---|
| 40 | filterOptions["Level"] = filtopt;
|
---|
| 41 |
|
---|
| 42 | // -- IndexField, enumerated, used to list available fields
|
---|
| 43 | filtopt.clear();
|
---|
| 44 | filtopt.name = "IndexField";
|
---|
| 45 | filtopt.type = FilterOption_t::enumeratedt;
|
---|
| 46 | filtopt.repeatable = FilterOption_t::onePerTerm;
|
---|
| 47 | filtopt.defaultValue = "";
|
---|
| 48 | filterOptions["IndexField"] = filtopt;
|
---|
| 49 |
|
---|
| 50 | }
|
---|
| 51 |
|
---|
| 52 | void fieldedqueryfilterclass::configure (const text_t &key, const text_tarray &cfgline) {
|
---|
| 53 | queryfilterclass::configure(key, cfgline);
|
---|
| 54 |
|
---|
| 55 | if (key == "indexfieldmap") {
|
---|
| 56 | indexfieldmap.importmap (cfgline);
|
---|
| 57 | text_tarray options;
|
---|
| 58 | indexfieldmap.gettoarray (options);
|
---|
| 59 | filterOptions["IndexField"].validValues = options;
|
---|
| 60 |
|
---|
| 61 | } else if (key == "levelmap") {
|
---|
| 62 | levelmap.importmap (cfgline);
|
---|
| 63 | } else if (key == "indexlevels") {
|
---|
| 64 | filterOptions["Level"].validValues.erase(filterOptions["Level"].validValues.begin(), filterOptions["Level"].validValues.end());
|
---|
| 65 | text_tarray::const_iterator here = cfgline.begin();
|
---|
| 66 | text_tarray::const_iterator end = cfgline.end();
|
---|
| 67 | while (here != end) {
|
---|
| 68 | if (!(*here).empty()) {
|
---|
| 69 | filterOptions["Level"].validValues.push_back(*here);
|
---|
| 70 | }
|
---|
| 71 | ++here;
|
---|
| 72 | }
|
---|
| 73 | } else if (key == "defaultindex") { // used for fields
|
---|
| 74 | indexfieldmap.from2to (cfgline[0], filterOptions["IndexField"].defaultValue);
|
---|
| 75 | } else if (key == "defaultlevel") {
|
---|
| 76 | levelmap.from2to (cfgline[0], filterOptions["Level"].defaultValue);
|
---|
| 77 | }
|
---|
| 78 |
|
---|
| 79 | }
|
---|
| 80 |
|
---|
| 81 | fieldedqueryfilterclass::~fieldedqueryfilterclass () {
|
---|
| 82 | }
|
---|
| 83 |
|
---|
| 84 | bool fieldedqueryfilterclass::init (ostream &logout) {
|
---|
| 85 |
|
---|
| 86 | if (!queryfilterclass::init(logout)) {
|
---|
| 87 | return false;
|
---|
| 88 | }
|
---|
| 89 |
|
---|
| 90 | if (filterOptions["IndexField"].defaultValue.empty()) {
|
---|
| 91 | // use first index in map as default if no default is set explicitly
|
---|
| 92 | text_tarray fromarray;
|
---|
| 93 | indexfieldmap.getfromarray(fromarray);
|
---|
| 94 | if (fromarray.size()) {
|
---|
| 95 | filterOptions["IndexField"].defaultValue = fromarray[0];
|
---|
| 96 | }
|
---|
| 97 | }
|
---|
| 98 | if (filterOptions["Levels"].defaultValue.empty()) {
|
---|
| 99 | // use first level as default if no default is set explicitly
|
---|
| 100 | if (!filterOptions["Level"].validValues[0].empty())
|
---|
| 101 | filterOptions["Levels"].defaultValue = filterOptions["Level"].validValues[0];
|
---|
| 102 | }
|
---|
| 103 |
|
---|
| 104 | return true;
|
---|
| 105 | }
|
---|
| 106 |
|
---|
| 107 | //whether a query is a full text browse
|
---|
| 108 | bool fieldedqueryfilterclass::full_text_browse (int filterRequestOptions) {
|
---|
| 109 | return (filterRequestOptions & FRfullTextBrowse);
|
---|
| 110 | }
|
---|