49 |
49 |
50 pcrecpp::RE prereg("([A-Za-z0-9_-]+):"); |
50 pcrecpp::RE prereg("([A-Za-z0-9_-]+):"); |
51 pcrecpp::StringPiece input(qstring); // Wrap in a StringPiece |
51 pcrecpp::StringPiece input(qstring); // Wrap in a StringPiece |
52 |
52 |
53 string var; |
53 string var; |
54 while (prereg.Consume(&input, &var)) { |
54 while (prereg.FindAndConsume(&input, &var)) { |
55 string upvar = var+"="; |
55 string upvar = var+":"; |
56 std::transform(var.begin(), var.end(), var.begin(), ::tolower); |
56 //std::transform(var.begin(), var.end(), var.begin(), ::tolower); |
57 std::transform(upvar.begin(), upvar.end(), upvar.begin(), ::toupper); |
57 std::transform(upvar.begin(), upvar.end(), upvar.begin(), ::toupper); |
58 cout << var << upvar << endl; |
58 //cout << var << " -> " << upvar << endl; |
59 qp.add_boolean_prefix(var,upvar); |
59 qp.add_boolean_prefix(var,upvar); |
60 } |
60 } |
61 |
61 |
62 |
62 |
63 // Build the query object |
63 // Build the query object |
64 Xapian::Query query = qp.parse_query(qstring); //Xapian::Query::OP_OR, argv + 2, argv + argc); |
64 Xapian::Query query = qp.parse_query(qstring); //Xapian::Query::OP_OR, argv + 2, argv + argc); |
65 |
65 |
66 cout << "Performing query `" << query.get_description() << "'" << endl; |
66 cerr << "Performing query `" << query.get_description() << "'" << endl; |
67 |
67 |
68 // Give the query object to the enquire session |
68 // Give the query object to the enquire session |
69 enquire.set_query(query); |
69 enquire.set_query(query); |
70 |
70 |
71 // Get the top 10 results of the query |
71 // Get the top 10 results of the query |
72 Xapian::MSet matches = enquire.get_mset(0, db.get_doccount()); |
72 Xapian::MSet matches = enquire.get_mset(0, db.get_doccount()); |
73 |
73 |
74 // Display the results |
74 // Display the results |
75 cout << matches.size() << " results found" << endl; |
75 cerr << matches.size() << " results found" << endl; |
76 |
76 |
77 for (Xapian::MSetIterator i = matches.begin(); |
77 for (Xapian::MSetIterator i = matches.begin(); |
78 i != matches.end(); |
78 i != matches.end(); |
79 ++i) { |
79 ++i) { |
80 Xapian::Document doc = i.get_document(); |
80 Xapian::Document doc = i.get_document(); |
81 cout << "Document ID " << *i << "\t" << |
81 cout << "#" << *i << "\t" << |
82 i.get_percent() << "% [" << |
82 doc.get_data() << endl; |
83 doc.get_data() << "]" << endl; |
|
84 } |
83 } |
85 } catch(const Xapian::Error &error) { |
84 } catch(const Xapian::Error &error) { |
86 cout << "Exception: " << error.get_msg() << endl; |
85 cerr << "Exception: " << error.get_msg() << endl; |
87 } |
86 } |
88 } |
87 } |