How to get the serialise score returned in Xapian::KeyMaker->operator().

Olly Betts olly at survex.com
Sat Dec 16 22:11:40 GMT 2017


On Fri, Dec 15, 2017 at 03:10:48PM +0800, 张少华 wrote:
> After using boolean terms to get some candidates of documents (still
> too much), we want sorted them by self-defined function which is used
> in Xapian::KeyMaker->operator(). But how can I get the serialise score
> in Xapian::MSetIterator object.
> 
> c++ code likes this:
> 
> class SortKeyMaker : public Xapian::KeyMaker {
> std::string operator()(const Xapian::Document& doc) const {
>     double score = self-defined-function(doc);
>     return Xapian::sortable_serialise(score);   // How get this value in Xapian::MSetIterator
> }

Unfortunately the sort key isn't currently exposed via the public API.
It's available internally and it seems like it ought to be accessible
but there's no accessor method for it - I can add one but that won't
help for existing releases.

A possible workaround (and perhaps a better approach) would be to
set BoolWeight as the weighting scheme, then feed in your score as
a weight using a PostingSource.  Then it's available via get_weight()
on the MSetIterator object:

https://getting-started-with-xapian.readthedocs.io/en/latest/advanced/postingsource.html

You may find that's faster because it'll mean sorting by doubles instead
of strings.

Also you'll get told the lowest weight that's of interest each time
you need to calculate a score - if your scoring function is expensive
you might be able to skip documents if a cheap calculation can show they
can't beat this lowest weight.

Cheers,
    Olly



More information about the Xapian-discuss mailing list