[Xapian-discuss] Sorting by date and time

Olly Betts olly at survex.com
Fri Oct 7 17:45:41 BST 2005


On Thu, Oct 06, 2005 at 04:08:35PM -0300, Christiano Anderson wrote:
> This can work fine for me, the documents are indexed in exact date order
> (older documents are indexed first). I still quite confused with Xapian
> classes and couldn't find the right places on omega.cc to make the
> changes.

I've just pulled this from the gmane version of omega:

diff -rup omega-0.9.2-orig/omega.cc omega-0.9.2/omega.cc
--- omega-0.9.2-orig/omega.cc	Fri Jul 15 12:21:34 2005
+++ omega-0.9.2/omega.cc	Fri Oct  7 18:39:25 2005
@@ -330,6 +389,16 @@ try {
 	}
 	// FIXME: add SORT and SORTBANDS to filters too!  But in a compatible
 	// way ideally...
+    }
+    val = cgi_params.find("sort");
+    if (val != cgi_params.end()) {
+	if (val->second == "date") {
+	    sort_key = Xapian::valueno(-1);
+	    sort_bands = 1; // sorting is off unless this is set
+	} else if (val->second == "revdate") {
+	    sort_key = Xapian::valueno(-1);
+	    sort_bands = -1; // sorting is off unless this is set
+	}
     }
 
     // min_hits (fill mset past topdoc+(hits_per_page+1) to
diff -rup omega-0.9.2-orig/query.cc omega-0.9.2/query.cc
--- omega-0.9.2-orig/query.cc	Fri Jul 15 12:21:34 2005
+++ omega-0.9.2/query.cc	Fri Oct  7 18:38:16 2005
@@ -323,15 +309,16 @@ run_query()
 	    enquire->set_bias(bias_weight, half_life);
 	}
 	if (sort_bands) {
-	    enquire->set_sorting(sort_key, sort_bands);
-	    // FIXME: ignore sort_numeric for now
+	    if (sort_bands > 0)
+		enquire->set_docid_order(Xapian::Enquire::DESCENDING);
+	    else
+		enquire->set_docid_order(Xapian::Enquire::ASCENDING);
+	    enquire->set_weighting_scheme(Xapian::BoolWeight());
 	}
 	if (collapse) {
 	    enquire->set_collapse_key(collapse_key);
 	}
 
-	// FIXME - set msetcmp to reverse?
-
 #ifdef HAVE_GETTIMEOFDAY
 	struct timeval tv;
 	if (gettimeofday(&tv, 0) == 0) {

This patch loses the ability to sort on a value (because I didn't need
that - if you want both options there's no good reason why you can't)
and I've changed the meaning of "sort_bands" to be:

    0 for relevance weighting,
    > 0 for date sort (newest first)
    < 0 for reverse date sort (oldest first)

I set that in omega.cc from CGI parameters.

I'm intending to merge the generally useful bits of the gmane omega back
into the release version, including this bit, so this should be possible
without patching in the next release, but that probably won't be for a
few weeks.

Cheers,
    Olly



More information about the Xapian-discuss mailing list