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"
35 parameter_error(const char * msg
, const string
& scheme
)
45 double_param(const char ** p
, double * ptr_val
)
49 double v
= strtod(*p
, &end
);
50 if (*p
== end
|| errno
) return false;
57 set_expansion_scheme(Xapian::Enquire
& enq
, const map
<string
, string
> & opt
)
59 map
<string
, string
>::const_iterator i
= opt
.find("expansion");
60 if (i
== opt
.end()) return;
62 const string
& scheme
= i
->second
;
63 if (scheme
.empty()) return;
65 if (startswith(scheme
, "trad")) {
66 const char *p
= scheme
.c_str() + 4;
68 enq
.set_expansion_scheme("trad");
72 // Initialise k just to silence compiler warning.
74 if (!double_param(&p
, &k
))
75 parameter_error("Parameter k is invalid", scheme
);
77 parameter_error("Extra data after first parameter", scheme
);
78 enq
.set_expansion_scheme("trad", k
);
83 if (startswith(scheme
, "bo1")) {
84 const char *p
= scheme
.c_str() + 3;
86 enq
.set_expansion_scheme("bo1");
90 throw "No parameters are required for BO1";
94 throw "Unknown $opt{expansion} setting: " + scheme
;