[Xapian-discuss] Patch to enable numeric sorting in Omega using scriptindex
Yevgeny Binder
pion at users.sourceforge.net
Mon Apr 28 00:34:29 BST 2008
Here is a quick patch to perform numeric sorting instead of the
default string sort in Omega 1.0.6. This must be decided at index
time, and is specified by replacing VALUE= with NUMERIC= in the
database spec file (this patch is for scriptindex only). A slightly
better approach, other than redesigning Omega (or Xapian?) to allow
setting the sort method at search time, would be to use NUMERIC as a
flag that modifies the VALUE= action, but I was just looking for an
easy hack. I hope to see this patch, or something like it, added to
the next release.
- Yevgeny Binder
30a31
> #include <sstream>
98c99
< "truncate", "unhtml", "unique", "value", "weight"
---
> "numeric", "truncate", "unhtml", "unique", "value", "weight"
109c110
< TRUNCATE, UNHTML, UNIQUE, VALUE, WEIGHT
---
> NUMERIC, TRUNCATE, UNHTML, UNIQUE, VALUE, WEIGHT
235a237,243
> case 'n':
> if (action == "numeric") {
> code = Action::NUMERIC;
> arg = YES;
> takes_integer_argument = true;
> }
> break;
593a602,612
> case Action::NUMERIC:
> if (!value.empty())
> {
> std::istringstream to_double(value);
> double value_double;
>
> to_double >> value_double;
>
> doc.add_value(i->get_num_arg(),
Xapian::sortable_serialise(value_double));
> }
> break;
More information about the Xapian-discuss
mailing list