Omega: Missing support for newer weighting schemes

Vivek Pal vivekpal.dtu at gmail.com
Wed Apr 12 11:51:23 BST 2017


> Each scheme already has a human-readable name, and Xapian::Registry
> can map that to an "examplar" object of the right type, so we
> could take a string like "bm25 1 0.8", see the first word is "bm25"
> and get a BM25Weight object, then call parse_params("1 0.8") on it to
> create the correct Weight object (broadly similar to how unserialise()
> is handled).

Hi Olly -- the following piece of tested code in omega/weight.cc hopefully
achieves what we intend to do. It works fine for all tests. Please let me
know what you think.

  if (startswith(scheme, "pl2")) {
     const char *p = scheme.c_str() + 3;
     if (*p == '\0') {
         enq.set_weighting_scheme(Xapian::BM25Weight());
         return;
     }
     if (C_isspace(*p)) {
       Xapian::Registry reg;
       const Xapian::Weight * wt =
reg.get_weighting_scheme("Xapian::PL2Weight");
       enq.set_weighting_scheme(*wt->set_parameter_values(p));
       return;
     }
  }

Although, I'm still having a hard time trying to figure out how it's possible
to achieve what we do with the above code by just:

  enq.set_weighting_scheme(Xapian::Weight::parse_params(scheme));

in omega like you mentioned previously.

Also, turns out that parse_params method is identical to unserialise() method
in each Weight subclass so why not simply use unserialise method rather than
implementing the same functionality that it provides under a different name
like parse_params to avoid code duplication? In fact, the following code
works just fine for all tests:

  enq.set_weighting_scheme(*wt->unserialise(p));

Thanks,
Vivek



More information about the Xapian-devel mailing list