Francis Irving
2004-May-26 21:54 UTC
[Xapian-discuss] Query::Query() in PHP, also QueryParser::prefixes
Just tried to do some query building in PHP but came up against a brick wall. The only constructor exposed by SWIG is the first one. SWIG doesn't seem to support operator overloading of constructors. I can make a query with one term $query1 = new_query("hello"); But trying to build one query from another doesn't work: $query = new_query(Query_OP_OR, $query1, $query2); When building the xapian bindings there are lots of warnings like this: ./../xapian.i:407: Warning(502): Previous declaration is Xapian::Query::Query(string const &,termcount,termpos) I've attempted to fix this by modifying xapian.i. I can't get the %rename clause to work for a constructor. I can make another function which returns "new Xapian::Query", but I'm worried about memory leaks since I don't understand how SWIG handles pointers. Similarly, the member variable QueryParser::prefixes isn't available. it should probably be a function call anyway. Either way I'm stuck and will have to resort to piping to Perl again soon... ;( Francis -- Undemocratic Europe. Fix it. Vote Martin Bell. http://www.bellforeurope.org.uk
James Aylett
2004-May-26 22:19 UTC
[Xapian-discuss] Query::Query() in PHP, also QueryParser::prefixes
On Wed, May 26, 2004 at 10:54:35PM +0100, Francis Irving wrote:> Just tried to do some query building in PHP but came up against a > brick wall. The only constructor exposed by SWIG is the first one. > SWIG doesn't seem to support operator overloading of constructors.It doesn't for PHP4, no. We have a plan to resolve this (and hence make the PHP4 bindings more useful).> I've attempted to fix this by modifying xapian.i. I can't get the > %rename clause to work for a constructor.It's now called %name, I think. I've managed to get it working for constructors in the past, but admittedly not for a while.> I can make another function which returns "new Xapian::Query", but > I'm worried about memory leaks since I don't understand how SWIG > handles pointers."Magically".> 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.> Either way I'm stuck and will have to resort to piping to Perl again > soon... ;(Eww. You may be able to do something with the query server that Richard put into CVS a while back - don't know quite what state it's in, though. J -- /--------------------------------------------------------------------------\ James Aylett xapian.org james@tartarus.org uncertaintydivision.org
Francis Irving
2004-May-28 11:01 UTC
[Xapian-discuss] Query::Query() in PHP, also QueryParser::prefixes
On Fri, May 28, 2004 at 11:34:24AM +0100, James Aylett wrote:> On Fri, May 28, 2004 at 08:46:43AM +0100, Francis Irving wrote: > > > This line: > > $query = new_QueryCombine(Query_OP_AND, $query1, $query2); > > Gives this error: > > Fatal error: Call to undefined function: new_querycombine() > > > > No other function with the word combine appears in the PHP function > > list either. > > Hmm. What version of SWIG are you using?owl:~$ swig -version SWIG Version 1.3.21 Copyright (c) 1995-1998 University of Utah and the Regents of the University of California Copyright (c) 1998-2003 University of Chicago Compiled with g++ [i686-pc-linux-gnu] Please see http://www.swig.org for reporting bugs and further information owl:~$ dpkg -s swig Package: swig Status: install ok installed Priority: optional Section: interpreters Installed-Size: 2748 Maintainer: Torsten Landschoff <torsten@debian.org> Source: swig1.3 Version: 1.3.21-5 Replaces: swig1.3 Depends: libc6 (>= 2.3.2.ds1-4), libgcc1 (>= 1:3.3.3-1), libstdc++5 (>= 1:3.3.3-1), libswig1.3.21 Suggests: swig-examples, swig-doc Description: Generate scripting interfaces to C/C++ code SWIG is a compiler that makes it easy to integrate C and C++ code with other languages including Perl, PHP, Tcl, Ruby, Python, Java, Guile, Mzscheme, Chicken, Ocaml, Pike, and C#. . Swig takes a set of ANSI C/C++ declarations and generates an interface for them to your favorite scripting language. Francis
Sam Liddicott
2004-May-28 11:23 UTC
[Xapian-discuss] Query::Query() in PHP, also QueryParser::prefixes
----- Original Message ----- From: "Francis Irving" <francis@flourish.org> To: <xapian-discuss@lists.xapian.org> Sent: Wednesday, May 26, 2004 10:54 PM Subject: [Xapian-discuss] Query::Query() in PHP, also QueryParser::prefixes> Just tried to do some query building in PHP but came up against a > brick wall. The only constructor exposed by SWIG is the first one. > SWIG doesn't seem to support operator overloading of constructors.If you use swig tricks (and I forget what they are now) to give the overloaded constructors different names, swig will still realise they are constructors and you can invoke them as class methods in php $new_object=Class::renamed_constructor("blah"); and still get a new instance. I made it support the default constructor as a class method that returns a new instance. Sam