2 * @brief Set the query expansion scheme for Omega
4 /* Copyright (C) 2009,2013,2014,2015 Olly Betts
5 * Copyright (C) 2013 Aarsh Shah
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (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 USA
26 #include "stringutils.h"
30 #include "common/noreturn.h"
34 XAPIAN_NORETURN(static void
35 parameter_error(const char * param
, const string
& scheme
));
38 parameter_error(const char * msg
, const string
& scheme
)
48 double_param(const char ** p
, double * ptr_val
)
52 double v
= strtod(*p
, &end
);
53 if (*p
== end
|| errno
) return false;
60 set_expansion_scheme(Xapian::Enquire
& enq
, const map
<string
, string
> & opt
)
62 map
<string
, string
>::const_iterator i
= opt
.find("expansion");
63 if (i
== opt
.end()) return;
65 const string
& scheme
= i
->second
;
66 if (scheme
.empty()) return;
68 if (startswith(scheme
, "trad")) {
69 const char *p
= scheme
.c_str() + 4;
71 enq
.set_expansion_scheme("trad");
75 // Initialise k just to silence compiler warning.
77 if (!double_param(&p
, &k
))
78 parameter_error("Parameter k is invalid", scheme
);
80 parameter_error("Extra data after first parameter", scheme
);
81 enq
.set_expansion_scheme("trad", k
);
86 if (startswith(scheme
, "bo1")) {
87 const char *p
= scheme
.c_str() + 3;
89 enq
.set_expansion_scheme("bo1");
93 throw "No parameters are required for BO1";
97 throw "Unknown $opt{expansion} setting: " + scheme
;