[Xapian-devel] C++ MatchDecider::operator() is const
olly at survex.com
Thu Oct 2 11:41:10 BST 2008
On Wed, Oct 01, 2008 at 05:54:20PM +0100, Richard Boulton wrote:
> Eric Sellin wrote:
> > Why is MatchDecider::operator() a const in the C++ API?
> > [...]
> That's a good question. I'm actually not certain it should be const,
> and perhaps it's something which should be fixed in future. However,
> fixing it would be a fairly intrusive API change, and would require any
> user subclasses to be updated, so I wouldn't be happy doing this until
> the 2.0 release (and I'm not convinced it's worth the effort, overall).
I'm pretty much convinced it isn't. The issue of whether this should be
const or not is arguable, but while "x.0" is a chance for making
incompatible changes when there's a good reason, it shouldn't be taken
as an excuse to change things just because we can. It requires users to
update their code, and complicates code which wants to support the old
and new APIs for a transitional period.
> Note, however, that Xapian does not give you any guarantees about the
> order in which the match decider is applied to documents, and doesn't
> guarantee that it will be called with all the potential matching
> documents. (At least, I don't think there's any guarantees about the
> order in which it will be presented with documents in the documentation
> anywhere - I'm willing to be disproved! It certainly often doesn't see
> all the potential matches.)
The intention is certainly that a MatchDecider should make an
independent decision about each document.
Currently the order is actually ascending docid order, but we certainly
want to reserve the right for it not to be as there are some potential
optimisations that this allows.
> [...] Of course, a matchspy can only really be useful if it has
> mutable members, which is why I feel it might be reasonable to remove
> the const.
Actually, you don't need mutable members here (though it's probably how
you would usually do it). A pointer to a place to tally the results
would be enough (while a pointer member itself can't be changed by a
const method, but what it points to can be).
We could potentially make MatchSpy a separate class with a non-const
operator() (probably returning void) - it's not been in a release yet.
More information about the Xapian-devel