[Xapian-discuss] Question on "single writer, multiple reader"
Gang Chen
pkuchengang at gmail.com
Thu Jan 22 05:19:27 GMT 2015
Hi, please see the attachments.
I compiled them with the following commands:
g++ -g -I <Xapian include path> batch_slot_indexer.cc libxapian.a
-luuid -lz -o batch_slot_indexer
g++ -g -I <Xapian include path> slot_searcher.cc libxapian.a -luuid -lz
-o slot_searcher
and tested them:
./batch_slot_indexer MOVIE 1
./slot_searcher MOVIE // keep it running
./batch_slot_indexer MOVIE 1000
Best,
Gang
2015-01-22 12:56 GMT+08:00 Olly Betts <olly at survex.com>:
> On Thu, Jan 22, 2015 at 11:45:37AM +0800, Gang Chen wrote:
> > Could it be something wrong with the slot value processing in the
> > Chert backend?
>
> Sounds like it. Can you provide a complete example which reproduces
> this?
>
> Cheers,
> Olly
>
-------------- next part --------------
#include <xapian.h>
#include <iostream>
#include <stdlib.h>
#include <sstream>
using namespace std;
int main(int argc, char **argv)
{
// Simplest possible options parsing: we just require three or more
// parameters.
if(argc < 3) {
cout << "usage: " << argv[0] <<
" <path to database> N" << endl;
exit(1);
}
// Catch any Xapian::Error exceptions thrown
try {
// Make the database
Xapian::WritableDatabase database(argv[1], Xapian::DB_CREATE_OR_OPEN);
//Xapian::WritableDatabase database = Xapian::Flint::open(argv[1], Xapian::DB_CREATE_OR_OPEN);
// Make the document
int N = atoi(argv[2]);
for (int i = 0; i < N; ++i) {
Xapian::Document newdocument;
stringstream ss;
string num_str;
ss << i;
ss >> num_str;
newdocument.add_value(1, "title_" + num_str); // slot1 : title_n
newdocument.add_posting("title_" + num_str, 1, 1);
newdocument.add_value(2, "time_" + num_str); // slot2 : time_n
newdocument.add_posting("time_" + num_str, 2, 1);
newdocument.set_data("DOC_" + num_str); // data : DOC_n
// Add the document to the database
long docid = database.add_document(newdocument);
if (docid % 20000 == 0) {
cout << "docid:" << docid << endl;
//database.commit();
}
}
database.commit();
} catch(const Xapian::Error &error) {
cout << "Exception: " << error.get_msg() << endl;
}
}
-------------- next part --------------
#include <xapian.h>
#include <iostream>
#include <stdlib.h>
using namespace std;
int main(int argc, char **argv)
{
// Simplest possible options parsing: we just require two or more
// parameters.
if (argc < 2) {
cout << "usage: " << argv[0] <<
" <path to database>" << endl;
exit(1);
}
// Catch any Xapian::Error exceptions thrown
try {
// Make the database
Xapian::Database db(argv[1]);
// Start an enquire session
Xapian::Enquire enquire(db);
while (true) {
// Build the query object
string line;
getline(cin, line);
Xapian::Query query(line, 1, 1);
cout << "Performing query `" << query.get_description() << "'" << endl;
// Give the query object to the enquire session
db.reopen();
enquire.set_query(query);
cout << "enquire.get_description():" << enquire.get_description() << endl;
// Get the top 10 results of the query
Xapian::MSet matches = enquire.get_mset(0, 10);
// Display the results
cout << matches.size() << " results found" << endl;
for (Xapian::MSetIterator i = matches.begin(); i != matches.end(); ++i) {
Xapian::Document doc = i.get_document();
cout << "Document ID " << *i << "\t" << i.get_percent() << "%" << endl;
cout << "[" << doc.get_value(1) << "]" << endl;
cout << "[" << doc.get_value(2) << "]" << endl;
}
}
} catch(const Xapian::Error &error) {
cout << "Exception: " << error.get_msg() << endl;
}
}
More information about the Xapian-discuss
mailing list