1 /** @file xapian-train.cc
2 * @brief Command line tool to train and save the LTR model
4 /* Copyright (C) 2004,2005,2006,2007,2008,2009,2010,2015 Olly Betts
5 * Copyright (C) 2011 Parth Gupta
6 * Copyright (C) 2016 Ayush Tomar
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of the
11 * License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
27 #include <xapian-letor.h>
32 #include "gnu_getopt.h"
36 #define PROG_NAME "xapian-train"
37 #define PROG_DESC "Command line tool to train and save the LTR model"
42 static void show_usage() {
43 cout
<< "Usage: " PROG_NAME
" [OPTIONS] PATH_TO_TRAINING_FILE MODEL_METADATA_KEY\n"
45 " -d, --db=DIRECTORY path to database to search\n"
46 " --help display this help and exit\n"
47 " --version output version information and exit\n";
51 main(int argc
, char **argv
)
53 const char * opts
= "d:h:v";
54 static const struct option long_opts
[] = {
55 { "db", required_argument
, 0, 'd' },
56 { "help", no_argument
, 0, OPT_HELP
},
57 { "version", no_argument
, 0, OPT_VERSION
},
61 bool have_database
= false;
66 while ((c
= gnu_getopt_long(argc
, argv
, opts
, long_opts
, 0)) != -1) {
73 cout
<< PROG_NAME
" - " PROG_DESC
"\n\n";
77 cout
<< PROG_NAME
" - " PACKAGE_STRING
<< endl
;
79 case ':': // missing parameter
80 case '?': // unknown option
86 if (argc
- optind
!= 2) {
91 string trainingfile
= argv
[optind
];
92 string model_metadata_key
= argv
[optind
+ 1];
95 cout
<< "No database specified so not running the query." << endl
;
99 // Initialise Ranker object.
100 // See Ranker documentation for available Ranker subclass options.
101 Xapian::Ranker
* ranker
= new Xapian::ListNETRanker();
104 ranker
->set_database_path(db_path
);
106 // Perform training and save model as database metadata with key "model_metadata_key"
107 ranker
->train_model(trainingfile
, model_metadata_key
);
113 } catch (const Xapian::Error
& err
) {
114 cout
<< err
.get_description() << endl
;