00001 00004 /* Copyright (C) 2007,2009 Olly Betts 00005 * 00006 * This program is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU General Public License as 00008 * published by the Free Software Foundation; either version 2 of the 00009 * License, or (at your option) any later version. 00010 * 00011 * This program is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 * GNU General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU General Public License 00017 * along with this program; if not, write to the Free Software 00018 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00019 */ 00020 00021 #ifndef XAPIAN_INCLUDED_KEYMAKER_H 00022 #define XAPIAN_INCLUDED_KEYMAKER_H 00023 00024 #include <string> 00025 #include <vector> 00026 00027 #include <xapian/deprecated.h> 00028 #include <xapian/types.h> 00029 #include <xapian/visibility.h> 00030 00031 namespace Xapian { 00032 00033 class Document; 00034 00036 class XAPIAN_VISIBILITY_DEFAULT KeyMaker { 00037 public: 00044 virtual std::string operator()(const Xapian::Document & doc) const = 0; 00045 00047 virtual ~KeyMaker(); 00048 }; 00049 00065 class XAPIAN_VISIBILITY_DEFAULT MultiValueKeyMaker : public KeyMaker { 00066 std::vector<std::pair<Xapian::valueno, bool> > slots; 00067 00068 public: 00069 MultiValueKeyMaker() { } 00070 00071 template <class Iterator> 00072 MultiValueKeyMaker(Iterator begin, Iterator end) { 00073 while (begin != end) add_value(*begin++); 00074 } 00075 00076 virtual std::string operator()(const Xapian::Document & doc) const; 00077 00078 void add_value(Xapian::valueno slot, bool reverse = false) { 00079 slots.push_back(std::make_pair(slot, reverse)); 00080 } 00081 }; 00082 00084 class XAPIAN_VISIBILITY_DEFAULT XAPIAN_DEPRECATED_CLASS Sorter : public KeyMaker { }; 00085 00111 class XAPIAN_VISIBILITY_DEFAULT XAPIAN_DEPRECATED_CLASS MultiValueSorter : public Sorter { 00112 std::vector<std::pair<Xapian::valueno, bool> > slots; 00113 00114 public: 00115 MultiValueSorter() { } 00116 00117 template <class Iterator> 00118 MultiValueSorter(Iterator begin, Iterator end) { 00119 while (begin != end) add(*begin++); 00120 } 00121 00122 virtual std::string operator()(const Xapian::Document & doc) const; 00123 00124 void add(Xapian::valueno slot, bool forward = true) { 00125 slots.push_back(std::make_pair(slot, forward)); 00126 } 00127 }; 00128 00129 } 00130 00131 #endif // XAPIAN_INCLUDED_KEYMAKER_H