[Xapian-discuss] Sorting set_sort_by_relevance_then_value

Olly Betts olly at survex.com
Sat Dec 9 04:03:54 GMT 2006

On Sat, Dec 09, 2006 at 10:45:53AM +0800, Andrey Kong wrote:
> I want to set_sort_by_relevance_then_value(0), but seems it doesnt work (PHP)
> $db = new XapianWritableDatabase("fullIndex3", DB_OPEN);
> $op_or = XapianQuery::OP_OR;
> $terms = array("google" ,"yahoo");
> $enq = new XapianEnquire($db);
> $query=new XapianQuery($op_or, $terms);
> $enq->set_sort_by_relevance_then_value(0);
> $enq->set_query($query);

The documentation for Enquire::set_sort_by_relevance_then_value() says:

     Note that with the default BM25 weighting scheme parameters,
     non-identical documents will rarely have the same weight, so this
     setting will give very similar results to set_sort_by_relevance().
     It becomes more useful with particular BM25 parameter settings
     (e.g. BM25Weight(1,0,1,0,0)) or custom weighting schemes.

Your example uses the default BM25 parameters, so this applies to you.
Try printing out the *differences* between the weights of adjacent
documents in the MSet (just printing out the weights will probably
show them as the same, but that's just because you aren't seeing
all the significant figures).

The default BM25 parameters which Xapian uses include the normalised
document length in calculations.  Documents are usually different
lengths so it's rare for two documents to get the exact same weight.

> i also tried to replace with set_docid_order() , still dosnt work too..

The same thing applies.


More information about the Xapian-discuss mailing list