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"
29 #include "safeerrno.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;
59 #if !XAPIAN_AT_LEAST(1,3,2)
60 double expand_param_k
= 1.0;
64 set_expansion_scheme(Xapian::Enquire
& enq
, const map
<string
, string
> & opt
)
66 map
<string
, string
>::const_iterator i
= opt
.find("expansion");
67 if (i
== opt
.end()) return;
69 const string
& scheme
= i
->second
;
70 if (scheme
.empty()) return;
72 #if XAPIAN_AT_LEAST(1,3,2)
73 if (startswith(scheme
, "trad")) {
74 const char *p
= scheme
.c_str() + 4;
76 enq
.set_expansion_scheme("trad");
79 if (C_isspace((unsigned char)*p
)) {
80 // Initialise k just to silence compiler warning.
82 if (!double_param(&p
, &k
))
83 parameter_error("Parameter k is invalid", scheme
);
85 parameter_error("Extra data after first parameter", scheme
);
86 enq
.set_expansion_scheme("trad", k
);
91 if (startswith(scheme
, "bo1")) {
92 const char *p
= scheme
.c_str() + 3;
94 enq
.set_expansion_scheme("bo1");
97 if (C_isspace((unsigned char)*p
)) {
98 throw "No parameters are required for BO1";
102 if (startswith(scheme
, "trad")) {
103 const char *p
= scheme
.c_str() + 4;
107 if (C_isspace((unsigned char)*p
)) {
108 // Initialise k just to silence compiler warning.
110 if (!double_param(&p
, &k
))
111 parameter_error("Parameter k is invalid", scheme
);
113 parameter_error("Extra data after first parameter", scheme
);
115 // Avoid "unused parameter" error.
122 throw "Unknown $opt{expansion} setting: " + scheme
;