36 #define PROG_NAME "quest" 37 #define PROG_DESC "Xapian command line search tool" 40 static const char *
const sw[] = {
41 "a",
"about",
"an",
"and",
"are",
"as",
"at",
46 "i",
"in",
"is",
"it",
48 "that",
"the",
"this",
"to",
49 "was",
"what",
"when",
"where",
"which",
"who",
"why",
"will",
"with" 52 struct qp_flag {
const char *
s;
unsigned f; };
73 return strcmp(f1.
s, f2.
s) < 0;
76 struct qp_op {
const char *
s;
unsigned f; };
89 return strcmp(f1.
s, f2.
s) < 0;
110 struct wt {
const char *
s;
int f; };
131 return strcmp(f1.
s, f2.
s) < 0;
135 cout <<
"Usage: " PROG_NAME " [OPTIONS] 'QUERY'\n" 136 "NB: QUERY should be quoted to protect it from the shell.\n\n" 138 " -d, --db=DIRECTORY database to search (multiple databases may\n" 140 " -m, --msize=MSIZE maximum number of matches to return\n" 141 " -c, --check-at-least=HOWMANY minimum number of matches to check\n" 142 " -s, --stemmer=LANG set the stemming language, the default is\n" 143 " 'english' (pass 'none' to disable stemming)\n" 144 " -p, --prefix=PFX:TERMPFX add a prefix\n" 145 " -b, --boolean-prefix=PFX:TERMPFX add a boolean prefix\n" 146 " -f, --flags=FLAG1[,FLAG2]... specify QueryParser flags (default:\n" 147 " default). Valid flags:";
152 size_t len = strlen(i->s);
153 if (pos < 256) cout <<
',';
154 if (pos + len >= 78) {
164 " -o, --default-op=OP specify QueryParser default operator\n" 165 " (default: or). Valid operators:";
168 size_t len = strlen(i->s);
169 if (pos < 256) cout <<
',';
170 if (pos + len >= 78) {
180 " -w, --weight=SCHEME specify weighting scheme to use\n" 181 " (default: bm25). Valid schemes:";
183 for (
const wt * i = wt_tab; i - wt_tab <
n_wt_tab; ++i) {
184 size_t len = strlen(i->s);
185 if (pos < 256) cout <<
',';
186 if (pos + len >= 78) {
196 " -h, --help display this help and exit\n" 197 " -v, --version output version information and exit\n";
216 const qp_op * p = lower_bound(op_tab, op_tab + n_op_tab, f);
217 if (p == op_tab + n_op_tab || f < *p)
227 const wt * p = lower_bound(wt_tab, wt_tab + n_wt_tab, f);
228 if (p == wt_tab + n_wt_tab || f < *p)
236 const char *
opts =
"d:m:c:s:p:b:f:o:w:hv";
237 static const struct option long_opts[] = {
257 bool have_database =
false;
262 bool flags_set =
false;
270 unsigned long v = strtoul(
optarg, &p, 10);
272 if (*p || v != msize) {
274 <<
"' passed for msize" << endl;
281 unsigned long v = strtoul(
optarg, &p, 10);
283 if (*p || v != check_at_least) {
285 <<
"' passed for check_at_least" << endl;
292 have_database =
true;
298 cerr <<
"Unknown stemming language '" <<
optarg <<
"'.\n" 299 "Available language names are: " 304 case 'b':
case 'p': {
305 const char * colon = strchr(
optarg,
':');
307 cerr << argv[0] <<
": need ':' when setting prefix" << endl;
311 string termprefix(colon + 1);
322 char * comma = strchr(
optarg,
',');
327 cerr <<
"Unknown flag '" <<
optarg <<
"'" << endl;
337 cerr <<
"Unknown op '" <<
optarg <<
"'" << endl;
346 cerr <<
"Unknown weighting scheme '" <<
optarg <<
"'" << endl;
380 if (!correction.empty())
381 cout <<
"Did you mean: " << correction <<
"\n\n";
385 if (!have_database) {
386 cout <<
"No database specified so not running the query." << endl;
446 if (lower_bound == upper_bound) {
447 cout <<
"Exactly " << estimate <<
" matches" << endl;
449 cout <<
"Between " << lower_bound <<
" and " << upper_bound
450 <<
" matches, best estimate is " << estimate << endl;
453 cout <<
"MSet:" << endl;
457 cout << *i <<
": [" << i.get_weight() <<
"]\n" << data <<
"\n";
461 cout <<
"Couldn't parse query: " << e.
get_msg() << endl;
Support AND, OR, etc even if they aren't in ALLCAPS.
static int decode_wt(const char *s)
static const char *const sw[]
Wrappers to allow GNU getopt to be used cleanly from C++ code.
Simple implementation of Stopper class - this will suit most users.
void set_default_op(Query::op default_op)
Set the default operator.
This class is used to access a database, or a group of databases.
int gnu_getopt_long(int argc_, char *const *argv_, const char *shortopts_, const struct option *longopts_, int *optind_)
static int decode_qp_op(const char *s)
int main(int argc, char **argv)
Class representing a stemming algorithm.
double weight
The weight of a document or term.
void set_stopper(const Stopper *stop=NULL)
Set the stopper.
static unsigned decode_qp_flag(const char *s)
std::string get_corrected_query_string() const
Get the spelling-corrected query string.
Xapian::doccount get_matches_lower_bound() const
Lower bound on the total number of matching documents.
const std::string & get_msg() const
Message giving details of the error, intended for human consumption.
Build a Xapian::Query object from a user query string.
static const qp_op op_tab[]
Class representing a list of search results.
This class implements the InL2 weighting scheme.
Pick the maximum weight of any subquery.
MSet get_mset(Xapian::doccount first, Xapian::doccount maxitems, Xapian::doccount checkatleast=0, const RSet *omrset=0, const MatchDecider *mdecider=0) const
Get (a portion of) the match set for the current query.
Indicates a query string can't be parsed.
Produce a query which doesn't use positional information.
Xapian::Weight subclass implementing the PL2+ probabilistic formula.
static Xapian::Stem stemmer
Enable automatic use of synonyms for single terms and groups of terms.
static bool operator<(const qp_flag &f1, const qp_flag &f2)
void set_stemmer(const Xapian::Stem &stemmer)
Set the stemmer.
Xapian::doccount get_matches_upper_bound() const
Upper bound on the total number of matching documents.
This class implements the BB2 weighting scheme.
Xapian::Weight subclass implementing Coordinate Matching.
InvalidArgumentError indicates an invalid parameter value was passed to the API.
Class implementing a "boolean" weighting scheme.
Pick the best N subqueries and combine with OP_OR.
void set_stemming_strategy(stem_strategy strategy)
Set the stemming strategy.
Iterator over a Xapian::MSet.
Match only documents where all subqueries match near and in order.
Public interfaces for the Xapian library.
Enable spelling correction.
static std::string get_available_languages()
Return a list of available languages.
void add_boolean_prefix(const std::string &field, const std::string &prefix, const std::string *grouping=NULL)
Add a boolean term prefix allowing the user to restrict a search with a boolean filter specified in t...
MSetIterator begin() const
Return iterator pointing to the first item in this MSet.
MSetIterator end() const
Return iterator pointing to just after the last item in this MSet.
Xapian::Weight subclass implementing the traditional probabilistic formula.
This class implements the DLH weighting scheme, which is a representative scheme of the Divergence fr...
This class implements the PL2 weighting scheme.
This class implements the IneB2 weighting scheme.
#define required_argument
Query parse_query(const std::string &query_string, unsigned flags=FLAG_DEFAULT, const std::string &default_prefix=std::string())
Parse a query.
void add_database(const Database &database)
Add an existing database (or group of databases) to those accessed by this object.
void set_query(const Xapian::Query &query, Xapian::termcount qlen=0)
Set the query to run.
Match like OP_OR but weighting as if a single term.
std::string get_description() const
Return a string describing this object.
This class implements the IfB2 weighting scheme.
Match only documents which all subqueries match.
static Xapian::Query query(Xapian::Query::op op, const string &t1=string(), const string &t2=string(), const string &t3=string(), const string &t4=string(), const string &t5=string(), const string &t6=string(), const string &t7=string(), const string &t8=string(), const string &t9=string(), const string &t10=string())
Enable automatic use of synonyms for single terms.
Xapian::doccount get_matches_estimated() const
Estimate of the total number of matching documents.
void set_database(const Database &db)
Specify the database being searched.
Accumulate unstem and stoplist results.
std::string get_description() const
Return a string describing this object.
This class provides an interface to the information retrieval system for the purpose of searching...
unsigned XAPIAN_DOCID_BASE_TYPE doccount
A count of documents.
Support AND, OR, etc and bracketed subexpressions.
Match only documents where all subqueries match near each other.
This class implements the DPH weighting scheme.
All exceptions thrown by Xapian are subclasses of Xapian::Error.
Match documents which at least one subquery matches.
Allow queries such as 'NOT apples'.
static const qp_flag flag_tab[]
Enable generation of n-grams from CJK text.
void set_weighting_scheme(const Weight &weight_)
Set the weighting scheme to use for queries.
Class representing a query.
void add_prefix(const std::string &field, const std::string &prefix)
Add a free-text field term prefix.
std::string get_data() const
Get data stored in the document.
Xapian::Weight subclass implementing the Language Model formula.
Enable synonym operator '~'.
A handle representing a document in a Xapian database.
Xapian::Weight subclass implementing the BM25+ probabilistic formula.
Xapian::Weight subclass implementing the BM25 probabilistic formula.
Xapian::Weight subclass implementing the tf-idf weighting scheme.