[Xapian-discuss] Query::Query() in PHP, also QueryParser::prefixes

James Aylett james-xapian@tartarus.org
Thu, 27 May 2004 17:20:52 +0100


On Thu, May 27, 2004 at 04:41:11PM +0100, Francis Irving wrote:

> > > > Similarly, the member variable QueryParser::prefixes isn't available.
> > > > it should probably be a function call anyway.
> > > 
> > > No, it's fine as a member. I'm having a quick (modulo recompile time,
> > > sigh) play to see if this can be wrapped conveniently, along with the
> > > other missing bits of the interface.
> > 
> > We're going to have to write some more typemaps to get this to work -
> > the nested templates of these members won't work with the standard
> > SWIG typemap libraries. It all looks reasonably tractable, but I can't
> > do it tonight, and in any case I can't do the PHP4 without a fair
> > amount of digging around to figure out how it's internal arrays work.
> 
> OK.  This was partly why I suggested it could be a function call -
> add_prefix or something.  But either way, thank you.

Well ... we can %extend{} some extra functions to do that, or write
typemaps to do the work for us. I guess %extend{} is slightly easier
to do.

Really what I want is to wrap the maps and multimaps directly, but
that would involve changing the way the library works. However /most/
of Xapian doesn't rely on the STL in its public interface, so that's
not necessarily a bad thing.

You could probably do something like (warning: untested!):

class QueryParser {
  public:
  QueryParser();
  void set_stemming_options(const string &lang, bool stem_all_ =
  false,
                                  Stopper *stop_ = NULL);

  void set_default_op(Query::op default_op_);
  void set_database(const Database &db_);
  Query parse_query(const string &q);

  %extend {
    void set_prefix(const std::string &name, std::string value) {
      self->prefixes[name] = value;
    }

    std::string get_prefix(const std::string &name) {
      return self->prefixes[name];
    }
  };
};

It would be useful to do similar things for stoplist and unstem, even
if we ignore termlist. We can tidy up for specific languages later.

J

-- 
/--------------------------------------------------------------------------\
  James Aylett                                                  xapian.org
  james@tartarus.org                               uncertaintydivision.org