Jarrod Roberson
2006-Oct-31 17:37 UTC
[Xapian-discuss] having trouble getting position lists from termtierators
I am writing some Cocoa bindings so I can create a graphical "delve" style tool for OS X. I have most of the basic things working off Xapian::Database. What I am stuck on is I have TermIterator working, but I can't get any positional information off of terms I _KNOW_ have positional information. Here is what delve reports.>delve -t LP:support -r 34 /index/wfsPosition List for term `LP:support', record #34: 12 here is the code I can't get to work, every term throws a Xapian::InvalidOperationError begin and end are pointers to copies of the begin and end iterators from database. Anyone have a clue what might be going on. NSMutableArray* terms = [[NSMutableArray alloc] init]; while (*begin != *end) { NSString* text = [[NSString alloc] initWithUTF8String:(**begin).c_str()]; NSMutableArray* positions = [[NSMutableArray alloc] init]; try { Xapian::PositionIterator beginpos = begin->positionlist_begin(); Xapian::PositionIterator endpos = begin->positionlist_end(); while (begin != end) { NSNumber* pos = [NSNumber numberWithUnsignedInt:*beginpos]; [positions addObject:pos]; [pos release]; beginpos++; } } catch ( const Xapian::InvalidOperationError &e ) { NSLog(@"no positions for term %@", text); }
Olly Betts
2006-Nov-01 02:18 UTC
[Xapian-discuss] having trouble getting position lists from termtierators
On Tue, Oct 31, 2006 at 12:37:12PM -0500, Jarrod Roberson wrote:> here is the code I can't get to work, every term throws a > Xapian::InvalidOperationError > begin and end are pointers to copies of the begin and end iterators from > database.What do you mean by "from database"? If you're trying to iterate positions from a TermIterator returned by allterms_begin(), then this is the expected behaviour - there's no implicit document id context to use to get the positions (a PositionIterator lists the occurences of a particular term in a particular document, so a document id and a termname are required). Note that you can use the termname from the TermIterator and a document id and use Database::positionlist_begin(did, termname) to create the PositionIterator. If this isn't the problem, a compilable example would probably be useful (ideally without the cocoa parts as the only OS X machines I have access to are at sourceforge and seem to be offline most of the time). Cheers, Olly