[Xapian-devel] Re: Bug in TermIterator::skip_to() ?
Pascal Beis
pascal14641 at gmail.com
Fri Feb 25 14:10:44 GMT 2005
Hi again,
I'd forgotton to include the output of the demonstration program, and
mailmain seems not to like .cc attachments, so here's the output and
the code inlined:
---- output ----
First term after skipping to amsterdam: !!!
First term after skipping to amsterda: amsterdam
All terms:
!!!
aarvark
amsterdam
amsterdamse
beast
rotterdam
---- source ----
#include <vector>
#include <string>
#include <iostream>
#include <iterator>
#include <xapian.h>
using namespace std;
int main(int argc, char** argv)
{
string data = "aarvark beast rotterdam amsterdamse amsterdam !!!";
vector<string> words;
int pos = 0;
while ( pos < data.length() ) {
int end = data.find( ' ', pos );
if ( end == string::npos ) end = data.length();
words.push_back( data.substr( pos, end-pos ) );
pos = end+1;
}
try {
Xapian::WritableDatabase db = Xapian::WritableDatabase(
"/tmp/xapian.db", Xapian::DB_CREATE_OR_OPEN );
Xapian::Document doc = Xapian::Document();
doc.set_data( data );
pos = 1;
for ( vector<string>::iterator i = words.begin(); i !=
words.end(); i++ ) {
doc.add_posting( *i, pos++ );
}
db.add_document( doc );
Xapian::TermIterator terms = db.allterms_begin();
string skip = "amsterdam";
terms.skip_to( skip );
cout << "First term after skipping to " << skip << ": " <<
*terms << endl;
terms = db.allterms_begin();
skip = "amsterda";
terms.skip_to( skip );
cout << "First term after skipping to " << skip << ": " <<
*terms << endl;
cout << "All terms:" << endl;
for( Xapian::TermIterator i = db.allterms_begin(); i !=
db.allterms_end(); i++ ) {
cout << *i << endl;
}
} catch ( const Xapian::Error& error ) {
cout << "Exception: " << error.get_msg() << endl;
}
}
Cheers
Pascal
More information about the Xapian-devel
mailing list