00001
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include <xapian.h>
00024
00025 #include <iostream>
00026 #include <string>
00027
00028 #include <cstdlib>
00029 #include <cstring>
00030
00031 using namespace std;
00032
00033 int
00034 main(int argc, char **argv)
00035 try {
00036
00037 if (argc < 3) {
00038 int rc = 1;
00039 if (argv[1]) {
00040 if (strcmp(argv[1], "--version") == 0) {
00041 cout << "simplesearch" << endl;
00042 exit(0);
00043 }
00044 if (strcmp(argv[1], "--help") == 0) {
00045 rc = 0;
00046 }
00047 }
00048 cout << "Usage: " << argv[0] << " PATH_TO_DATABASE QUERY" << endl;
00049 exit(rc);
00050 }
00051
00052
00053 Xapian::Database db(argv[1]);
00054
00055
00056 Xapian::Enquire enquire(db);
00057
00058
00059
00060
00061 string query_string(argv[2]);
00062 argv += 3;
00063 while (*argv) {
00064 query_string += ' ';
00065 query_string += *argv++;
00066 }
00067
00068
00069 Xapian::QueryParser qp;
00070 Xapian::Stem stemmer("english");
00071 qp.set_stemmer(stemmer);
00072 qp.set_database(db);
00073 qp.set_stemming_strategy(Xapian::QueryParser::STEM_SOME);
00074 Xapian::Query query = qp.parse_query(query_string);
00075 cout << "Parsed query is: " << query.get_description() << endl;
00076
00077
00078 enquire.set_query(query);
00079 Xapian::MSet matches = enquire.get_mset(0, 10);
00080
00081
00082 cout << matches.get_matches_estimated() << " results found.\n";
00083 cout << "Matches 1-" << matches.size() << ":\n" << endl;
00084
00085 for (Xapian::MSetIterator i = matches.begin(); i != matches.end(); ++i) {
00086 cout << i.get_rank() + 1 << ": " << i.get_percent() << "% docid=" << *i
00087 << " [" << i.get_document().get_data() << "]\n\n";
00088 }
00089 } catch (const Xapian::Error &e) {
00090 cout << e.get_description() << endl;
00091 exit(1);
00092 }