1 | #include <xapian.h>
|
---|
2 | #include <iostream>
|
---|
3 | #include <sys/types.h>
|
---|
4 | #include <unistd.h>
|
---|
5 | #include <stdlib.h>
|
---|
6 | #include <string.h>
|
---|
7 | #include <stdio.h>
|
---|
8 |
|
---|
9 | using namespace std;
|
---|
10 |
|
---|
11 | static void get_memory() {
|
---|
12 | static pid_t pid = getpid();
|
---|
13 | char buf[80];
|
---|
14 | sprintf(buf, "ps -p %d -o rss -o vsz | tail -1", pid);
|
---|
15 | system(buf);
|
---|
16 | }
|
---|
17 |
|
---|
18 | static void test(const char * name, bool get_data) {
|
---|
19 | cout << "version: " << Xapian::version_string() << endl;
|
---|
20 | Xapian::Database database(name);
|
---|
21 | Xapian::Enquire enquiry(database);
|
---|
22 | enquiry.set_query(Xapian::Query::MatchAll);
|
---|
23 | Xapian::MSet matches = enquiry.get_mset(0, database.get_doccount());
|
---|
24 | Xapian::doccount total = matches.get_matches_estimated();
|
---|
25 | cout << "matches: " << total << " ";
|
---|
26 | get_memory();
|
---|
27 |
|
---|
28 | for (Xapian::doccount i = 0; i < total; ++i) {
|
---|
29 | if (get_data)
|
---|
30 | matches[i].get_document();
|
---|
31 | if (i % 100 == 99) {
|
---|
32 | cout << "read: " << i + 1 << " " << flush;
|
---|
33 | get_memory();
|
---|
34 | }
|
---|
35 | }
|
---|
36 | }
|
---|
37 |
|
---|
38 | int main(int, char **argv) {
|
---|
39 | bool get_data = true;
|
---|
40 | ++argv;
|
---|
41 | if (*argv && strcmp(*argv, "-d") == 0) {
|
---|
42 | get_data = false;
|
---|
43 | ++argv;
|
---|
44 | }
|
---|
45 | test(*argv, get_data);
|
---|
46 | }
|
---|