[Xapian-discuss] Question about sorting using the Java bindings.

Olly Betts olly at survex.com
Thu Mar 8 21:44:24 GMT 2007


On Thu, Mar 08, 2007 at 04:32:08PM -0500, jarrod roberson wrote:
> there appears to be only 3 ways to sort using the java bindings.

The Java bindings are lagging behind the C++ API here.  It's a pain to
update the JNI wrappers by hand, and my hope is to move them over to
using SWIG which will mean everything gets wrapped, and can then be
kept up to date with almost no extra effort.

> 1) default sort by relevance
> 2) .setSortForward(boolean) , this appears to try and sort by docid,
> but it seems to skip some docid's

This is a wrapper for the precursor to what's now
Enquire::set_docid_order() in C++.  It specifies the ordering by docid
*for two documents which otherwise are equal in the sort order*.

> 3) .setSorting(long, int) , what are valid inputs for this?

This is a wrapper for the (now deprecated in C++) method
Enquire::set_sorting().  The docs for that are here:

http://www.xapian.org/docs/apidoc/html/classXapian_1_1Enquire.html

Which say:

    void set_sorting(Xapian::valueno sort_key, int sort_bands, bool sort_by_relevance=false)

	For compatibility with Xapian 0.8.5 and earlier.

	Deprecated:
	This method is now deprecated, use
	set_sort_by_relevance(), set_sort_by_value(), or
	set_sort_by_value_then_relevance() instead.

    set_sorting(KEY, 1) -> set_sort_by_value(KEY)

    set_sorting(KEY, 1, false) -> set_sort_by_value(KEY)

    set_sorting(KEY, 1, true) -> set_sort_by_value_then_relevance(KEY)

    set_sorting(ANYTHING, 0) -> set_sort_by_relevance()

    set_sorting(Xapian::valueno(-1), ANYTHING) -> set_sort_by_relevance() 

Looks like Java doesn't wrap the "sort_by_relevance" parameter, and
sort_bands is just ignored now, so the meaningful option is:

	enquire.setSorting(VALUENO, 1)

Which is the same as enquire.set_sort_by_value(VALUENO) in C++.  The
sort uses a string comparison.

Cheers,
    Olly



More information about the Xapian-discuss mailing list