On Mon, May 07, 2007 at 12:19:52PM +0900, Josef Novak
wrote:> I was wondering if it is possible to return a particular indexed
> term from a search result. I have a special prefixed term index value
> "XINDEX" which I store for each document I index (this differs
from
> the index value that xapian automatically adds at indexing time, and
> is not necessarily unique). I would like to return this index value,
> instead of the actual document, as the result of a query.
Can you not just store it in the document data as well as adding it as a
term? That's the simplest way and is likely to be most efficient.
> I tried using termlist_begin() and get_termname() but I am either
> using these wrongly or this does not work.
That should work.
> I want to return the term based
> on its position in the termlist (i always index it at the first
> position).
A TermIterator from termlist_begin() iterates over the terms in sorted
order. The positions at which you added the terms (or indeed whether
they even have positional information) isn't relevant here.
So if you want to find a term with prefix "XINDEX", use (in C++):
Xapian::TermIterator t = doc.termlist_begin();
t.skip_to("XINDEX");
if (t != doc.termlist_end()) {
string term = *t;
if (term.substr(0, 6) == "XINDEX") {
// term is the first XINDEX prefixed term
}
}
Cheers,
Olly