1 /** @file valuesetmatchdecider.h
2 * @brief MatchDecider subclass for filtering results by value.
4 /* Copyright 2008 Lemur Consulting Ltd
5 * Copyright 2008,2009,2011,2013,2014,2017 Olly Betts
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.
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.
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
23 #ifndef XAPIAN_INCLUDED_VALUESETMATCHDECIDER_H
24 #define XAPIAN_INCLUDED_VALUESETMATCHDECIDER_H
26 #if !defined XAPIAN_IN_XAPIAN_H && !defined XAPIAN_LIB_BUILD
27 # error "Never use <xapian/valuesetmatchdecider.h> directly; include <xapian.h> instead."
30 #include <xapian/matchdecider.h>
31 #include <xapian/types.h>
32 #include <xapian/visibility.h>
41 /** MatchDecider filtering results based on whether document values are in a
44 class XAPIAN_VISIBILITY_DEFAULT ValueSetMatchDecider
: public MatchDecider
{
45 /** Set of values to test for. */
46 std::set
<std::string
> testset
;
48 /** The value slot to look in. */
51 /** Whether to include or exclude documents with the specified values.
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.
59 /** Construct a ValueSetMatchDecider.
61 * @param slot The value slot number to look in.
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
68 ValueSetMatchDecider(Xapian::valueno slot
, bool inclusive_
)
69 : valuenum(slot
), inclusive(inclusive_
) { }
71 /** Add a value to the test set.
73 * @param value The value to add to the test set.
75 void add_value(const std::string
& value
)
77 testset
.insert(value
);
80 /** Remove a value from the test set.
82 * @param value The value to remove from the test set.
84 void remove_value(const std::string
& value
)
89 /** Decide whether we want a particular document to be in the MSet.
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.
95 bool operator()(const Xapian::Document
& doc
) const;
100 #endif /* XAPIAN_INCLUDED_VALUESETMATCHDECIDER_H */