[Xapian-discuss] Sorting by date and time

Olly Betts olly at survex.com
Tue Oct 4 19:48:04 BST 2005


On Tue, Oct 04, 2005 at 02:43:19PM -0300, Christiano Anderson wrote:
> I am indexing documents for a newspaper company and I need to sort them
> by date and time, where the most recent documents should appear on the
> top. 
> 
> I am searching on Omega. Each document has a customized termprefix XDATE
> with the date/time in timestamp. All I need is to make Omega put the
> most recent documents (highest XDATE value) on the top. I have tried
> lots of CGI Params, but maybe this is not the right path. Any tip is
> welcome.

You can't sort on a term prefix like this.

There are 3 approaches:

(a) Put the timestamp in a document value, and then sort on that value
SORT=0 if you put the timestamp in value number 0.

(b) Create suitable D, M, and Y prefix terms and use Omega's date
sorting feature.  E.g. D20051004 M200510 Y2005 for a document
dated today.

(c) Arrange that documents are indexed in exact date order (or close
enough that you don't care about discrepancies) and then implement
"sort by date" by using set_weighting_scheme(BoolWeight()) and
set_docid_order(DESCENDING) - currently you'll need to patch Omega
to do this.

Option (c) will give the fastest date search (especially once I finish
off a patch I've been working on), but can be fiddly to implement on
the indexing side.  Option (b) is probably currently faster than (a)
but I've not timed them.  Sorting on a value will be rather faster
once the new Flint backend is finished.

Cheers,
    Olly



More information about the Xapian-discuss mailing list