Jason Chapin
2009-Aug-05 16:50 UTC
[Xapian-discuss] Trouble understanding MultiValueSorter with PHP bindings
Hi all, Using the PHP5 bindings, I have been trying to sort results using MultiValueSorter: ... $enquire = new XapianEnquire($database); $enquire->set_query($query); $sorter = new XapianMultiValueSorter(); $sorter->add(2); $enquire->set_sort_by_key($sorter, false); $matches = $enquire->get_mset((int)$startAt, (int)$perPage); ... the results always come sorted by ascending docId. My understanding of $sorter->add(2) is to sort the results on the third field of the document (field 0 being the docId and field 3 being the second field defined in the scriptindex file used to build the database). Any advice apreciated. Regards, Jason -- //////////////////////////////////// Jason Chapin jason at roasted.org
Olly Betts
2009-Aug-13 03:53 UTC
[Xapian-discuss] Trouble understanding MultiValueSorter with PHP bindings
On Wed, Aug 05, 2009 at 12:50:38PM -0400, Jason Chapin wrote:> My understanding of > $sorter->add(2) is to sort the results on the third field of the > document (field 0 being the docId and field 3 being the second field > defined in the scriptindex file used to build the database).No, that's incorrect. The argument of Sorter::add() is the number of a Document value slot. With the API, you add these with Document::add_value(). With scriptindex, you can add these with value=SLOT or valuenumeric=SLOT. See: xapian.org/docs/omega/scriptindex.html As for sorting by docid as well, then note that this only makes sense as the "least significant" ordering (since no two documents have the same document id, sorting by docid then <anything> means that <anything> never affects the ordering). The docid is always used as the final decider anyway, but you can change whether you want ascending, descending, or you don't care (in which case you get whatever is most efficient). In the API that is Enquire::set_docid_order(). Doesn't seem to be accessible from OmegaScript at present (but would be easy to add). There's more discussion of sorting here: xapian.org/docs/sorting Cheers, Olly