|
Revision 8842, 2.5 kB
(checked in by olly, 19 months ago)
|
|
examples/simplesearch.cc: Report "Matches 1-<N>:".
|
-
Property svn:eol-style set to
native
-
Property svn:keywords set to
Author Date Id Revision
|
| Line | |
|---|
| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | |
|---|
| 18 | |
|---|
| 19 | |
|---|
| 20 | |
|---|
| 21 | |
|---|
| 22 | |
|---|
| 23 | #include <xapian.h> |
|---|
| 24 | |
|---|
| 25 | #include <iostream> |
|---|
| 26 | #include <string> |
|---|
| 27 | |
|---|
| 28 | #include <stdlib.h> // For exit(). |
|---|
| 29 | |
|---|
| 30 | using namespace std; |
|---|
| 31 | |
|---|
| 32 | int |
|---|
| 33 | main(int argc, char **argv) |
|---|
| 34 | try { |
|---|
| 35 | |
|---|
| 36 | if (argc < 3) { |
|---|
| 37 | cout << "Usage: " << argv[0] << " PATH_TO_DATABASE QUERY" << endl; |
|---|
| 38 | exit(1); |
|---|
| 39 | } |
|---|
| 40 | |
|---|
| 41 | |
|---|
| 42 | Xapian::Database db(argv[1]); |
|---|
| 43 | |
|---|
| 44 | |
|---|
| 45 | Xapian::Enquire enquire(db); |
|---|
| 46 | |
|---|
| 47 | |
|---|
| 48 | |
|---|
| 49 | |
|---|
| 50 | string query_string(argv[2]); |
|---|
| 51 | argv += 3; |
|---|
| 52 | while (*argv) { |
|---|
| 53 | query_string += ' '; |
|---|
| 54 | query_string += *argv++; |
|---|
| 55 | } |
|---|
| 56 | |
|---|
| 57 | |
|---|
| 58 | Xapian::QueryParser qp; |
|---|
| 59 | Xapian::Stem stemmer("english"); |
|---|
| 60 | qp.set_stemmer(stemmer); |
|---|
| 61 | qp.set_database(db); |
|---|
| 62 | qp.set_stemming_strategy(Xapian::QueryParser::STEM_SOME); |
|---|
| 63 | Xapian::Query query = qp.parse_query(query_string); |
|---|
| 64 | cout << "Parsed query is: " << query.get_description() << endl; |
|---|
| 65 | |
|---|
| 66 | |
|---|
| 67 | enquire.set_query(query); |
|---|
| 68 | Xapian::MSet matches = enquire.get_mset(0, 10); |
|---|
| 69 | |
|---|
| 70 | |
|---|
| 71 | cout << matches.get_matches_estimated() << " results found.\n"; |
|---|
| 72 | cout << "Matches 1-" << matches.size() << ":\n" << endl; |
|---|
| 73 | |
|---|
| 74 | for (Xapian::MSetIterator i = matches.begin(); i != matches.end(); ++i) { |
|---|
| 75 | cout << i.get_rank() + 1 << ": " << i.get_percent() << "% docid=" << *i |
|---|
| 76 | << " [" << i.get_document().get_data() << "]\n\n"; |
|---|
| 77 | } |
|---|
| 78 | } catch (const Xapian::Error &e) { |
|---|
| 79 | cout << e.get_description() << endl; |
|---|
| 80 | exit(1); |
|---|
| 81 | } |
|---|