Branch data Line data Source code
1 : : /** @file valuesetmatchdecider.h
2 : : * @brief MatchDecider subclass for filtering results by value.
3 : : */
4 : : /* Copyright 2008 Lemur Consulting Ltd
5 : : * Copyright 2008,2009,2011,2013,2014,2017 Olly Betts
6 : : *
7 : : * This program is free software; you can redistribute it and/or
8 : : * modify it under the terms of the GNU General Public License as
9 : : * published by the Free Software Foundation; either version 2 of the
10 : : * License, or (at your option) any later version.
11 : : *
12 : : * This program is distributed in the hope that it will be useful,
13 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 : : * GNU General Public License for more details.
16 : : *
17 : : * You should have received a copy of the GNU General Public License
18 : : * along with this program; if not, write to the Free Software
19 : : * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
20 : : * USA
21 : : */
22 : :
23 : : #ifndef XAPIAN_INCLUDED_VALUESETMATCHDECIDER_H
24 : : #define XAPIAN_INCLUDED_VALUESETMATCHDECIDER_H
25 : :
26 : : #if !defined XAPIAN_IN_XAPIAN_H && !defined XAPIAN_LIB_BUILD
27 : : # error "Never use <xapian/valuesetmatchdecider.h> directly; include <xapian.h> instead."
28 : : #endif
29 : :
30 : : #include <xapian/matchdecider.h>
31 : : #include <xapian/types.h>
32 : : #include <xapian/visibility.h>
33 : :
34 : : #include <string>
35 : : #include <set>
36 : :
37 : : namespace Xapian {
38 : :
39 : : class Document;
40 : :
41 : : /** MatchDecider filtering results based on whether document values are in a
42 : : * user-defined set.
43 : : */
44 [ - + ]: 26 : class XAPIAN_VISIBILITY_DEFAULT ValueSetMatchDecider : public MatchDecider {
45 : : /** Set of values to test for. */
46 : : std::set<std::string> testset;
47 : :
48 : : /** The value slot to look in. */
49 : : valueno valuenum;
50 : :
51 : : /** Whether to include or exclude documents with the specified values.
52 : : *
53 : : * If true, documents with a value in the set are returned.
54 : : * If false, documents with a value not in the set are returned.
55 : : */
56 : : bool inclusive;
57 : :
58 : : public:
59 : : /** Construct a ValueSetMatchDecider.
60 : : *
61 : : * @param slot The value slot number to look in.
62 : : *
63 : : * @param inclusive_ If true, match decider accepts documents which have a
64 : : * value in the specified slot which is a member of the test set; if
65 : : * false, match decider accepts documents which do not have a value in the
66 : : * specified slot.
67 : : */
68 : 13 : ValueSetMatchDecider(Xapian::valueno slot, bool inclusive_)
69 [ + - ]: 13 : : valuenum(slot), inclusive(inclusive_) { }
70 : :
71 : : /** Add a value to the test set.
72 : : *
73 : : * @param value The value to add to the test set.
74 : : */
75 : 14 : void add_value(const std::string& value)
76 : : {
77 : 14 : testset.insert(value);
78 : 14 : }
79 : :
80 : : /** Remove a value from the test set.
81 : : *
82 : : * @param value The value to remove from the test set.
83 : : */
84 : 3 : void remove_value(const std::string& value)
85 : : {
86 : 3 : testset.erase(value);
87 : 3 : }
88 : :
89 : : /** Decide whether we want a particular document to be in the MSet.
90 : : *
91 : : * @param doc The document to test.
92 : : * @return true if the document is acceptable, or false if the
93 : : * document should be excluded from the MSet.
94 : : */
95 : : bool operator()(const Xapian::Document& doc) const;
96 : : };
97 : :
98 : : }
99 : :
100 : : #endif /* XAPIAN_INCLUDED_VALUESETMATCHDECIDER_H */
|